Skip to content

fix(Dialog, Drawer): a backdrop press dismisses only when it starts and ends on the backdrop - #9613

Merged
cixzhang merged 7 commits into
mainfrom
lane4/backdrop-press-start-end
Nov 3, 2026
Merged

cixzhang merged 7 commits into
mainfrom
lane4/backdrop-press-start-end

Conversation

@cixzhang

@cixzhang cixzhang commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #8964.

User impact

Someone works in a light-dismissable Dialog (purpose="info"), a Drawer with its scrim, or CommandPalette. They select text in a field and release the mouse a little past the dialog's edge. The dialog closes, and what they were doing is lost. The same happens with a pen.

Problem and solution fit

  • Why does it fail? These members closed on any click whose target was the <dialog> itself, on the assumption that clicks on content always target the content. But when a press starts on one element and ends on another, the browser sends click to their nearest common ancestor, which here is the <dialog>.
  • Why does it harm the task? A press that began as work inside the dialog is read as "dismiss".
  • Why does it matter? Text selection is ordinary inside dialogs, and closing loses unsaved input.

Expected behavior and authority

Smallest restoration

  • New Layer/useBackdropPress: records on pointerdown whether the press started on the <dialog> itself, and on pointerup whether it also ended there. pointercancel clears both. On click, it dismisses only for a press that started and ended on the backdrop, then clears the record (as Layer/outsidePress.ts does for light dismiss).
  • Capture phase: the pointer handlers run in the capture phase, because a nested layer (a popover open in the dialog) stops its presses at its own root. A press into or out of that layer is still recorded.
  • Dialog and Drawer both use it; CommandPalette inherits it through Dialog. A caller's own onClick and pointer handlers still run, in each component's existing order, and a caller's capture handlers run after the record.
  • Record:
    • family:overlay-dismissal FR10 names its three members, and AV4 points to it for them. BottomSheet, MobileNav and Lightbox keep their own backdrop handling.
    • The family's evidence row names both tests, and useBackdropPress.test.tsx joins its verified_by.
    • Drawer FR6 and its verification cell.

Evidence

  • Reproduction before the change: useBackdropPress.test.tsx covers all three members, each with a mouse and a finger. Its crossing, cancelled and carry-over cases fail on main: a press that crosses the edge either way dismisses, and so does a cancelled one.
  • Result after the change: all pass, including a nested-layer case for Dialog and Drawer: a drag from the backdrop into a nested layer, then from it to the backdrop, leaves the dialog open. That case fails with bubble-phase handlers.
  • Representative unchanged path:
    • A press that starts and ends on the backdrop still dismisses.
    • form and required purposes still ignore it, and content clicks never dismiss.
    • The Dialog, Drawer, CommandPalette and Layer suites pass (715 tests). Existing backdrop tests now press down and up before clicking, as a real press does.
  • Regression test or other mutation-sensitive proof: BackdropPress.a11y.chromium.spec.ts on a new no-visual story checks each member in Chromium:
    • a real mouse drag from inside the field out to the backdrop, and one from the backdrop into the field, leave it open;
    • a mouse click on the backdrop closes it;
    • a finger tap on the backdrop closes it.

Scope

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split. The popover-above case isn't changed.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • Public text and artifacts contain no internal Meta context.

Testing

  • pnpm vitest run packages/core/src/Dialog packages/core/src/Drawer packages/core/src/CommandPalette packages/core/src/Layer: 715 passed.
  • pnpm check:knowledge: aligned.
  • The Chromium spec runs in CI's scoped a11y leg.

Writing rubric results

Run over family:overlay-dismissal FR10, AV4 and its evidence row, and Drawer FR6 (docs/contributing/spec-writing.md):

  • Present tense, describes the system: yes.
  • One owner per fact: the family owns the rule (FR10), and Drawer FR6 restates only its own case and cites FR10.
  • Testable: FR10 names the start-and-end condition and its counterexamples, and the evidence row names both tests.
  • Plain language: short sentences, active voice.

…nd ends on the backdrop

