Skip to content

Commit

Permalink
Hide other modals when showing a mounted modal for react select compa…
Browse files Browse the repository at this point in the history
…tibility
  • Loading branch information
james-manley committed Sep 30, 2021
1 parent 6840922 commit ef2b954
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/components/html/Modal/MountedModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@ import ModalPortal from "./ModalPortal";
import Modal from "./Modal";

export default class MountedModal extends React.Component {
render() {
if (this.props.show === false) {
return null;
componentDidMount() {
let shownModal = document.querySelector('.modal.in');
if (shownModal) {
shownModal.setAttribute('style', 'display:none');
shownModal.setAttribute('data-shown-modal', 'true');
}
}

componentWillUnmount() {
let shownModal = document.querySelector('[data-shown-modal=true]');
if (shownModal) {
shownModal.setAttribute('style', 'display:block');
shownModal.removeAttribute('data-shown');
}
}

render() {
return <ModalPortal portalId="react-modal-container">
<Modal style={{display: 'block'}} className={`${this.props.large ? 'modal--large' : ''} in`}>
{this.props.children}
Expand Down

0 comments on commit ef2b954

Please sign in to comment.