Repository navigation
[drawer] Fix unreliable swipe-to-open gestures - #5105
Conversation
The first-move latency calibration in useSwipeDismiss discarded the displacement of the first move to avoid the dragged element jumping. On a quick flick the whole travel can land in that single move, so the swipe area (which uses trackDrag: false and has no element to jump) lost the gesture. Skip the calibration when trackDrag is false.
commit: |
Bundle size
PerformanceTotal duration: 1,403.47 ms -20.95 ms(-1.5%) | Renders: 78 (+0)
…and 1 more (+8 within noise) — details Metric alarms
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. |
…zed click A swipe-open released outside the popup (e.g. dragged past its size) makes the gesture's own pointerup synthesize a click over the backdrop, which outside-press dismissal closed at random. The swipe area disabled outside-press during the gesture and re-enabled it on a timer, which raced the synthesized click. Re-enable on the next fresh pointerdown instead: the synthesized click has no pointerdown of its own so it is ignored, while a deliberate outside press starts with one and still dismisses.
371f190 to
3a2e232
Compare
There was a problem hiding this comment.
Pull request overview
This PR improves the reliability of Drawer.SwipeArea swipe-to-open gestures by adjusting how the shared swipe gesture hook treats the first movement sample (especially on low-refresh-rate devices) and by making outside-press dismissal re-enable deterministic after a swipe-open release.
Changes:
- Update
useSwipeDismissfirst-move calibration to only reset the drag origin whentrackDragis enabled, preserving quick-flick displacement for swipe areas. - Replace timer-based outside-press re-enable in
DrawerSwipeAreawith a “next fresh interaction” guard using a document capture listener. - Update and extend tests to model realistic pointer button state (
buttons) and to cover the synthesized-click regression and quick-flick edge cases.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/react/src/utils/useSwipeDismiss.ts | Skips first-move drag-origin/time calibration when trackDrag is false to preserve quick-flick displacement. |
| packages/react/src/utils/useSwipeDismiss.test.tsx | Adds buttons: 1 to pointer moves to better match real pointer dragging semantics. |
| packages/react/src/drawer/viewport/DrawerViewport.test.tsx | Ensures pointer-move test events include buttons to match updated gesture logic. |
| packages/react/src/drawer/swipe-area/DrawerSwipeArea.tsx | Replaces timer-based dismissal re-enable with a capture-phase “next pointerdown” guard and adds cleanup. |
| packages/react/src/drawer/swipe-area/DrawerSwipeArea.test.tsx | Adds regression tests for synthesized-click dismissal and quick-flick scenarios; introduces pressOutside() helper. |
| packages/react/src/drawer/root/DrawerRoot.test.tsx | Updates swipe simulations so pointer moves include buttons: 1. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Ports the six applicable Drawer fixes from the base-ui v1.7.0 release: - mui/base-ui#5105: reliable swipe-to-open — first-move re-anchoring is now gated on trackDrag (the SwipeArea passes trackDrag: false, so a flick whose whole travel lands in the first move still registers), and sawPrimaryButtonsOnMove initializes from the event type. - mui/base-ui#5308: drag styles are only rewritten when the offset actually changed, fixing the snap point jump when the pointer is pinned at a screen edge. The swipeThreshold function is snapshotted at gesture start. - mui/base-ui#5257: cross-axis touch arbitration rewritten (shouldYieldTouchMove) — 6px slop / 2px bias, one-shot attribution per gesture, non-cancelable moves yield to native scroll, and no preventDefault until an axis passes the slop (iOS kills native scrolling for the whole gesture otherwise). - mui/base-ui#5360: elementFromPoint resolves through getRootNode() so swipe gestures work inside shadow DOM. - mui/base-ui#5112: the popup no longer flashes fully open for a frame during a swipe-area open — resetAfterOpen skips the movement-var reset while the SwipeArea drives the gesture (swipeAreaActive), and the SwipeArea re-asserts its styles when the popup (re)mounts. - mui/base-ui#5179: virtual keyboard scroll handling rework for focus moves while the keyboard is open — interval realign passes, preemptive focus geometry override to neutralize WebKit's reveal scroll, window scroll pinning, programmatic-focus flag, settle-watching scroll bookkeeping. The SwipeArea outside-press guard is now deterministic (capture-phase pointerdown/click listeners + isVirtualClick) instead of a 300ms timer. Not ported (React-only): mui/base-ui#5109, Drawer.Handle/createHandle detached triggers, bundle-size refactors. Co-Authored-By: Claude Fable 5 <[email protected]>
Two fixes for
Drawer.SwipeAreaswipe-to-open:trackDrag: false), so the gesture was lost — skip the calibration whentrackDragis false. This was only noticeable on a 60 Hz MacBook Neo; a 120 Hz MacBook Pro was unaffected (the higher sample rate splits the flick across multiple moves).clickover the backdrop, which outside-press dismissal closed at random (the timer re-enabling dismissal raced that click). Re-enable on the next fresh pointerdown instead: the synthesized click has no pointerdown of its own so it's ignored, while a deliberate outside press still dismisses. Again, only noticeable on the 60 Hz Neo, not the Pro