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

Add mountNode prop to Popup module #4362

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions src/modules/Popup/Popup.d.ts
Expand Up @@ -57,6 +57,9 @@ export interface StrictPopupProps extends StrictPortalProps {
/** Invert the colors of the popup */
inverted?: boolean

/** The node where the popup should mount. Defaults to document.body. */
mountNode?: any

/**
* Offset values in px unit to apply to rendered popup. The basic offset accepts an
* array with two numbers in the form [skidding, distance]:
Expand Down
9 changes: 9 additions & 0 deletions src/modules/Popup/Popup.js
Expand Up @@ -13,6 +13,7 @@ import {
customPropTypes,
getElementType,
getUnhandledProps,
isBrowser,
makeDebugger,
SUI,
useKeyOnly,
Expand Down Expand Up @@ -68,6 +69,9 @@ export default class Popup extends Component {
clearTimeout(this.timeoutId)
}

// Do not access document when server side rendering
getMountNode = () => (isBrowser() ? this.props.mountNode || document.body : null)

getPortalProps = () => {
debug('getPortalProps()')
const portalProps = {}
Expand Down Expand Up @@ -231,6 +235,7 @@ export default class Popup extends Component {
trigger,
} = this.props
const { closed, portalRestProps } = this.state
const mountNode = this.getMountNode()

if (closed || disabled) {
return trigger
Expand Down Expand Up @@ -285,6 +290,7 @@ export default class Popup extends Component {
return (
<Portal
{...mergedPortalProps}
mountNode={mountNode}
onClose={this.handleClose}
onMount={this.handlePortalMount}
onOpen={this.handleOpen}
Expand Down Expand Up @@ -349,6 +355,9 @@ Popup.propTypes = {
/** Invert the colors of the Popup. */
inverted: PropTypes.bool,

/** The node where the popup should mount. Defaults to document.body. */
mountNode: PropTypes.any,

/**
* Offset values in px unit to apply to rendered popup. The basic offset accepts an
* array with two numbers in the form [skidding, distance]:
Expand Down