Skip to content

[popover] Support visualViewport positioning#48288

Open
mj12albert wants to merge 2 commits intomui:masterfrom
mj12albert:popover-visual-viewport
Open

[popover] Support visualViewport positioning#48288
mj12albert wants to merge 2 commits intomui:masterfrom
mj12albert:popover-visual-viewport

Conversation

@mj12albert
Copy link
Copy Markdown
Member

@mj12albert mj12albert commented Apr 15, 2026

This ensures the popup stays anchored correctly when (pinch)zoomed

Components:

Tested with Chrome, Safari, Firefox (there are some cross-browser differences), iOS Safari & Chrome - open while zoomed, and also open then zoom/pan around

Fixes #17636
Fixes #23919
Fixes #39538

@mj12albert mj12albert added the component: Popover The React component. label Apr 15, 2026
@code-infra-dashboard
Copy link
Copy Markdown

code-infra-dashboard bot commented Apr 15, 2026

Bundle size

Bundle Parsed size Gzip size
@mui/material 🔺+1.08KB(+0.21%) 🔺+424B(+0.29%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/private-theming 0B(0.00%) 0B(0.00%)
@mui/system 0B(0.00%) 0B(0.00%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes

Deploy preview

https://deploy-preview-48288--material-ui.netlify.app/


Check out the code infra dashboard for more information about this PR.

@mj12albert mj12albert force-pushed the popover-visual-viewport branch 2 times, most recently from 70865bf to 5fd68fc Compare April 15, 2026 15:40
@mj12albert mj12albert added scope: menu Changes related to the menu. scope: select Changes related to the select. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. labels Apr 15, 2026
@mj12albert mj12albert marked this pull request as ready for review April 15, 2026 16:01
Copy link
Copy Markdown
Member

@ZeeshanTamboli ZeeshanTamboli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial review. Will review in detail later.

Comment thread packages/mui-material/src/Popover/Popover.js Outdated
return typeof anchorEl === 'function' ? anchorEl() : anchorEl;
}

function getAnchorWindow(anchorEl) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would a better name be getAnchorElWindow?


if (resolvedAnchorEl && resolvedAnchorEl.nodeType === 1) {
anchorElement = resolvedAnchorEl;
} else if (resolvedAnchorEl?.contextElement && resolvedAnchorEl.contextElement.nodeType === 1) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is contextElement? I can't find anything about it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +236 to +244
// Convert the anchor rect to the popover's offsetParent. Some pinch-zoom paths
// report the fixed Modal root relative to the visual viewport.
const containerRect = element.offsetParent?.getBoundingClientRect();
const containerTop = Math.min(containerRect?.top ?? 0, 0);
const containerLeft = Math.min(containerRect?.left ?? 0, 0);

// Calculate element positioning relative to the container.
let top = anchorOffset.top - containerTop - elemTransformOrigin.vertical;
let left = anchorOffset.left - containerLeft - elemTransformOrigin.horizontal;
Copy link
Copy Markdown
Member

@ZeeshanTamboli ZeeshanTamboli Apr 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain what this all is doing compared to earlier calculation?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted this part to a getAnchorOffsetRelativeToContainer function and added comments there

anchorOffset is in viewport coordinates, popover paper is positioned inside its offsetParent, so the anchor needs to be converted to the parent's coordinate space

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Apr 18, 2026
@mj12albert mj12albert force-pushed the popover-visual-viewport branch from 0ec196f to d3f41a6 Compare April 18, 2026 15:45
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Apr 18, 2026
@mj12albert mj12albert force-pushed the popover-visual-viewport branch from d3f41a6 to 9f8e1ea Compare April 18, 2026 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: Popover The React component. scope: menu Changes related to the menu. scope: select Changes related to the select. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.

Projects

None yet

2 participants