[toast] Fix swipe direction locking for two-axis swipes - #5295
Conversation
|
|
||
| let candidate: 'up' | 'down' | 'left' | 'right' | undefined; | ||
| if (!intendedSwipeDirectionRef.current) { | ||
| if (lockedDirection === 'vertical') { |
There was a problem hiding this comment.
lockedDirection here is refering to it's stale value not the updated one at line 338.
commit: |
Bundle size
PerformanceTotal duration: 1,353.61 ms +94.35 ms(+7.5%) | Renders: 78 (+0) | Paint: 2,099.79 ms +157.87 ms(+8.1%)
12 tests within noise — details Metric alarms
Check out the code infra dashboard for more information about this PR. |
There was a problem hiding this comment.
Pull request overview
This PR fixes swipe direction locking in Toast.Root for two-axis swipes by ensuring the newly determined lock direction is applied immediately within the same pointer-move event (rather than relying on an async state update).
Changes:
- Resolve and use a local
resolvedLockedDirectionto avoid stalelockedDirectionstate during the first “real swipe” move. - Add a regression test covering two-axis swipe locking behavior on the first move that crosses the drag threshold.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/react/src/toast/root/ToastRoot.tsx | Applies the computed axis lock immediately in the move handler to prevent the first post-threshold move from affecting both axes. |
| packages/react/src/toast/root/ToastRoot.test.tsx | Adds a regression test asserting movement is constrained to a single axis on the first qualifying two-axis swipe move. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
✅ Deploy Preview for base-ui ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
Fix swipe direction locking for two-axis swipes