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

[Popover] Fix paper position flash on open #34546

Merged
merged 5 commits into from
Oct 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

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