Skip to content

Commit

Permalink
[Popover] Fix paper position flash on open (#34546)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheUnlocked authored Oct 12, 2022
1 parent bd57024 commit 5cc3566
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/mui-material/src/Popover/Popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ const Popover = React.forwardRef(function Popover(inProps, ref) {
[anchorEl, anchorReference, getAnchorOffset, getTransformOrigin, marginThreshold],
);

const [isPositioned, setIsPositioned] = React.useState(open);

const setPositioningStyles = React.useCallback(() => {
const element = paperRef.current;

Expand All @@ -294,6 +296,7 @@ const Popover = React.forwardRef(function Popover(inProps, ref) {
element.style.left = positioning.left;
}
element.style.transformOrigin = positioning.transformOrigin;
setIsPositioned(true);
}, [getPositioningStyle]);

const handleEntering = (element, isAppearing) => {
Expand All @@ -304,6 +307,10 @@ const Popover = React.forwardRef(function Popover(inProps, ref) {
setPositioningStyles();
};

const handleExited = () => {
setIsPositioned(false);
};

React.useEffect(() => {
if (open) {
setPositioningStyles();
Expand Down Expand Up @@ -366,6 +373,7 @@ const Popover = React.forwardRef(function Popover(inProps, ref) {
appear
in={open}
onEntering={handleEntering}
onExited={handleExited}
timeout={transitionDuration}
{...TransitionProps}
>
Expand All @@ -374,6 +382,7 @@ const Popover = React.forwardRef(function Popover(inProps, ref) {
{...PaperProps}
ref={handlePaperRef}
className={clsx(classes.paper, PaperProps.className)}
{...(isPositioned ? undefined : { style: { ...PaperProps.style, opacity: 0 } })}
ownerState={ownerState}
>
{children}
Expand Down

0 comments on commit 5cc3566

Please sign in to comment.