Skip to content

fix(Dialog, BottomSheet): a dismissed file picker inside no longer closes them - #7851

Merged
cixzhang merged 2 commits into
meta:mainfrom
vjeux:dialog-cancel-descendant
Oct 22, 2026
Merged

cixzhang merged 2 commits into
meta:mainfrom
vjeux:dialog-cancel-descendant

Conversation

@vjeux

@vjeux vjeux commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

User impact

A person who dismisses a file picker (Escape, or Cancel in the chooser) from an upload field inside a Dialog or BottomSheet loses the whole surface: it closes and takes any unsaved form state with it, although they only backed out of the picker. Inside a BottomSheetSwitcher step, the whole flow closes.

Problem and solution fit

  • Why does it close? A file input fires a cancel event at itself when its picker closes without a selection, and that event bubbles (HTML Standard, file upload state). It reaches the <dialog>.
  • Why is that a dismissal? Each component treats every cancel reaching its <dialog> as the platform close request and dismisses, whatever its target. A switcher step renders no dialog, so the switcher's receives it.
  • Why does it matter? Backing out of a picker is not a request to close the layer, and treating it as one discards work.

The fix ignores a cancel whose target is not the component's own <dialog>. A close request is fired at the dialog itself and does not bubble, so no real dismissal is lost.

Expected behavior and authority

family:overlay-dismissal (current) names the dismissal commands: Escape or a platform close request (the close-request row and FR3). component:Dialog routes its dismissal to that family. A cancel bubbling up from a control inside the layer is neither.

Smallest restoration

One early return at the top of the three handleCancels (Dialog, BottomSheet, BottomSheetSwitcher), before preventDefault(): if (event.target !== event.currentTarget) return;, leaving the input's event alone. No API, default or visual change; a patch changeset.

Evidence

  • Reproduction before the change: in Chromium 149, a click on a file input inside a modal <dialog> (headless dismisses the picker at once) delivers cancel to the dialog with the input as target. On main the four new tests fail: each component dismisses for the picker's cancel.
  • Result after the change: both stay open, and the picker's event is not default-prevented.
  • Representative unchanged path: each component's own cancel still closes it (new tests); the existing Escape, required, IME and nesting tests pass.
  • Regression test: Dialog.test.tsx › "a cancel from inside the dialog" (two cases), BottomSheet.test.tsx › "stays open when a file picker inside it is dismissed…" and BottomSheetSwitcher.test.tsx › "keeps the flow open when a file picker inside a step is dismissed…".

Scope

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • 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

  • Sibling: fix(BottomSheet): keep toasts visible and clickable above an open sheet #7781 also edits BottomSheet.tsx, in another region; the two merge cleanly and pass together (below).
  • pnpm exec vitest run packages/core/src/Dialog packages/core/src/BottomSheet packages/core/src/Layer: 23 files, 584 tests passed, including the 4 new ones (red on main; the switcher case also red on the first head).
  • With fix(BottomSheet): keep toasts visible and clickable above an open sheet #7781 merged in, adding packages/core/src/Toast: 26 files, 660 passed.
  • pnpm -F @astryxdesign/core typecheck, eslint and prettier on the changed files, and the pre-commit check:repo steps: clean.
  • Real browser (Chromium 149, Playwright): a click on <input type="file"> inside a modal <dialog> gives one cancel at the dialog, with the input as target and bubbles: true.

…oses them

A file input fires a bubbling `cancel` event at itself when its picker
closes without a choice. Dialog and BottomSheet handled every `cancel`
that reached their <dialog> as a close request, so dismissing an upload
picker inside one closed it. Both now ignore a `cancel` whose target is
not their own <dialog>; Escape and platform close requests are unchanged.
@vercel

vercel Bot commented Oct 22, 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 Oct 22, 2026 1:10am UTC

Request Review

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

astracat-bot Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 22, 2026, 1:40 AM UTC

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

🧪 Sandbox Preview

View Sandbox for this PR

No new or modified components detected.

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.9KB 1.2KB

Accessibility Audit

Status: No accessibility violations detected.

Visual Regression

46 of 486 shot(s) changed.

A change here is a question, not a failure: check whether the after is the
picture you intended. Record that review on the PR. Baseline maintenance is an
explicit dispatch of CI; this report never rewrites the baseline or adds a release gate.

