Skip to content

[popups] Ignore pinch-zoom shifting - #4485

Merged
atomiks merged 10 commits into
mui:masterfrom
atomiks:codex/navigation-menu-pinch-zoom-shift
Jul 19, 2026
Merged

atomiks merged 10 commits into
mui:masterfrom
atomiks:codex/navigation-menu-pinch-zoom-shift

Conversation

@atomiks

@atomiks atomiks commented Mar 30, 2026 •

Copy link
Copy Markdown
Contributor

Only Navigation Menu popups and the root Context Menu popup use the layout viewport for shift(). This keeps them anchored to page content instead of following the smaller visual viewport during pinch zoom. Context Menu submenus and all other anchored popups keep their existing visual viewport behavior.

Changes

  • Use Floating UI's layoutViewport boundary for Navigation Menu positioners.
  • Use the same boundary for the root Context Menu positioner, replacing its custom layout viewport rectangle.
  • Keep Context Menu submenus, Menu, Menubar, and other anchored popup components on the default visual viewport.
  • Keep flip() and size() on the visual viewport so software keyboard collision handling is unchanged.

@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

pkg-pr-new Bot commented Mar 30, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@4485
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@4485
    

commit: 4f2d3ee

@mui-bot

mui-bot commented Mar 30, 2026 •

Copy link
Copy Markdown

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

netlify Bot commented Mar 30, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 4f2d3ee
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a5d59781426a1000a936867
😎 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.
🤖 Make changes Run an agent on this branch

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

@flaviendelangle flaviendelangle left a comment

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.

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-safe — win.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 naming — useLayoutViewport 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

atomiks commented Apr 3, 2026

Copy link
Copy Markdown
Contributor Author

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

@code-infra-dashboard

code-infra-dashboard Bot commented Jul 13, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react ▼-209B(-0.05%) ▼-16B(-0.01%)

Details of bundle changes

Performance

Total duration: 1,195.05 ms -112.15 ms(-8.6%) | Renders: 78 (+0) | Paint: 1,893.22 ms -170.40 ms(-8.3%)

Test Duration Renders
Scroll Area mount (300 instances) 77.41 ms ▼-20.91 ms(-21.3%) 3 (+0)
Dialog mount (300 instances) 46.72 ms ▼-11.89 ms(-20.3%) 1 (+0)
Combobox open — 500 items 36.78 ms ▼-10.05 ms(-21.5%) 4 (+0)
Combobox type — 500 items, all stay mounted (type "Row ") 32.03 ms ▼-10.05 ms(-23.9%) 11 (+0)

11 tests within noise — details


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

@flaviendelangle flaviendelangle left a comment

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.

PR review

This is a clean, behavior-preserving refactor: it extracts the inline trigger-bounds check from the menu, select, and combobox triggers into a shared isMouseWithinBounds util, and widens the drift tolerance from 2px to 5px so a fast click that drifts slightly during press-release isn't mistaken for a drag-off cancellation. All three call sites are guarded against a null trigger and pass a native MouseEvent, matching the util signature. Nothing is merge-blocking. Combobox and util tests pass locally.

Bugs (0)

No findings.

Tests (1)

1. ℹ️ New 5px tolerance is only integration-tested for combobox, not menu/select

Location: packages/react/src/menu/trigger/MenuTrigger.tsx:149, packages/react/src/select/trigger/SelectTrigger.tsx:204

The behavioral change (release up to 5px outside the trigger keeps the popup open) got dedicated integration tests only in ComboboxTrigger.test.tsx. MenuTrigger and SelectTrigger share the same util, and the exact boundary is directly unit-tested in getPseudoElementBounds.test.ts, so the core logic is well covered — but there's no test pinning that menu/select actually route through isMouseWithinBounds on release.

Failure scenario: A future refactor that removes or bypasses the bounds check in MenuTrigger/SelectTrigger (e.g. reordering the early-return guards) would not be caught by any test, since only combobox exercises this path end-to-end.

Fix: Optional — add a menu and select equivalent of the combobox "keeps open within 5px / closes beyond 5px" test, or leave as-is given the util is directly boundary-tested.

Simplifications (0)

No findings. The refactor removes three duplicated copies of the inline bounds math and the BOUNDARY_OFFSET constant; all consumers were updated consistently and no orphaned getPseudoElementBounds direct usages remain.

Docs (0)

No findings. The new JSDoc and the BOUNDARY_OFFSET comment accurately describe the tolerance and its rationale.

Verdict

Approve — clean, well-tested refactor with an intended tolerance widening; the only observation is an optional test-coverage symmetry note across the three triggers.


🤖 Review generated with Claude Code

@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jul 16, 2026
@atomiks
atomiks force-pushed the codex/navigation-menu-pinch-zoom-shift branch from a48301b to 8069f6c Compare July 17, 2026 12:05
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jul 17, 2026
@atomiks
atomiks requested a review from Copilot July 19, 2026 22:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adjusts Base UI’s anchored popup positioning so Navigation Menu popups and the root Context Menu popup remain anchored to page content during pinch-zoom by using Floating UI’s layoutViewport as the shift() root boundary, while keeping other popups on the visual viewport and preserving existing flip()/size() behavior.

Changes:

  • Extend useAnchorPositioning to accept a shift configuration object (crossAxis, rootBoundary).
  • Apply rootBoundary: 'layoutViewport' for Navigation Menu positioners and root Context Menu positioners; keep submenus and other popups on the default behavior.
  • Bump Floating UI package versions and add unit tests covering the new configuration plumbing.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pnpm-lock.yaml Updates resolved Floating UI package versions to support layoutViewport.
packages/utils/package.json Bumps @floating-ui/utils dependency.
packages/react/package.json Bumps @floating-ui/react-dom and @floating-ui/utils dependencies.
packages/react/src/utils/useAnchorPositioning.ts Introduces shift options and wires rootBoundary into shift() middleware.
packages/react/src/utils/useAnchorPositioning.test.tsx Adds tests to validate default vs configured shift options.
packages/react/src/navigation-menu/positioner/NavigationMenuPositioner.tsx Configures Navigation Menu positioner shift to use layoutViewport.
packages/react/src/navigation-menu/positioner/NavigationMenuPositioner.test.tsx Verifies Navigation Menu passes the expected shift configuration.
packages/react/src/menu/positioner/MenuPositioner.tsx Configures root Context Menu positioner to use layoutViewport (while leaving submenus unchanged).
packages/react/src/menu/positioner/MenuPositioner.test.tsx Adds coverage for root Context Menu vs submenu shift behavior.
Files not reviewed (1)
  • pnpm-lock.yaml: Generated file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@atomiks
atomiks force-pushed the codex/navigation-menu-pinch-zoom-shift branch from 2079784 to 4f2d3ee Compare July 19, 2026 23:10
@atomiks
atomiks merged commit 84ac4b7 into mui:master Jul 19, 2026
6 checks passed
@atomiks
atomiks deleted the codex/navigation-menu-pinch-zoom-shift branch August 11, 2026 03:02
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.

4 participants