#8964. Dialog (purpose="info"), Drawer's scrim and CommandPalette (through
Dialog) closed on any click whose target was the <dialog>. A press that
starts inside and ends on the backdrop (a text selection or a slider drag
released past the edge) also produces that click, because the browser sends
it to the common ancestor, so the dialog closed and the input was lost.

Specs' ruling, one shared path: Layer/useBackdropPress records whether the
pointer-down landed on the backdrop and dismisses on the click only if it
did; Dialog and Drawer both use it (CommandPalette inherits it). Record:
family:overlay-dismissal FR10 states the rule, AV4 points to it, and its
evidence row names the tests; Drawer FR6 says the press starts and ends
there. Tests: useBackdropPress.test.tsx for all three members, mouse and
touch (12 of 18 fail before), existing backdrop tests now press down first,
and a Chromium spec with a real drag out of each member and a mouse click
and finger tap on the backdrop.
@vercel

vercel Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 3, 2026 4:32am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 2, 2026
@astracat-bot

astracat-bot Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 3, 2026, 4:39 AM UTC

@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 2, 2026
@cixzhang

cixzhang commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec e9e455b

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · a645f6a

Storybook · Sandbox · built from this PR's head

Current run: Heavy CI deferred: runs when marked ready and before merge. Lint, typecheck and any path-filtered checks ran on this push.


Generated by PR Enrichment workflow | View current CI run

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested: presses that start inside and end on the backdrop now leave the dialog open, but a press that starts on the backdrop and ends inside still closes Dialog, Drawer and CommandPalette, because useBackdropPress never checks where the press ended.

  • Record the pointer-up target too, as watchOutsidePress in Layer/outsidePress.ts does, clear it on pointercancel, and add a backdrop-to-inside case to the unit test, the Chromium spec and the FR10 evidence row.
  • FR10 and AV4 read as a rule for every member with backdrop dismissal, but BottomSheet, BottomSheetSwitcher, MobileNav and Lightbox keep their own handlers and MobileNav FR4 is unchanged; name the three members in FR10, or move the others onto the hook.

[Automated review]

