Skip to content

[drawer] Ignore swipes without an attributed direction when using snap points - #5477

Merged
atomiks merged 8 commits into
mui:masterfrom
atomiks:claude/drawer-snap-points-issue-f0647f
Aug 17, 2026
Merged

atomiks merged 8 commits into
mui:masterfrom
atomiks:claude/drawer-snap-points-issue-f0647f

Conversation

@atomiks

@atomiks atomiks commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #5471

With snapPoints, the release logic decides to close from the vertical delta and release velocity alone. A mostly horizontal flick with a fast downward arc at lift passes those checks even though useSwipeDismiss never attributed a swipe direction to the gesture. The viewport then commits the closing choreography (data-ending-style, data-swipe-dismiss, snap point set to null), but the hook drops the release decision because it has no dismiss direction, so onOpenChange never fires and the popup stays visually dismissed while open remains true.

Changes

  • When the gesture has no attributed direction, a would-close release settles on the nearest snap point instead of dismissing. Snap point navigation keeps working exactly as before for these gestures, since the sheet tracks their vertical component during the drag; only the close outcome is suppressed. The close is not deferred to the hook's fallback threshold loop because that loop checks both vertical directions when snap points are configured and would bypass the snap logic.
  • Unattributed releases also reset nested swipe state, which the hook's deduped trailing progress update cannot do, so a nested parent no longer keeps data-nested-drawer-swiping and a stale swipe progress.
  • Added regression tests for the unattributed fast flick, unattributed snap navigation, and nested cleanup.

@atomiks atomiks added component: drawer Changes related to the drawer component. type: bug It doesn't behave as expected. labels Aug 13, 2026
@pkg-pr-new

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

commit: 624af6f

@code-infra-dashboard

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

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+30B(+0.01%) 🔺+34B(+0.02%)

Details of bundle changes

Performance

Total duration: 1,157.37 ms -31.53 ms(-2.7%) | Renders: 76 (+0) | Paint: 1,785.91 ms -64.26 ms(-3.5%)

Test Duration Renders
Checkbox mount (500 instances) 67.91 ms ▼-17.62 ms(-20.6%) 1 (+0)

14 tests within noise — details


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

@netlify

netlify Bot commented Aug 13, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 624af6f
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a82ad385175820008081b53
😎 Deploy Preview https://deploy-preview-5477--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 force-pushed the claude/drawer-snap-points-issue-f0647f branch from bd14ad7 to 5b1a593 Compare August 13, 2026 04:10
@atomiks
atomiks marked this pull request as ready for review August 13, 2026 04:22
@atomiks

atomiks commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

@claude review

@github-actions

github-actions Bot commented Aug 17, 2026 •

Copy link
Copy Markdown

PR review

The core fix is sound: with snap points configured directions always has two entries, so primaryDirection is undefined in useSwipeDismiss (useSwipeDismiss.ts:131, :857) and a directionless release really is dropped — suppressing the close and settling on a snap point is the right repair, and the first test genuinely fails without it. Nothing here is merge-blocking. Two things are worth a second look: the nested-swipe cleanup this PR adds only covers the unattributed gesture, while the identical stranding happens on ordinary vertical snap-point drags, and the new fallback re-derives a snap point that the surrounding code already computes.

Bugs (1)

1. 🟠 Nested swipe state is still stranded after an attributed snap point settle

Location: packages/react/src/drawer/viewport/DrawerViewport.tsx:487

if (!direction) {
  applySwipeProgress(0, true, true);
}

The reset is gated on !direction, but the mechanism that strands the parent is not specific to unattributed gestures. finishNestedSwipe() only runs from applySwipeProgress(..., notifyParent: true) when the resolved progress is <= 0 (DrawerViewport.tsx:198-204), from startSwipeRelease, or on unmount. For a normal, direction-attributed drag on a nested drawer with snap points:

  • release → the hook fires updateSwipeProgress(0, progressDetails) (useSwipeDismiss.ts:877); the hook's own progress was non-zero, so this is not deduped and onProgress does run;
  • the viewport's onProgress recomputes from details.deltaY, not from the settled snap point (DrawerViewport.tsx:391-392), so it re-applies a non-zero progress and notifies the parent with it;
  • the restore effect then runs with notifyParent: false (DrawerViewport.tsx:793), so the parent is never corrected.

