Skip to content

[drawer] Fix unreliable swipe-to-open gestures - #5105

Merged
atomiks merged 7 commits into
mui:masterfrom
atomiks:claude/sharp-austin-8f034c
Jun 29, 2026
Merged

atomiks merged 7 commits into
mui:masterfrom
atomiks:claude/sharp-austin-8f034c

Conversation

@atomiks

@atomiks atomiks commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

Two fixes for Drawer.SwipeArea swipe-to-open:

  • Quick flicks didn't open on low refresh displays. The shared swipe gesture discards the first move's displacement to avoid the dragged element jumping, but on a fast flick (especially on a low-refresh display) the whole travel can land in that single move. The swipe area has no element to jump (trackDrag: false), so the gesture was lost — skip the calibration when trackDrag is 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).
  • Dragging past the popup and releasing randomly dismissed. The gesture's own pointerup synthesizes a click over 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

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.
@atomiks atomiks added component: drawer Changes related to the drawer component. type: bug It doesn't behave as expected. labels Jun 23, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jun 23, 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@5105
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@5105
    

commit: d1f69e7

@code-infra-dashboard

code-infra-dashboard Bot commented Jun 23, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+178B(+0.04%) 🔺+57B(+0.04%)

Details of bundle changes

Performance

Total duration: 1,403.47 ms -20.95 ms(-1.5%) | Renders: 78 (+0)

Test Duration Renders
Slider mount (300 instances) 223.40 ms 🔺+48.37 ms(+27.6%) 3 (+0)
Checkbox mount (500 instances) 81.58 ms 🔺+17.44 ms(+27.2%) 1 (+0)
Popover mount (300 instances) 89.32 ms 🔺+15.84 ms(+21.6%) 1 (+0)
Mixed surface mount (app-like density) 71.31 ms ▼-18.71 ms(-20.8%) 5 (+0)
Combobox type — 500 items, narrows to ~11 (type "Row 25") 29.36 ms ▼-12.54 ms(-29.9%) 17 (+0)

…and 1 more (+8 within noise) — details

Metric alarms

Test Metric Change
Slider mount (300 instances) bench:paint 🔺 +79.69 ms
Checkbox mount (500 instances) bench:paint 🔺 +26.66 ms
Popover mount (300 instances) bench:paint 🔺 +25.47 ms

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

@netlify

netlify Bot commented Jun 23, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit d1f69e7
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a420abb5c5c070008ecce76
😎 Deploy Preview https://deploy-preview-5105--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 [drawer] Fix swipe area not opening on quick flicks [drawer] Fix unreliable swipe-to-open gestures Jun 23, 2026
…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.
@atomiks
atomiks force-pushed the claude/sharp-austin-8f034c branch from 371f190 to 3a2e232 Compare June 23, 2026 12:22
@atomiks
atomiks marked this pull request as ready for review June 24, 2026 05:44
@atomiks
atomiks requested a review from Copilot June 29, 2026 05:30

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

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 useSwipeDismiss first-move calibration to only reset the drag origin when trackDrag is enabled, preserving quick-flick displacement for swipe areas.
  • Replace timer-based outside-press re-enable in DrawerSwipeArea with 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.

@atomiks
atomiks merged commit 51eb5c7 into mui:master Jun 29, 2026
6 checks passed
@atomiks
atomiks deleted the claude/sharp-austin-8f034c branch June 29, 2026 06:13
legowhales added a commit to legowhales/svelte-base-drawer that referenced this pull request Aug 13, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants