Skip to content

[popups] Ignore pinch-zoom shifting#4485

Open
atomiks wants to merge 5 commits intomui:masterfrom
atomiks:codex/navigation-menu-pinch-zoom-shift
Open

[popups] Ignore pinch-zoom shifting#4485
atomiks wants to merge 5 commits intomui:masterfrom
atomiks:codex/navigation-menu-pinch-zoom-shift

Conversation

@atomiks
Copy link
Copy Markdown
Contributor

@atomiks atomiks commented Mar 30, 2026

Shared anchor positioning now switches shift() to the layout viewport only detection while pinch-zoomed, which keeps Navigation Menu and other popups from moving around when the visual viewport scales during pinch zoom, which is disorienting. It continues to support virtual software keyboard collision detection.

Changes

  • Use the layout viewport for shift() when visualViewport.scale !== 1.
  • Keep the existing context-menu behavior intact through the shared positioning path.

@atomiks atomiks added type: bug It doesn't behave as expected. component: navigation menu Changes related to the navigation menu component. labels Mar 30, 2026 — with ChatGPT Codex Connector
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 30, 2026

commit: cfd4aed

@mui-bot
Copy link
Copy Markdown

mui-bot commented Mar 30, 2026

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react 🔺+97B(+0.02%) 🔺+61B(+0.04%)

Details of bundle changes


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

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 30, 2026

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit cfd4aed
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/69ccc92d98b623000814f561
😎 Deploy Preview https://deploy-preview-4485--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@atomiks atomiks changed the title [navigation menu] Ignore pinch-zoom shifting [popups] Ignore pinch-zoom shifting Mar 31, 2026
@atomiks atomiks marked this pull request as ready for review March 31, 2026 04:17
Copy link
Copy Markdown
Member

@flaviendelangle flaviendelangle left a comment

Choose a reason for hiding this comment

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

Code Review: [popups] Ignore pinch-zoom shifting

Rating: 4/5 ⭐⭐⭐⭐

Overview

This PR extends the existing layout-viewport-based shift() behavior — previously scoped only to context menus (shiftCrossAxis) — to all popups when the user is actively pinch-zooming (visualViewport.scale !== 1). This prevents disorienting popup movement during pinch zoom on touch devices.

What's Good

  • Minimal, focused diff — net +4/−3 in a single file. The change is easy to reason about.
  • Correct use of project utilities — uses ownerWindow() as required by project conventions, instead of accessing the global window directly.
  • SSR-safewin.visualViewport?.scale ?? 1 gracefully handles environments where visualViewport is undefined or null.
  • Backward compatible — the shiftCrossAxis condition is preserved in the OR expression, so existing context menu behavior is untouched.
  • Clean variable naminguseLayoutViewport clearly communicates intent and replaces a bare shiftCrossAxis that was harder to read in context.

Concerns

  • Tests were added then removed — The first commit introduced well-structured unit tests that validated both the default behavior and the pinch-zoom case. The second commit deletes them entirely. This leaves the new visualViewport.scale code path without any test coverage. Could these tests be kept, perhaps adjusted to be less reliant on mocking Floating UI internals? Even a simpler assertion (e.g., verifying the useLayoutViewport logic in isolation) would improve confidence against regressions.

Minor Nits

  • The dependency array at line 310 doesn't include visualViewport.scale, but this is correct — the value is read dynamically inside the callback each time Floating UI recalculates positioning, so it doesn't need to be a memoization dep.

Summary

Clean, well-scoped fix that correctly generalizes an existing safeguard. The only real concern is the removal of test coverage in the second commit — I'd love to see at least some test retained for the new behavior.

@atomiks
Copy link
Copy Markdown
Contributor Author

atomiks commented Apr 3, 2026

This should be built into Floating UI as a string option due to floating-ui/floating-ui#3387 unless we implement that on our side. It's pretty rare to encounter but it does happen, so I'll try to do a release that handles this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: navigation menu Changes related to the navigation menu component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants