[popover] Support visualViewport positioning#48288
[popover] Support visualViewport positioning#48288mj12albert wants to merge 2 commits intomui:masterfrom
Conversation
Bundle size
Deploy previewhttps://deploy-preview-48288--material-ui.netlify.app/ Check out the code infra dashboard for more information about this PR. |
70865bf to
5fd68fc
Compare
ZeeshanTamboli
left a comment
There was a problem hiding this comment.
Initial review. Will review in detail later.
| return typeof anchorEl === 'function' ? anchorEl() : anchorEl; | ||
| } | ||
|
|
||
| function getAnchorWindow(anchorEl) { |
There was a problem hiding this comment.
Would a better name be getAnchorElWindow?
|
|
||
| if (resolvedAnchorEl && resolvedAnchorEl.nodeType === 1) { | ||
| anchorElement = resolvedAnchorEl; | ||
| } else if (resolvedAnchorEl?.contextElement && resolvedAnchorEl.contextElement.nodeType === 1) { |
There was a problem hiding this comment.
What is contextElement? I can't find anything about it.
| // 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; |
There was a problem hiding this comment.
Can you explain what this all is doing compared to earlier calculation?
There was a problem hiding this comment.
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
0ec196f to
d3f41a6
Compare
d3f41a6 to
9f8e1ea
Compare
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