component story theme mode pixels
Selector Indicator Space Bottom Sheet Narrow End RTL neutral light 753,933
Selector Indicator Space Bottom Sheet Wide Start neutral light 740,072
Chat Full AI Chat probe light 230,823
Chat Full AI Chat probe dark 229,805
RichTextEditor Markdown parity: side by side probe dark 94,866
RichTextEditor Markdown parity: side by side probe light 89,762
Collapsible Dividers probe dark 66,445
Collapsible Dividers probe light 66,445
Chat Default neutral dark 36,304
Chat Default neutral light 35,767
Chat Empty State probe light 23,531
Chat Empty State probe dark 22,622
ChatAutoScroll Scroll Behavior Comparison neutral dark 15,378
ChatAutoScroll Scroll Behavior Comparison neutral light 14,107
Chat With Attachments probe light 13,406
Chat With Attachments probe dark 11,232
ProgressBar With Target Mark probe dark 7,895
ProgressBar With Target Mark probe light 7,895
Markdown Default neutral dark 7,573
Markdown Default neutral light 7,566

and 26 more.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

@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.

Requesting changes: the target check fixes the reported bug for Dialog and a standalone BottomSheet (the new tests fail on main and pass here, and a dismissed picker no longer closes either in Chromium), but a BottomSheet used as a step inside BottomSheetSwitcher still closes the whole flow, because the switcher's own handleCancel still dismisses on every cancel. Please add the same event.target !== event.currentTarget guard there with a switcher test, or narrow the changeset and title to the standalone sheet, since the changeset currently says BottomSheet stays open.

[Automated review]

'@astryxdesign/core': patch
---

[fix] Dialog and BottomSheet stay open when a file picker inside them is dismissed. A file input fires a bubbling `cancel` event when its picker closes without a choice, and both components took that event for a close request of their own and closed. They now act only on a `cancel` aimed at their own `<dialog>`, so Escape and platform close requests (the Android back gesture) behave as before. No API changes.

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 holds for a standalone BottomSheet, but a BottomSheet with a sheetId inside BottomSheetSwitcher still closes the whole flow when its picker is dismissed: that sheet renders no <dialog> of its own, and BottomSheetSwitcher's handleCancel still calls preventDefault() and dismisses on every cancel. Either add the same guard there (with a switcher test), or say "a standalone BottomSheet" here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 9d49457: the changeset now names Dialog, BottomSheet and BottomSheetSwitcher, including the switcher closing its whole flow before the fix.

// layer dismisses, and nothing dismisses during an IME composition.
const handleCancel = useCallback(
(event: React.SyntheticEvent<HTMLDialogElement>) => {
if (event.target !== event.currentTarget) {

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 covers only a sheet that owns its <dialog>. Inside a BottomSheetSwitcher the step renders no dialog, so the switcher's handleCancel (BottomSheetSwitcher.tsx, line 594) receives the picker's cancel and calls onActiveSheetChange(null). The same three-line guard at the top of that handler stops it, and the existing BottomSheetSwitcher.test.tsx cases still pass with it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 9d49457: BottomSheetSwitcher's handleCancel takes the same guard, with a switcher test. A bubbling cancel from a file input inside a step leaves the flow open, and the switcher's own cancel still closes it. The new case fails on the first head and passes now; the existing switcher cases pass (Dialog, BottomSheet and Layer suites: 584 of 584).

…nger closes the flow

A step in a BottomSheetSwitcher renders no dialog of its own, so a file
input's bubbling `cancel` reaches the switcher's <dialog>, whose handler
dismissed the whole flow. It now ignores a `cancel` whose target is not
its own <dialog>, as Dialog and BottomSheet do.

@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 fix is ready to approve: Dialog, a standalone BottomSheet and BottomSheetSwitcher now stay open when a file picker inside them is dismissed, while a close request aimed at their own <dialog> still closes them. The new tests fail on main and pass here, and the switcher guard requested on the previous revision is in place with its own test. Nothing more is needed in this PR; Drawer, Lightbox and MobileNav keep the same unguarded cancel handler and could take the same guard in a follow-up.

[Automated review]

@cixzhang
cixzhang merged commit 79f4fc7 into meta:main Oct 22, 2026
68 checks passed
@vjeux
vjeux deleted the dialog-cancel-descendant branch October 22, 2026 03:26

This branch was successfully deployed

1 active deployment
Preview — 9d49457b Deployed Oct 22, 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.

2 participants