Repository navigation
[popups] Ignore pinch-zoom shifting - #4485
Conversation
commit: |
Bundle size report
Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
flaviendelangle
left a comment
There was a problem hiding this comment.
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 globalwindowdirectly. - SSR-safe —
win.visualViewport?.scale ?? 1gracefully handles environments wherevisualViewportisundefinedornull. - Backward compatible — the
shiftCrossAxiscondition is preserved in the OR expression, so existing context menu behavior is untouched. - Clean variable naming —
useLayoutViewportclearly communicates intent and replaces a bareshiftCrossAxisthat 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.scalecode 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 theuseLayoutViewportlogic 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.
|
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 |
Bundle size
PerformanceTotal duration: 1,195.05 ms -112.15 ms(-8.6%) | Renders: 78 (+0) | Paint: 1,893.22 ms -170.40 ms(-8.3%)
11 tests within noise — details Check out the code infra dashboard for more information about this PR. |
flaviendelangle
left a comment
There was a problem hiding this comment.
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
a48301b to
8069f6c
Compare
There was a problem hiding this comment.
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
useAnchorPositioningto accept ashiftconfiguration 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.
2079784 to
4f2d3ee
Compare
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
layoutViewportboundary for Navigation Menu positioners.flip()andsize()on the visual viewport so software keyboard collision handling is unchanged.