Repository navigation
fix(Dialog, BottomSheet): a dismissed file picker inside no longer closes them - #7851
Conversation
…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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report📚 Storybook Preview🧪 Sandbox PreviewNo new or modified components detected. Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Visual Regression46 of 486 shot(s) changed. A change here is a question, not a failure: check whether the after is the
and 26 more. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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]
User impact
A person who dismisses a file picker (Escape, or Cancel in the chooser) from an upload field inside a
DialogorBottomSheetloses the whole surface: it closes and takes any unsaved form state with it, although they only backed out of the picker. Inside aBottomSheetSwitcherstep, the whole flow closes.Problem and solution fit
cancelevent at itself when its picker closes without a selection, and that event bubbles (HTML Standard, file upload state). It reaches the<dialog>.cancelreaching its<dialog>as the platform close request and dismisses, whatever its target. A switcher step renders no dialog, so the switcher's receives it.The fix ignores a
cancelwhose 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:Dialogroutes its dismissal to that family. Acancelbubbling up from a control inside the layer is neither.Smallest restoration
One early return at the top of the three
handleCancels (Dialog,BottomSheet,BottomSheetSwitcher), beforepreventDefault():if (event.target !== event.currentTarget) return;, leaving the input's event alone. No API, default or visual change; a patch changeset.Evidence
<dialog>(headless dismisses the picker at once) deliverscancelto the dialog with the input astarget. Onmainthe four new tests fail: each component dismisses for the picker'scancel.cancelstill closes it (new tests); the existing Escape,required, IME and nesting tests pass.Dialog.test.tsx› "a cancel from inside the dialog" (two cases),BottomSheet.test.tsx› "stays open when a file picker inside it is dismissed…" andBottomSheetSwitcher.test.tsx› "keeps the flow open when a file picker inside a step is dismissed…".Scope
Testing
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 onmain; the switcher case also red on the first head).packages/core/src/Toast: 26 files, 660 passed.pnpm -F @astryxdesign/core typecheck, eslint and prettier on the changed files, and the pre-commitcheck:reposteps: clean.<input type="file">inside a modal<dialog>gives onecancelat the dialog, with the input as target andbubbles: true.