Repository navigation
[dialog] Fix touch outside-press dismissal without a backdrop - #5096
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,398.97 ms +43.53 ms(+3.2%) | Renders: 78 (+0)
13 tests 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. |
b20692b to
000de20
Compare
000de20 to
35af7d8
Compare
flaviendelangle
left a comment
There was a problem hiding this comment.
Verification summary:
-
The bug is real.
useDismisshandleTouchEnd(line 640–655) callscloseOnPressOutside(event)with the actualtouchendevent whendismissOnTouchEndis set (arming happens atdistance > 5inhandleTouchMove).closeOnPressOutsideinvokes the dialog'soutsidePress(event)at line 465. On a completed single-fingertouchend,event.touches.length === 0, so the old guardevent.touches.length !== 1rejected it → dialog stayed open. Confirmed. -
The fix is correct. The new
touchendbranch accepts onlychangedTouches.length === 1 && touches.length === 0(true single-finger tap), andtouchstart/touchmovestill requiretouches.length === 1, preserving multi-touch rejection. The>10pximmediate-dismiss path goes through atouchmoveevent (touches.length === 1) → still accepted via theelse if. No regression. -
No path-confusion regressions. For
modal === true,InternalBackdroprenders only whenmodal === true(DialogPortal.tsx:35), sooutsidePressEventreturns'intentional'→ touch dismissal goes throughclick(notouchesproperty) → guard block skipped entirely. Formodal={false}andmodal="trap-focus"there's no backdrop →'sloppy'→touchend/touchmovepath. Test premises are accurate. -
No sibling copies. The guard is unique to
useDialogRoot.ts(shared by Dialog + Drawer); Popover has no such guard. Othertouches.lengthreferences are unrelated handlers. -
Tests pin the behavior and would fail without the fix (
waitForwould time out). Assertion shapemock.calls[0][1].reasonmatches file conventions.
PR review
A correct, well-scoped fix for a narrow touch-dismissal bug. I verified the central claim against the vendored useDismiss source: the dialog's outsidePress guard does receive the real touchend event (where touches.length === 0), the old guard wrongly rejected it, and the new branch accepts exactly the single-finger-tap case while preserving multi-touch rejection. Nothing is merge-blocking. One optional note on an untested branch of the new guard.
Bugs (0)
No findings.
Tests (1)
1. ℹ️ The changedTouches.length !== 1 rejection branch is untested
Location: packages/react/src/dialog/root/useDialogRoot.ts:90
if (event.type === 'touchend') {
if (event.changedTouches.length !== 1 || event.touches.length !== 0) {
return false;
}
}The new touchend guard rejects on two conditions. The added tests cover the accept case (1 ended / 0 remaining) and the touches.length !== 0 rejection (a second finger still down). The other half — two fingers lifting simultaneously, so changedTouches.length === 2 and touches.length === 0 — is not exercised. It's a rare real-world gesture, so a maintainer may reasonably skip it.
Failure scenario: A future refactor that drops the changedTouches.length !== 1 check (e.g. simplifying to only test touches.length) would let a two-finger simultaneous lift dismiss the dialog, and no test would catch the regression.
Fix: Optionally extend the multi-touch test with a touchEnd whose changedTouches has two entries and touches: [], asserting the dialog stays open — or leave as-is given how marginal the gesture is.
Simplifications (0)
No findings.
Docs (0)
No findings.
Verdict
Approve — the fix is correct, regression-tested across both backdrop-less modal variants plus a multi-touch negative case, and introduces no new public surface; the only note is an optional test-coverage nicety.
🤖 Review generated with Claude Code
Summary
Tapping outside a
Dialogwith touch did not dismiss it within a 5px-10px touchmove range when the dialog had noDialog.Backdrop— i.e.modal={false}ormodal="trap-focus". Mouse outside-press worked; only the touchend dismissal path was broken.Cause
useDismissinvokes the dialog'soutsidePresscallback with thetouchendevent after a small outside touch movement. Ontouchend, the lifted point is reported inevent.changedTouchesandevent.touchesis empty for a completed single-finger gesture. The dialog-only guard rejected anything whereevent.touches.length !== 1:So in the touchend-dismiss window,
0 !== 1→ the press was wrongly rejected and the dialog stayed open. This is narrow to reproduce manually: movement under 5px does not arm touchend dismissal, while movement over 10px dismisses earlier duringtouchmovewheretouches.length === 1. The broken case is the middle window (>5px and <=10px) that waits fortouchend. This guard is dialog-only legacy from #3011;Popoverhas no such guard and relies on floating-ui defaults.Fix
Handle
touchendseparately: accept it only when exactly one touch ended and no other touches remain active.touchstart/touchmovestill require exactly one active touch, preserving the original multi-touch rejection.Testing
Added Chromium-only regression coverage for the narrow touchend-dismiss window by dispatching a real single-finger sequence with a ~6px move (
touchstart→touchmove→touchendwith the lifted point inchangedTouches) across bothmodal={false}andmodal="trap-focus"with no backdrop. The 6px move intentionally arms touchend dismissal without crossing the >10px immediate touchmove-dismiss threshold. Also added a multi-touchtouchendcase that keeps the dialog open when another touch remains active.