Comment on lines +40 to +46
if (
isEnabled &&
startedOnBackdrop &&
event.target === event.currentTarget
) {
onBackdropPress();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A press that starts on the backdrop and ends inside the dialog also produces a click on the <dialog> (the common ancestor), so this still dismisses. In Chromium on this head, pointer-down on the dialog, pointer-up on the field and click on the dialog closes Dialog, Drawer and CommandPalette. Record the pointer-up target as well and require both here, clearing both on click and on pointercancel, as watchOutsidePress in outsidePress.ts does.

Comment thread docs/families/overlay-dismissal.md Outdated
Comment on lines +218 to +224
- **FR10 — A backdrop press starts and ends on the backdrop.** A member that
dismisses on a press on its modal backdrop (a Dialog with `purpose="info"`,
a Drawer's scrim, a CommandPalette through its Dialog) dismisses only when the
press both started and ended on the backdrop. A press that starts inside the
member and ends on the backdrop, such as a text selection or a slider drag
released past the edge, does not dismiss it. The rule is the same for a
mouse, a pen, and a finger, and the members share one implementation.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reads as a rule for every member that dismisses on a backdrop press. BottomSheet, BottomSheetSwitcher, MobileNav and Lightbox do that with their own target === currentTarget handlers and are not changed, and component:MobileNav FR4 still says a click on the overlay requests close. Name the three members this pull request changes as the subject, or move the other four onto useBackdropPress and amend MobileNav FR4.

Comment on lines +691 to +693
// A press on the ::backdrop targets the <dialog> itself, so native browser
// popups (date pickers, selects, color pickers) that render outside the
// dialog's bounding rect.
const handleClick = (event: React.MouseEvent<HTMLDialogElement>) => {
if (event.target === event.currentTarget && allowBackdropClick) {
onOpenChange(false);
}
};
// dialog's rect never count. The press must start and end there.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking (INV29): the first sentence runs 26 words over two topics, and the last sentence is stronger than what the hook checks. Suggested: "A press on the ::backdrop targets the itself. A native popup outside the dialog's rect is not the backdrop."

…FR10 names its members

CodeBunny on #9613: a press that started on the backdrop and ended inside
still closed the members, because only the pointer-down was checked.
useBackdropPress now records the pointer-up too (as Layer/outsidePress.ts
does) and clears both on pointercancel; Dialog and Drawer wire the two new
handlers. FR10 names Dialog (purpose="info"), Drawer's scrim and
CommandPalette instead of reading as a rule for every member with a
backdrop, and AV4 points to it for those members; Drawer FR6 checks the
pointer-up. Tests gain backdrop-to-inside and cancelled-pointer cases (unit,
mouse and touch) and a backdrop-to-inside Chromium drag.
@cixzhang

cixzhang commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 984947d

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested: a press that crosses the edge either way now leaves Dialog, Drawer and CommandPalette open, and a press on the backdrop alone still closes them. One fix remains: Drawer now wraps a caller's onPointerDown, onPointerUp and onPointerCancel in composeEventHandlers, so they stop running whenever a descendant (a TextInput clear button, a NumberInput stepper) has called preventDefault(), which Drawer FR11's forwarding of unclaimed props does not allow. Chaining those three with chainEventHandlers, as Dialog already does, plus a Drawer test where a child prevents default on pointerdown, resolves it.

[Automated review]

Comment thread packages/core/src/Drawer/Drawer.tsx Outdated
Comment on lines +614 to +625
onPointerDown: composeEventHandlers(
scrimPress.onPointerDown,
safeProps.onPointerDown as PointerHandler | undefined,
),
onPointerUp: composeEventHandlers(
scrimPress.onPointerUp,
safeProps.onPointerUp as PointerHandler | undefined,
),
onPointerCancel: composeEventHandlers(
scrimPress.onPointerCancel,
safeProps.onPointerCancel as PointerHandler | undefined,
),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

composeEventHandlers returns once event.defaultPrevented is true, so a caller's onPointerDown, onPointerUp and onPointerCancel no longer run for a press on a child that prevented default (a TextInput clear button, a NumberInput stepper). Before this change they rode {...safeProps} into layerClickBoundary and always ran, as Drawer FR11 ("forwards remaining unclaimed props") requires. chainEventHandlers(scrimPress.onPointerDown, safeProps.onPointerDown) (and the same for up and cancel), as Dialog does, keeps the hook first and always forwards.

…ented default

CodeBunny on #9613: composeEventHandlers stops at defaultPrevented, so a
caller's onPointerDown/Up/Cancel no longer ran for a press on a child such
as a clear button, which Drawer FR11's forwarding does not allow. Chain them
with chainEventHandlers, as Dialog does; the backdrop press still records
first.
@cixzhang

cixzhang commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 5d4f6c9

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested: a press that crosses the edge of a Dialog, Drawer or CommandPalette now leaves it open in Chromium, and a press on the backdrop alone still closes it, but two things block approval.

  • useBackdropPress records the press with bubble-phase handlers, which never see a press inside a nested layer such as a Popover open in the dialog, so a press from the backdrop into that Popover leaves its start recorded and the next press from the Popover to the backdrop closes the Dialog or Drawer; recording the press in the capture phase, clearing it on click, and adding a nested-Popover test resolves it.
  • The changeset says dragging a slider out of the dialog no longer closes it, but no test drags a slider, and in Chromium neither Slider nor a native range input closed a Dialog on the base; drop that clause or narrow it to what a test reproduces.

The Drawer pointer-handler forwarding from the last round is fixed.

[Automated review]

Comment on lines +35 to +44
const onPointerDown = useCallback((event: PointerEvent<HTMLElement>) => {
startedOnBackdropRef.current = event.target === event.currentTarget;
endedOnBackdropRef.current = false;
}, []);

const onPointerUp = useCallback((event: PointerEvent<HTMLElement>) => {
endedOnBackdropRef.current =
startedOnBackdropRef.current && event.target === event.currentTarget;
startedOnBackdropRef.current = false;
}, []);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A press that starts inside a nested layer (a Popover, a menu, a Selector list) stops at that layer's root in the React tree, so these bubble-phase handlers never see it. After a press from the backdrop into an open Popover, startedOnBackdropRef stays true, and the next press from the Popover to the backdrop closes the dialog. In Chromium, a drag from a Popover field to the backdrop leaves a Dialog open, but closes it right after one drag from the backdrop into that field. Recording in the capture phase (onPointerDownCapture, onPointerUpCapture, onPointerCancelCapture), as watchOutsidePress does, and clearing both refs in onClick avoids it.

Comment thread packages/core/src/Drawer/Drawer.tsx Outdated
Comment on lines +613 to +614
// Where the press started is recorded first. The caller's handler
// always runs after it, also when a child prevented default.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking (INV29): passive voice. Suggested: "The hook records where the press started first. The caller's handler then runs, even when a child prevented default."

# Conflicts:
#	packages/core/src/Drawer/Drawer.tsx
CodeBunny on #9613: a nested layer, such as a popover open in the dialog,
stops its presses at its own root, so bubble-phase handlers missed a press
into or out of it; a drag from the backdrop into the popover left its start
recorded, and the next press from the popover to the backdrop closed the
dialog. useBackdropPress now returns capture-phase pointer handlers, and a
click clears both records. Dialog and Drawer set them as capture props and
chain the caller's capture handlers after them. A nested-layer test covers
Dialog and Drawer. The changeset drops the slider clause, which no test
reproduces.
@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 3, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ready apart from one spec decision for the current head; no code change is needed.

  • The record changes (family:overlay-dismissal FR10, its AV4 pointer and evidence row, and the component:Drawer FR6 rewrite) add requirements the current specs do not state, and the latest commit cleared the earlier spec approval: an engineering owner records the decision by commenting /approve-spec <full head SHA> on this pull request, which the author, as an engineering owner, may do.

Both issues from the last round are fixed: the press is now recorded in the capture phase, so a press through a popover inside the dialog no longer carries over, and the changeset no longer claims a slider fix. One optional comment rewrite is suggested inline.

[Automated review]

Comment on lines +620 to +621
// The hook records where the press started first. The caller's capture
// handler then runs, also when a child prevented default.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: a capture handler on the root runs before any child's handler, so "also when a child prevented default" cannot happen here. Suggested: "The hook records the press before the caller's capture handler runs."

@cixzhang

cixzhang commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec bd05bb3

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 3, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ready to approve: a press that crosses the edge of a Dialog (purpose="info"), a Drawer's scrim or CommandPalette now leaves it open, a press on the backdrop alone still closes it, and the record changes are approved for this head.

Two optional comment rewrites from the earlier round remain open on Dialog.tsx and Drawer.tsx; neither blocks.

[Automated review]

MobilePowerSearch and MobileTokenizer press a confirmation Dialog's scrim
with a bare click. A backdrop press now dismisses only when its pointer-down
and pointer-up both land on the backdrop, so the tests send them first, as a
real press does.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested: the backdrop fix works and the record changes are approved for this head, but it leaves two existing tests failing.

  • packages/lab/src/MobilePowerSearch/MobilePowerSearch.test.tsx ("returns to Filters unchanged when the clear confirmation scrim is pressed") and packages/lab/src/MobileTokenizer/MobileTokenizer.test.tsx ("guards dirty Escape, scrim, and swipe dismissal…") close a purpose="info" confirmation Dialog with a bare fireEvent.click, which no longer dismisses under the new rule, so both fail on this head and pass on main; firing pointerDown and pointerUp on the dialog before each click, as Dialog.test.tsx and Drawer.test.tsx now do, fixes them.

Two optional comment rewrites from the earlier round remain open on Dialog.tsx and Drawer.tsx.

[Automated review]

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ready to approve: a press that crosses the edge of a Dialog (purpose="info"), a Drawer's scrim or CommandPalette now leaves it open, a press on the backdrop alone still closes it, and the record changes are approved for this head.

The two Lab tests from the last round now press down and up before the click and pass. Two optional comment rewrites remain open on Dialog.tsx and Drawer.tsx; neither blocks.

[Automated review]

@cixzhang

cixzhang commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec a645f6a

This branch was successfully deployed

1 active deployment
Preview — a645f6a2 Deployed Nov 3, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Dialog, Drawer, CommandPalette: a press that starts inside and ends on the backdrop closes the dialog

1 participant