Net result: the parent keeps data-nested-drawer-swiping and a non-zero --drawer-swipe-progress indefinitely — the same symptom the PR description calls out, on the more common gesture. (Pre-existing, not introduced here, but the new test only pins the !direction variant, so the general case stays uncovered.)

Failure scenario: Nested drawer whose child has snapPoints={['100px', '200px']}. Drag the child popup straight down ~20px (direction attributed as down) and release; it settles back on 100px. The parent popup stays scaled/inset with data-nested-drawer-swiping set and --drawer-swipe-progress: 1 until the child closes, even though no swipe is in progress.

Fix: Move the reset out of the !direction branch — e.g. call applySwipeProgress(snapPointProgress-for-the-settled-point, true, true) (or 0, matching the steady state the parent otherwise sees) on every non-dismissing release in the snap point path, and add a nested test for the attributed drag.

Tests (1)

1. 🟡 No coverage for an unattributed release with snapToSequentialPoints

Location: packages/react/src/drawer/viewport/DrawerViewport.test.tsx:3144

All three new tests use the default (non-sequential) snap behavior, so the two sequential call sites of closeFromSnapPoints (DrawerViewport.tsx:569 and :576) never exercise the new fallback. That is exactly where the fallback's choice can diverge from what the sequential branch had already decided (see Simplifications #1).

Failure scenario: A regression in the sequential path — e.g. the fallback picking a non-adjacent or tie-broken-differently snap point after an unattributed flick on <Drawer.Root snapToSequentialPoints snapPoints={['100px','200px','300px']}> — ships unnoticed.

Fix: Add one test with snapToSequentialPoints and an unattributed fast downward flick from the most-collapsed snap point (the :569 branch), asserting it settles rather than dismisses.

Simplifications (1)

1. 🟡 The fallback re-derives a nearest snap point the caller already computed

Location: packages/react/src/drawer/viewport/DrawerViewport.tsx:517-528

if (!direction) {
  const nearestSnapPoint =
    resolvedSnapPoints[
      closestSnapPointIndex(
        resolvedSnapPoints.map((point) => point.offset),
        targetOffset,
      )
    ];
  setActiveSnapPoint(nearestSnapPoint.value, snapPointEventDetails);

This is a third copy of the lookup already present at :540-542 (sequential) and :588-594 (default), including the resolvedSnapPoints.map(...) allocation. Beyond the duplicated bytes, it ignores the decision the caller had already made: the sequential branch snaps against orderedSnapPoints/effectiveTargetOffset, so with equidistant offsets closestSnapPointIndex tie-breaks on declaration order here versus sorted order there, and the "advance one step" adjustment at :552-570 is discarded.

Failure scenario: With snapToSequentialPoints and snap points equidistant from targetOffset, an unattributed release settles on a different snap point than an otherwise identical attributed release — for no stated reason, and with an extra array allocation on every such release.

Fix: Hoist the default-path closestSnapPoint above closeFromSnapPoints and give the helper a parameter, e.g. closeFromSnapPoints(fallbackSnapPoint), passing targetSnapPoint from the sequential branch and closestSnapPoint from the default branch. Same behavior, ~10 fewer lines, no third lookup.

Verdict

Approve after nits - the fix itself is correct and well-tested for the reported bug; the nested-state cleanup is only half the story and the fallback duplicates an existing lookup, but neither blocks merge.


🤖 Review generated with Claude Code · Opus 5 (High) · medium review depth · 32 turns · 7m42s · $2.38 · run

@atomiks

atomiks commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

@claude review low

@github-actions

This comment was marked as low quality.

@atomiks
atomiks merged commit 9922b2f into mui:master Aug 17, 2026
6 checks passed
@atomiks
atomiks deleted the claude/drawer-snap-points-issue-f0647f branch August 17, 2026 06:49
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.

[drawer] With snapPoints, a swipe can dismiss the popup visually while onOpenChange never fires

1 participant