Skip to content

Commit

Permalink
[Popper] Use ownerDocument of anchorEl
Browse files Browse the repository at this point in the history
  • Loading branch information
ruppysuppy committed Feb 3, 2021
1 parent 44884aa commit 4185abe
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/material-ui/src/Popper/Popper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createPopper } from '@popperjs/core';
import { chainPropTypes, refType, HTMLElementType } from '@material-ui/utils';
import { useTheme } from '@material-ui/styles';
import Portal from '../Portal';
import ownerDocument from '../utils/ownerDocument';
import setRef from '../utils/setRef';
import useForkRef from '../utils/useForkRef';
import useEnhancedEffect from '../utils/useEnhancedEffect';
Expand Down Expand Up @@ -42,7 +43,7 @@ const Popper = React.forwardRef(function Popper(props, ref) {
const {
anchorEl,
children,
container,
container: containerProp,
disablePortal = false,
keepMounted = false,
modifiers,
Expand Down Expand Up @@ -211,6 +212,12 @@ const Popper = React.forwardRef(function Popper(props, ref) {
};
}

// If the container prop is provided, use that
// If the anchorEl prop is provided, use its parent body element as the container
// If neither are provided let the Modal take care of choosing the container
const container =
containerProp || (anchorEl ? ownerDocument(getAnchorEl(anchorEl)).body : undefined);

return (
<Portal disablePortal={disablePortal} container={container}>
<div
Expand Down

0 comments on commit 4185abe

Please sign in to comment.