Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Modal): match container behaviour to targetPropType like of Popover and Tooltip #1844

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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