Skip to content

Commit

Permalink
feat(Modal): match container behaviour to targetPropType like of Popo…
Browse files Browse the repository at this point in the history
…ver and Tooltip (#1844)
  • Loading branch information
DeMoorJasper committed Jun 3, 2020
1 parent d394c45 commit 6ea2488
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/lib/Components/ModalsPage.js
Expand Up @@ -108,7 +108,7 @@ const ModalsPage = () => {
// if the element which triggered the modal to open should focused after the modal closes (see example somewhere below)
returnFocusAfterClose: PropTypes.bool, // defaults to true
// container to append the modal to
container: PropTypes.string // css selector, defauls to "body"
container: PropTypes.oneOfType([PropTypes.string, PropTypes.func, DOMElement]),
}`}
</PrismCode>
</pre>
Expand Down
8 changes: 5 additions & 3 deletions src/Modal.js
Expand Up @@ -11,7 +11,9 @@ import {
omit,
focusableElements,
TransitionTimeouts,
keyCodes
keyCodes,
targetPropType,
getTarget
} from './utils';

function noop() { }
Expand Down Expand Up @@ -58,7 +60,7 @@ const propTypes = {
]),
unmountOnClose: PropTypes.bool,
returnFocusAfterClose: PropTypes.bool,
container: PropTypes.string
container: targetPropType
};

const propsToOmit = Object.keys(propTypes);
Expand Down Expand Up @@ -292,7 +294,7 @@ class Modal extends React.Component {
this._element.setAttribute('tabindex', '-1');
this._element.style.position = 'relative';
this._element.style.zIndex = this.props.zIndex;
this._mountContainer = document.querySelector(this.props.container) || document.querySelector('body');
this._mountContainer = getTarget(this.props.container);
this._mountContainer.appendChild(this._element);
}

Expand Down

0 comments on commit 6ea2488

Please sign in to comment.