Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(BottomSheet): a standalone sheet closing with focus inside stays out of inert while focus stays (#9635)

Cindy Zhang4e495ec5ea4f
diff --git a/.changeset/bottomsheet-close-focus.md b/.changeset/bottomsheet-close-focus.md
new file mode 100644
index 0000000000..8afcaa4054
--- /dev/null
+++ b/.changeset/bottomsheet-close-focus.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] BottomSheet: a sheet closed from a control inside it, such as a Done button, a Selector's search field or a menu row, marked itself `inert` and `aria-hidden` while that control still had focus. The browser then dropped focus to the page, or screen readers were left in a hidden subtree, for the length of the exit. Now a standalone sheet that closes with focus inside it stays out of `inert` and `aria-hidden` while that focus stays, and ignores pointer and keyboard activation during its exit; when the exit ends, it closes and returns focus to its opener. The exit still plays. A sheet that closes with focus elsewhere, or that focus leaves during the exit, goes inert at once, as before.
+
+@cixzhang
diff --git a/apps/storybook/stories/BottomSheet.stories.tsx b/apps/storybook/stories/BottomSheet.stories.tsx
index 401911299a..e71f25fd23 100644
--- a/apps/storybook/stories/BottomSheet.stories.tsx
+++ b/apps/storybook/stories/BottomSheet.stories.tsx
@@ -3,8 +3,8 @@
/**
* @file BottomSheet.stories.tsx
* @input BottomSheet, content primitives, and controlled story state
- * @output BottomSheet examples plus keyboard delegation and nested-layer
- * Escape browser fixtures
+ * @output BottomSheet examples plus keyboard delegation, nested-layer
+ * Escape, and exit-focus browser fixtures
* @position Storybook coverage for BottomSheet presentation and interaction
*/
@@ -929,3 +929,53 @@ export const ModalAutofocus: Story = {
);
},
};
+
+type ExitFocusChange = 'remove' | 'disable';
+
+function ExitFocusChangeFixture({change}: {change: ExitFocusChange}) {
+ const [isOpen, setIsOpen] = useState(false);
+ const [isDoneChanged, setIsDoneChanged] = useState(false);
+ const open = () => {
+ setIsDoneChanged(false);
+ setIsOpen(true);
+ };
+ const close = () => {
+ setIsOpen(false);
+ // The control changes after the close starts, during the exit motion.
+ window.setTimeout(() => setIsDoneChanged(true), 100);
+ };
+ return (
+ <>
+ <Button label="Open sheet" onClick={open} />
+ <BottomSheet isOpen={isOpen} onOpenChange={setIsOpen} label="Exit focus">
+ <Section>
+ {change === 'remove' && isDoneChanged ? null : (
+ <Button
+ label="Done"
+ onClick={close}
+ isDisabled={change === 'disable' && isDoneChanged}
+ />
+ )}
+ </Section>
+ </BottomSheet>
+ </>
+ );
+}
+
+/**
+ * Browser fixture: Done closes the sheet, and 100 ms into the exit the Done
+ * control is removed. The sheet goes inert and hidden as focus leaves it.
+ */
+export const ExitFocusControlRemoved: Story = {
+ tags: ['!autodocs'],
+ render: () => <ExitFocusChangeFixture change="remove" />,
+};
+
+/**
+ * Browser fixture: Done closes the sheet, and 100 ms into the exit the Done
+ * control is disabled. The sheet goes inert and hidden as focus leaves it.
+ */
+export const ExitFocusControlDisabled: Story = {
+ tags: ['!autodocs'],
+ render: () => <ExitFocusChangeFixture change="disable" />,
+};
diff --git a/docs/architecture/layer-runtime.md b/docs/architecture/layer-runtime.md
index 226a93adb3..dbb4db24b8 100644
--- a/docs/architecture/layer-runtime.md
+++ b/docs/architecture/layer-runtime.md
@@ -414,8 +414,8 @@ sheet it reveals is the latest again and takes the host back; a sheet is
raised only among sheet outlets, so a Dialog opened from a sheet and
supplied later stays the latest until it closes. A BottomSheet releases its
outlet when it starts closing: its dialog stays modal through the exit
-animation, but inert. A modal Drawer also releases its outlet when it starts
-closing, so toasts do not slide out with it. A top-layer viewport renders into a host element
+animation, but inert. A closing BottomSheet with focus inside is not yet inert or hidden (`component:BottomSheet` FR9); it becomes inert and hidden when focus leaves it or its exit ends. A modal Drawer also releases its outlet when it starts closing, so toasts
+do not slide out with it. A top-layer viewport renders into a host element
it owns, moves that host into the latest open outlet, returns it to the
viewport's tree position when no outlet is open, and enters the top layer again
after each move. Toasts therefore paint above the modal and stay operable inside
diff --git a/docs/specs/components/BottomSheet/BottomSheet.spec.md b/docs/specs/components/BottomSheet/BottomSheet.spec.md
index 9168decd4a..5f598e42f4 100644
--- a/docs/specs/components/BottomSheet/BottomSheet.spec.md
+++ b/docs/specs/components/BottomSheet/BottomSheet.spec.md
@@ -145,25 +145,25 @@ remain documented in `BottomSheet.doc.mjs`.
## Behavioral and layout contract
-| ID | Invariant | Basis |
-| ---- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
-| FR1 | The current presented sheet contains one Sheet panel, one scrolling Content area, and one decorative Handle; a Scrim is present only in scrim-backed presentation. | Current source, docs, and tests |
-| FR2 | The Sheet panel carries `bottom-sheet`; Content area, Handle, and Scrim carry no BottomSheet public target. | Current source, docs, and tests |
-| FR3 | Content renders in one real observed content box. Effective overflow, containment, and keyboard access come from `useScrollableArea`; the named overflowing body delegates forward Tab entry to a safe first sequential native link/button. | `spec:AST-025`; tests |
-| FR4 | The Content area pads caller content by the sheet's container inset and publishes the applied inset to descendants as a container publisher. | `architecture:container-padding` |
-| FR5 | Modal sheets presented in one document form one stack ordered by open order: the sheet opened most recently is on top; sheets opening in one update are ordered by tree order (a sheet before the sheets rendered in its content, siblings in source order), and the first painted frame already shows that order. Only sheets of one document stack. | DEC-2 |
-| FR6 | A covered modal sheet stays mounted with its state, recedes behind the top sheet, and is blocked: the browser's modal rules block it, and when it contains no presented sheet it is also `inert` and `aria-hidden`. Exactly one backdrop is visible for a stack — the bottom open sheet's — and a change of scrim owner lands with no transition, so the page dim is constant through a push, a pop, and a handoff. | DEC-2 |
-| FR7 | Escape, a scrim tap, a swipe, and a platform close request reach only the top sheet of a stack, through that sheet's own `onOpenChange` and `purpose`; a covered sheet, and a replaced sheet during its handoff, report themselves absent to the shared `family:overlay-dismissal` stack while that lasts, so the order among sheets is the sheet stack's and the shared stack stays one registry. | DEC-2; `family:overlay-dismissal/FR2`, `/FR3` |
-| FR8 | A sheet rendered in another sheet's content is presented only while its host is open: it leaves the top layer with its host and is presented again, on top, if its own `isOpen` is still true when the host reopens. Its `isOpen` is never written by the host. | DEC-2 |
-| FR9 | Closing the top sheet returns focus into the sheet it reveals: to the element that opened the closing sheet when that element is inside the revealed sheet, else to the revealed sheet's panel; an explicit `finalFocusRef` outside the revealed sheet yields to its panel in the same way. The last sheet of a stack keeps the standalone rule: `finalFocusRef`, else the opener. Closing every sheet of a stack in one update returns focus once, to the bottom sheet's `finalFocusRef` or opener, after the last dialog has closed. A close driven by the stack itself never moves focus. | DEC-2 |
-| FR10 | When exactly one standalone sheet closes and exactly one opens in the same update, both of one document and one modality, the closing sheet was the top sheet of its group — its document's modal stack, or, for non-modal sheets, the one open non-modal sheet (FR11) — with the opening sheet set aside, neither dialog contains the other, and the actor — the control last pressed, or, with no fresh press, the element focused when the update began — is inside the closing sheet's dialog or is none (no fresh press, and nothing or only the document body focused, as when code changes the step while focus has fallen to the body), the opening sheet replaces the closing one: it enters above the retained sheet; a retained sheet whose top edge is above the entering sheet's resting top edge moves down to meet it at the same time; the retained sheet fades only after both motions complete; it is `inert` and `aria-hidden` from the first frame and takes no dismissal request; the scrim owner is FR6's, the bottom open sheet: when the retained sheet is that owner (a replace at the bottom of the stack) its backdrop keeps the one visible scrim until it leaves and the entering sheet's backdrop takes over with no transition, and when the replace runs above a covered sheet that sheet stays the owner and the retained sheet's backdrop is transparent throughout, so it only fades; focus moves into the entering sheet; and the entering sheet adopts the retained sheet's focus-return target, so closing the flow returns focus to its first opener. A close and an open that fail any condition — different updates, a covered sheet closing, several sheets changing, a sheet closing with its host, or a control outside the closing sheet acting — keep the ordinary push and pop motion and their own focus return. | DEC-2 |
-| FR11 | A non-modal sheet (`hasScrim={false}`) is presented in the browser's top layer as a manual popover with no backdrop, no scroll lock, and no focus trap, and carries no page-level `z-index`; where the Popover API is absent it is presented with `show()` in page stacking order as a reduced fallback. A non-modal sheet shown while a modal dialog that does not contain it is open (a modal sheet, a `Dialog`) is inert under that modal, so it does not enter the top layer yet — there it would paint above the modal while a press on it lands on the modal — and is presented with `show()` beneath the modal, with no page-level `z-index`; a modal on its way out (inert, hidden) counts as gone. Once no such modal is open the sheet enters the top layer as a manual popover, a top-layer toast viewport re-entering above it (FR14), so page content never paints over an interactive non-modal sheet (`spec:AST-027` FR8). A non-modal sheet rendered inside the modal's content is not inert and enters the top layer at once. Non-modal sheets never stack, recede, or own a scrim, and never pair with a modal sheet; because they never stack, the one open non-modal sheet of a document is always the top of its own group, so two non-modal sheets replace each other under FR10 — the closing one being that top — with no backdrop. On a lone open, focus goes where the engine's own `show()` focusing steps would put it when they enter the sheet, and no `data-autofocus` preference is added over them (the released behavior, kept, and the same rule as a modal sheet's `showModal()`): in Chromium the panel, whose focusing steps take the first focusable area including a `tabindex="-1"` container; in Firefox the first focusable control in the content, which is the `data-autofocus` field only when it comes first; in WebKit wherever its `show()` lands. Where the manual-popover host's own focusing steps would land elsewhere than that engine's `show()` (Chromium's `showPopover()` lands on the first control), focus arrives where `show()` would have put it without passing through any control — no control receives a focus or a blur on the way, so a field validating on blur does not fire on open; when the sheet is replacing the sheet the person was in, it takes focus, and a `data-autofocus` descendant then wins (AR4). On close an explicit `finalFocusRef` is focused wherever focus is, and otherwise the element focused when the sheet was shown is focused again only while focus is still inside the sheet — the native dialog's own return rule, kept. | DEC-2; `spec:AST-027/FR8`; `architecture:layer-runtime` |
-| FR12 | A modal `BottomSheetSwitcher` flow is one level of the stack: the dialog of its active step is the flow's level, keeps the flow's rank across the flow's own handoffs, recedes and is blocked when covered, yields its backdrop to the stack's scrim owner, stands down from dismissal while covered, and returns focus by FR9. A standalone sheet rendered in a step's content stacks above the flow and leaves with the step (FR8). A switcher step is never paired under FR10. | DEC-2; `component:BottomSheetSwitcher/DEC-1` |
-| FR13 | Every open scrim sheet supplies its dialog as a passive global outlet for app-global surfaces such as toasts (`spec:AST-003` FR18: each active native modal, a covered sheet included), and a modal `BottomSheetSwitcher` flow supplies its active step's dialog — the one its host dialog resolves to, following each handoff; the retained step's dialog, inert and fading, never hosts. Among sheets, the latest outlet — the one a global host renders into — follows the stack's order, not the order the sheets were supplied in: the top sheet is the latest, so a toast lands in the top sheet and never in a covered, inert one, and when the top sheet closes the sheet it reveals is the latest again and takes the host back. A sheet is raised only among sheet outlets: an outlet supplied later by another modal (a `Dialog` opened from a sheet) stays above every sheet until it closes. A sheet, or a flow, stops supplying as soon as it starts closing, and a native `close` event that fires while its dialog is open again (the stack re-showing it, or a reopen during its exit) does not take its outlet away. | DEC-2; `spec:AST-003/FR16`, `/FR18`; `architecture:layer-runtime`; `component:BottomSheetSwitcher/FR10` |
-| FR14 | When a non-modal sheet enters the top layer, a top-layer toast viewport shown before it leaves and re-enters the top layer in place, keeping focus inside it, so toasts paint above the sheet. | DEC-2; `architecture:layer-runtime` |
-| FR15 | Under `prefers-reduced-motion: reduce` the recede, the return from receded, a push's entrance, a pop's exit and the replace handoff — and a `BottomSheetSwitcher` step's, which shares the sheet panel's motion — follow `design:reduced-motion`, keyed on its queries (`prefers-reduced-motion: reduce`, with `pointer: coarse` for the cross-fade): no transform motion runs (DR1) — a covered sheet appears in its receded place and size the frame the push lands and returns the same way, the entering sheet appears in its final place, the retained sheet does not align down; on a coarse pointer the entering sheet fades in and the leaving or retained sheet fades out where it is, opacity only, in 200 ms or less (DR2); a dismissal the release of a touch drag started (a swipe past the dismiss line) fades out in place the same way on every pointer (DR2's drag-release clause); on any other pointer every other change is immediate (DR3); the handoff's steps run in the released order, so the retained sheet is hidden and its dialog closed once its fade ends. The constant page dim through a push, a pop and a handoff (FR6) holds as it does with motion. | DEC-2; `design:reduced-motion` |
-| FR16 | An open modal sheet is a focus region through Core's shared focus-region module (`component:Dialog/DEC-2`): in the top sheet, Tab from the last tabbable control moves focus to the first and Shift+Tab from the first moves focus to the last, so focus never leaves the sheet for the browser's own interface. A covered or closing sheet does not answer Tab, and a non-modal sheet contains nothing (FR11). | `component:Dialog/DEC-2` |
-| FR17 | A BottomSheet open on the server, by its own `isOpen` or as a `BottomSheetSwitcher`'s active sheet, renders closed until hydration (no open styles, no `aria-modal`, the markup of a closed sheet) and opens in the render after hydration, the first that can enter its native host; it never claims a modality it does not have (`spec:AST-020` FR1, WCAG 2.2 SC 4.1.2). The server and hydrating renders produce the same markup (`spec:AST-013` FR9), and the open after hydration is settled, with no entry motion; later opens and closes animate as usual (`spec:AST-013` FR13). | `spec:AST-020` FR1 |
+| ID | Invariant | Basis |
+| ---- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
+| FR1 | The current presented sheet contains one Sheet panel, one scrolling Content area, and one decorative Handle; a Scrim is present only in scrim-backed presentation. | Current source, docs, and tests |
+| FR2 | The Sheet panel carries `bottom-sheet`; Content area, Handle, and Scrim carry no BottomSheet public target. | Current source, docs, and tests |
+| FR3 | Content renders in one real observed content box. Effective overflow, containment, and keyboard access come from `useScrollableArea`; the named overflowing body delegates forward Tab entry to a safe first sequential native link/button. | `spec:AST-025`; tests |
+| FR4 | The Content area pads caller content by the sheet's container inset and publishes the applied inset to descendants as a container publisher. | `architecture:container-padding` |
+| FR5 | Modal sheets presented in one document form one stack ordered by open order: the sheet opened most recently is on top; sheets opening in one update are ordered by tree order (a sheet before the sheets rendered in its content, siblings in source order), and the first painted frame already shows that order. Only sheets of one document stack. | DEC-2 |
+| FR6 | A covered modal sheet stays mounted with its state, recedes behind the top sheet, and is blocked: the browser's modal rules block it, and when it contains no presented sheet it is also `inert` and `aria-hidden`. Exactly one backdrop is visible for a stack — the bottom open sheet's — and a change of scrim owner lands with no transition, so the page dim is constant through a push, a pop, and a handoff. | DEC-2 |
+| FR7 | Escape, a scrim tap, a swipe, and a platform close request reach only the top sheet of a stack, through that sheet's own `onOpenChange` and `purpose`; a covered sheet, and a replaced sheet during its handoff, report themselves absent to the shared `family:overlay-dismissal` stack while that lasts, so the order among sheets is the sheet stack's and the shared stack stays one registry. | DEC-2; `family:overlay-dismissal/FR2`, `/FR3` |
+| FR8 | A sheet rendered in another sheet's content is presented only while its host is open: it leaves the top layer with its host and is presented again, on top, if its own `isOpen` is still true when the host reopens. Its `isOpen` is never written by the host. | DEC-2 |
+| FR9 | Closing the top sheet returns focus into the sheet it reveals: to the element that opened the closing sheet when that element is inside the revealed sheet, else to the revealed sheet's panel; an explicit `finalFocusRef` outside the revealed sheet yields to its panel in the same way. The last sheet of a stack keeps the standalone rule: `finalFocusRef`, else the opener. Closing every sheet of a stack in one update returns focus once, to the bottom sheet's `finalFocusRef` or opener, after the last dialog has closed. A close driven by the stack itself never moves focus. A standalone sheet (not a switcher step) that closes with focus inside it is neither `inert` nor `aria-hidden` while that focus stays, and takes no pointer or keyboard activation; when the exit ends, its dialog closes and focus returns in the same task, so focus never sits in a hidden subtree (`spec:AST-020` FR1; WCAG 2.2 SC 2.4.3 and 4.1.2). It becomes `inert` and `aria-hidden` as soon as focus leaves it. A sheet that closes with focus elsewhere is `inert` and `aria-hidden` from the close. | DEC-2 |
+| FR10 | When exactly one standalone sheet closes and exactly one opens in the same update, both of one document and one modality, the closing sheet was the top sheet of its group — its document's modal stack, or, for non-modal sheets, the one open non-modal sheet (FR11) — with the opening sheet set aside, neither dialog contains the other, and the actor — the control last pressed, or, with no fresh press, the element focused when the update began — is inside the closing sheet's dialog or is none (no fresh press, and nothing or only the document body focused, as when code changes the step while focus has fallen to the body), the opening sheet replaces the closing one: it enters above the retained sheet; a retained sheet whose top edge is above the entering sheet's resting top edge moves down to meet it at the same time; the retained sheet fades only after both motions complete; it is `inert` and `aria-hidden` from the first frame and takes no dismissal request; the scrim owner is FR6's, the bottom open sheet: when the retained sheet is that owner (a replace at the bottom of the stack) its backdrop keeps the one visible scrim until it leaves and the entering sheet's backdrop takes over with no transition, and when the replace runs above a covered sheet that sheet stays the owner and the retained sheet's backdrop is transparent throughout, so it only fades; focus moves into the entering sheet; and the entering sheet adopts the retained sheet's focus-return target, so closing the flow returns focus to its first opener. A close and an open that fail any condition — different updates, a covered sheet closing, several sheets changing, a sheet closing with its host, or a control outside the closing sheet acting — keep the ordinary push and pop motion and their own focus return. | DEC-2 |
+| FR11 | A non-modal sheet (`hasScrim={false}`) is presented in the browser's top layer as a manual popover with no backdrop, no scroll lock, and no focus trap, and carries no page-level `z-index`; where the Popover API is absent it is presented with `show()` in page stacking order as a reduced fallback. A non-modal sheet shown while a modal dialog that does not contain it is open (a modal sheet, a `Dialog`) is inert under that modal, so it does not enter the top layer yet — there it would paint above the modal while a press on it lands on the modal — and is presented with `show()` beneath the modal, with no page-level `z-index`; a modal on its way out (inert and hidden, or holding focus under FR9) counts as gone. Once no such modal is open the sheet enters the top layer as a manual popover, a top-layer toast viewport re-entering above it (FR14), so page content never paints over an interactive non-modal sheet (`spec:AST-027` FR8). A non-modal sheet rendered inside the modal's content is not inert and enters the top layer at once. Non-modal sheets never stack, recede, or own a scrim, and never pair with a modal sheet; because they never stack, the one open non-modal sheet of a document is always the top of its own group, so two non-modal sheets replace each other under FR10 — the closing one being that top — with no backdrop. On a lone open, focus goes where the engine's own `show()` focusing steps would put it when they enter the sheet, and no `data-autofocus` preference is added over them (the released behavior, kept, and the same rule as a modal sheet's `showModal()`): in Chromium the panel, whose focusing steps take the first focusable area including a `tabindex="-1"` container; in Firefox the first focusable control in the content, which is the `data-autofocus` field only when it comes first; in WebKit wherever its `show()` lands. Where the manual-popover host's own focusing steps would land elsewhere than that engine's `show()` (Chromium's `showPopover()` lands on the first control), focus arrives where `show()` would have put it without passing through any control — no control receives a focus or a blur on the way, so a field validating on blur does not fire on open; when the sheet is replacing the sheet the person was in, it takes focus, and a `data-autofocus` descendant then wins (AR4). On close an explicit `finalFocusRef` is focused wherever focus is, and otherwise the element focused when the sheet was shown is focused again only while focus is still inside the sheet — the native dialog's own return rule, kept. | DEC-2; `spec:AST-027/FR8`; `architecture:layer-runtime` |
+| FR12 | A modal `BottomSheetSwitcher` flow is one level of the stack: the dialog of its active step is the flow's level, keeps the flow's rank across the flow's own handoffs, recedes and is blocked when covered, yields its backdrop to the stack's scrim owner, stands down from dismissal while covered, and returns focus by FR9. A standalone sheet rendered in a step's content stacks above the flow and leaves with the step (FR8). A switcher step is never paired under FR10. | DEC-2; `component:BottomSheetSwitcher/DEC-1` |
+| FR13 | Every open scrim sheet supplies its dialog as a passive global outlet for app-global surfaces such as toasts (`spec:AST-003` FR18: each active native modal, a covered sheet included), and a modal `BottomSheetSwitcher` flow supplies its active step's dialog — the one its host dialog resolves to, following each handoff; the retained step's dialog, inert and fading, never hosts. Among sheets, the latest outlet — the one a global host renders into — follows the stack's order, not the order the sheets were supplied in: the top sheet is the latest, so a toast lands in the top sheet and never in a covered, inert one, and when the top sheet closes the sheet it reveals is the latest again and takes the host back. A sheet is raised only among sheet outlets: an outlet supplied later by another modal (a `Dialog` opened from a sheet) stays above every sheet until it closes. A sheet, or a flow, stops supplying as soon as it starts closing, and a native `close` event that fires while its dialog is open again (the stack re-showing it, or a reopen during its exit) does not take its outlet away. | DEC-2; `spec:AST-003/FR16`, `/FR18`; `architecture:layer-runtime`; `component:BottomSheetSwitcher/FR10` |
+| FR14 | When a non-modal sheet enters the top layer, a top-layer toast viewport shown before it leaves and re-enters the top layer in place, keeping focus inside it, so toasts paint above the sheet. | DEC-2; `architecture:layer-runtime` |
+| FR15 | Under `prefers-reduced-motion: reduce` the recede, the return from receded, a push's entrance, a pop's exit and the replace handoff — and a `BottomSheetSwitcher` step's, which shares the sheet panel's motion — follow `design:reduced-motion`, keyed on its queries (`prefers-reduced-motion: reduce`, with `pointer: coarse` for the cross-fade): no transform motion runs (DR1) — a covered sheet appears in its receded place and size the frame the push lands and returns the same way, the entering sheet appears in its final place, the retained sheet does not align down; on a coarse pointer the entering sheet fades in and the leaving or retained sheet fades out where it is, opacity only, in 200 ms or less (DR2); a dismissal the release of a touch drag started (a swipe past the dismiss line) fades out in place the same way on every pointer (DR2's drag-release clause); on any other pointer every other change is immediate (DR3); the handoff's steps run in the released order, so the retained sheet is hidden and its dialog closed once its fade ends. The constant page dim through a push, a pop and a handoff (FR6) holds as it does with motion. | DEC-2; `design:reduced-motion` |
+| FR16 | An open modal sheet is a focus region through Core's shared focus-region module (`component:Dialog/DEC-2`): in the top sheet, Tab from the last tabbable control moves focus to the first and Shift+Tab from the first moves focus to the last, so focus never leaves the sheet for the browser's own interface. A covered or closing sheet does not answer Tab, and a non-modal sheet contains nothing (FR11). | `component:Dialog/DEC-2` |
+| FR17 | A BottomSheet open on the server, by its own `isOpen` or as a `BottomSheetSwitcher`'s active sheet, renders closed until hydration (no open styles, no `aria-modal`, the markup of a closed sheet) and opens in the render after hydration, the first that can enter its native host; it never claims a modality it does not have (`spec:AST-020` FR1, WCAG 2.2 SC 4.1.2). The server and hydrating renders produce the same markup (`spec:AST-013` FR9), and the open after hydration is settled, with no entry motion; later opens and closes animate as usual (`spec:AST-013` FR13). | `spec:AST-020` FR1 |
### Allowed variation
@@ -370,20 +370,20 @@ a decision that they must remain unthemeable.
## Verification map
-| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |
-| --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- |
-| FR1 | `BottomSheet.test.tsx` render, content, Handle, and scrim behavior suites | Modal, non-modal, and switcher presentations | Removing a documented part fails existing content, structure, or dismissal assertions. | `audit:BottomSheet/anatomy` |
-| FR2 | Panel target assertion, source inspection, and theming target inventories | Sheet panel, Content area, Handle, and Scrim | Removing the panel target or documenting an unshipped child target fails evidence or inventory. | `audit:BottomSheet/theming` |
-| FR3, AR1–AR2 | `BottomSheetKeyboard.test.tsx`; `BottomSheetKeyboard.a11y.browser.spec.ts`; open Storybook stories | fitting/overflow, plain text, usable/unusable/dynamic descendants, focus | Missing/duplicate keyboard access, stale ownership, focus movement, or broken content-box layout fails. | `audit:BottomSheet/accessibility` |
-| Layout evidence | `BottomSheetPanel.test.tsx` | Floating Handle and scrolling Content area | Reordering or merging the stable parts fails existing panel structure and style assertions. | `audit:BottomSheet/anatomy` |
-| FR4 | `BottomSheetPanel.test.tsx` container padding tests; `derivedVarRegistry.test.ts` | default, `padding` prop, theme `padding`, lone padded Section child | The published inset differs from the applied padding, or a lone padded Section changes geometry. | `audit:BottomSheet/anatomy` |
-| Element jobs | Open-sheet element count test against the named job list | modal and non-modal sheet, scrim and no scrim | An element in the open sheet's frame with no named job, or a named job with no element | |
-| Theming anatomy map | `scripts/check-knowledge.mjs` | Canonical anatomy and current target inventory | Missing, extra, prefixed, stale, or multiply assigned mappings fail repository validation. | `audit:BottomSheet/theming` |
-| FR5–FR9, FR12–FR15, AR3–AR5 | Stacking unit suite (jsdom, native dialog methods stubbed); real-browser per-frame sampling of transforms, backdrop opacity, hit-testing, and focus on the stacking stories in Chromium, WebKit, and real Safari; a real-browser accessibility-tree check (`spec:AST-020`, `spec:AST-009` FR3) that a lone sheet, a stack of two and three, and a replace handoff expose exactly one `dialog`, the top or entering sheet, with its name, while covered and replaced sheets are hidden, that the stack renders no live region of its own, and that focus enters the entering step's `data-autofocus` field or panel on a replace; a real-browser run with reduced motion emulated on a fine and on a coarse pointer, sampling per frame that no transform animates, that the covered sheet is in its receded place from the frame the push lands, that on a coarse pointer the entering and leaving sheets change opacity only within 200 ms and on a fine pointer at once, that a swipe dismissal fades out in place on a fine pointer, that the dim is constant and that the handoff still completes | siblings, separate components, nested in content, inside a switcher step, a switcher flow as a level, out-of-tree-order opens, same-update deep link, depth 1–3, Escape/scrim/swipe/platform close, covered close, close of the whole stack, focus after each pop, two package copies, a second document | A covered or replaced sheet is exposed in the accessibility tree, the top sheet is exposed without role `dialog` or its name, a covered sheet stays interactive, a second backdrop paints, the dim dips or doubles on a handoff, a dismissal reaches a covered sheet, a nested sheet's state is written or it stays open invisibly, or focus lands on `body` after a pop or a close of the whole stack. | `audit:BottomSheet/behavior` |
-| FR10–FR11 | Replace unit suite (jsdom); real-browser parity of the standalone flow against the switcher's handoff — per-frame transforms, opacity, page dim, focus, settled pixels — in Chromium and WebKit, and real Safari for hosting, dim, toast order, and focus; a per-engine lone-open focus probe in Chromium, Firefox and WebKit comparing the sheet's focus on open against that engine's bare `show()` and `showModal()` on the same markup, and recording the focus and blur events the sheet's first control receives on open (none) | push, pop, different updates, covered close, nested, a replace above a covered sheet (the bottom sheet keeps the scrim, the retained sheet only fades), switcher flow, a lone sheet; handoff in both completion orders; reversal mid-handoff in both directions and both tree orders; unrelated owners from a page control; non-modal replace, reversal, `show()` fallback; a non-modal sheet opened from a modal sheet or a `Dialog` and rendered outside it (while the modal is open, and once it has closed, with positioned page content), one opened in the update that closes a modal sheet, and one rendered inside the modal's content | A replace is recognized for unrelated owners or missed for a real step flow, the retained sheet is exposed or dismissable, the scrim dips, the replaced step stays on screen after a reversal, focus does not enter the step or return to the flow's opener, a non-modal sheet carries a page-level `z-index`, a toast paints under a non-modal sheet, or a lone sheet's focus on open, modal or not, differs from where that engine's released native host (`showModal()`, or `show()` for a non-modal sheet) puts it — in Chromium the panel, with a ring only after keyboard input and a `data-autofocus` field left unfocused; in Firefox the first focusable control — a control inside the sheet receives a focus or a blur on a lone open that `show()` would not have given it, or a replacement entry fails to focus its `data-autofocus` field. A non-modal sheet rendered outside an open modal paints above it while a press lands on the modal, or stays beneath page content once that modal has gone. | `audit:BottomSheet/behavior` |
-| FR13–FR14 | Toast viewport hosting suite (jsdom, native dialog methods and popover state stubbed); real-browser hit-testing of a toast raised from the top sheet, from a Dialog opened from a sheet after an inner sheet closed, from a sheet re-shown by a reversal, and over a non-modal sheet | a lone sheet; a stack of two; sheet → Dialog → sheet → close the inner sheet; a reversal and a reopen during exit, with the stale native `close`; a non-modal sheet shown after the viewport; a modal switcher flow alone, through a handoff and its close; a flow stacked over a standalone sheet and a standalone sheet over a flow; a non-modal flow | A toast renders in a covered or inert sheet, a Dialog opened from a sheet loses the toast to the sheet beneath it, a re-shown sheet loses its outlet to the stale `close`, a toast raised from a switcher step lands behind the flow or in its retained step, or a toast paints beneath a non-modal sheet. | `audit:BottomSheet/behavior` |
-| FR16 | `BottomSheet.test.tsx` focus-region suite | Modal and non-modal sheets; Tab and Shift+Tab at the sheet's edge | Tab from the last control leaves a modal sheet, or a non-modal sheet captures Tab | `audit:BottomSheet/accessibility` |
-| FR17 | `BottomSheet.ssr.test.tsx`; `BottomSheetSwitcher.test.tsx` flow that mounts open | Open on the server; hydration; a closed sheet's markup | An open server render with `aria-modal`, open styles, or markup unlike a closed one, a hydration error, no `showModal()` after hydration, an entry motion on the open right after hydration, or none on a later open fails. | `audit:BottomSheet/accessibility` |
+| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |
+| --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- |
+| FR1 | `BottomSheet.test.tsx` render, content, Handle, and scrim behavior suites | Modal, non-modal, and switcher presentations | Removing a documented part fails existing content, structure, or dismissal assertions. | `audit:BottomSheet/anatomy` |
+| FR2 | Panel target assertion, source inspection, and theming target inventories | Sheet panel, Content area, Handle, and Scrim | Removing the panel target or documenting an unshipped child target fails evidence or inventory. | `audit:BottomSheet/theming` |
+| FR3, AR1–AR2 | `BottomSheetKeyboard.test.tsx`; `BottomSheetKeyboard.a11y.browser.spec.ts`; open Storybook stories | fitting/overflow, plain text, usable/unusable/dynamic descendants, focus | Missing/duplicate keyboard access, stale ownership, focus movement, or broken content-box layout fails. | `audit:BottomSheet/accessibility` |
+| Layout evidence | `BottomSheetPanel.test.tsx` | Floating Handle and scrolling Content area | Reordering or merging the stable parts fails existing panel structure and style assertions. | `audit:BottomSheet/anatomy` |
+| FR4 | `BottomSheetPanel.test.tsx` container padding tests; `derivedVarRegistry.test.ts` | default, `padding` prop, theme `padding`, lone padded Section child | The published inset differs from the applied padding, or a lone padded Section changes geometry. | `audit:BottomSheet/anatomy` |
+| Element jobs | Open-sheet element count test against the named job list | modal and non-modal sheet, scrim and no scrim | An element in the open sheet's frame with no named job, or a named job with no element | |
+| Theming anatomy map | `scripts/check-knowledge.mjs` | Canonical anatomy and current target inventory | Missing, extra, prefixed, stale, or multiply assigned mappings fail repository validation. | `audit:BottomSheet/theming` |
+| FR5–FR9, FR12–FR15, AR3–AR5 | Stacking unit suite (jsdom, native dialog methods stubbed); real-browser per-frame sampling of transforms, backdrop opacity, hit-testing, and focus on the stacking stories in Chromium, WebKit, and real Safari; a real-browser accessibility-tree check (`spec:AST-020`, `spec:AST-009` FR3) that a lone sheet, a stack of two and three, and a replace handoff expose exactly one `dialog`, the top or entering sheet, with its name, while covered and replaced sheets are hidden, that the stack renders no live region of its own, and that focus enters the entering step's `data-autofocus` field or panel on a replace; a real-browser run with reduced motion emulated on a fine and on a coarse pointer, sampling per frame that no transform animates, that the covered sheet is in its receded place from the frame the push lands, that on a coarse pointer the entering and leaving sheets change opacity only within 200 ms and on a fine pointer at once, that a swipe dismissal fades out in place on a fine pointer, that the dim is constant and that the handoff still completes; `BottomSheetCloseFocus.test.tsx` for FR9's close order | siblings, separate components, nested in content, inside a switcher step, a switcher flow as a level, out-of-tree-order opens, same-update deep link, depth 1–3, Escape/scrim/swipe/platform close, covered close, close of the whole stack, focus after each pop, two package copies, a second document | A covered or replaced sheet is exposed in the accessibility tree, the top sheet is exposed without role `dialog` or its name, a covered sheet stays interactive, a second backdrop paints, the dim dips or doubles on a handoff, a dismissal reaches a covered sheet, a nested sheet's state is written or it stays open invisibly, or focus lands on `body` after a pop or a close of the whole stack. | `audit:BottomSheet/behavior` |
+| FR10–FR11 | Replace unit suite (jsdom); real-browser parity of the standalone flow against the switcher's handoff — per-frame transforms, opacity, page dim, focus, settled pixels — in Chromium and WebKit, and real Safari for hosting, dim, toast order, and focus; a per-engine lone-open focus probe in Chromium, Firefox and WebKit comparing the sheet's focus on open against that engine's bare `show()` and `showModal()` on the same markup, and recording the focus and blur events the sheet's first control receives on open (none) | push, pop, different updates, covered close, nested, a replace above a covered sheet (the bottom sheet keeps the scrim, the retained sheet only fades), switcher flow, a lone sheet; handoff in both completion orders; reversal mid-handoff in both directions and both tree orders; unrelated owners from a page control; non-modal replace, reversal, `show()` fallback; a non-modal sheet opened from a modal sheet or a `Dialog` and rendered outside it (while the modal is open, and once it has closed, with positioned page content), one opened in the update that closes a modal sheet, and one rendered inside the modal's content | A replace is recognized for unrelated owners or missed for a real step flow, the retained sheet is exposed or dismissable, the scrim dips, the replaced step stays on screen after a reversal, focus does not enter the step or return to the flow's opener, a non-modal sheet carries a page-level `z-index`, a toast paints under a non-modal sheet, or a lone sheet's focus on open, modal or not, differs from where that engine's released native host (`showModal()`, or `show()` for a non-modal sheet) puts it — in Chromium the panel, with a ring only after keyboard input and a `data-autofocus` field left unfocused; in Firefox the first focusable control — a control inside the sheet receives a focus or a blur on a lone open that `show()` would not have given it, or a replacement entry fails to focus its `data-autofocus` field. A non-modal sheet rendered outside an open modal paints above it while a press lands on the modal, or stays beneath page content once that modal has gone. | `audit:BottomSheet/behavior` |
+| FR13–FR14 | Toast viewport hosting suite (jsdom, native dialog methods and popover state stubbed); real-browser hit-testing of a toast raised from the top sheet, from a Dialog opened from a sheet after an inner sheet closed, from a sheet re-shown by a reversal, and over a non-modal sheet | a lone sheet; a stack of two; sheet → Dialog → sheet → close the inner sheet; a reversal and a reopen during exit, with the stale native `close`; a non-modal sheet shown after the viewport; a modal switcher flow alone, through a handoff and its close; a flow stacked over a standalone sheet and a standalone sheet over a flow; a non-modal flow | A toast renders in a covered or inert sheet, a Dialog opened from a sheet loses the toast to the sheet beneath it, a re-shown sheet loses its outlet to the stale `close`, a toast raised from a switcher step lands behind the flow or in its retained step, or a toast paints beneath a non-modal sheet. | `audit:BottomSheet/behavior` |
+| FR16 | `BottomSheet.test.tsx` focus-region suite | Modal and non-modal sheets; Tab and Shift+Tab at the sheet's edge | Tab from the last control leaves a modal sheet, or a non-modal sheet captures Tab | `audit:BottomSheet/accessibility` |
+| FR17 | `BottomSheet.ssr.test.tsx`; `BottomSheetSwitcher.test.tsx` flow that mounts open | Open on the server; hydration; a closed sheet's markup | An open server render with `aria-modal`, open styles, or markup unlike a closed one, a hydration error, no `showModal()` after hydration, an entry motion on the open right after hydration, or none on a later open fails. | `audit:BottomSheet/accessibility` |
Existing tests directly assert the Sheet panel target, Content area placement,
Handle structure, and scrim behavior. Source and public target metadata confirm
diff --git a/packages/core/src/BottomSheet/BottomSheet.test.tsx b/packages/core/src/BottomSheet/BottomSheet.test.tsx
index e32c6994bc..dca6d28529 100644
--- a/packages/core/src/BottomSheet/BottomSheet.test.tsx
+++ b/packages/core/src/BottomSheet/BottomSheet.test.tsx
@@ -568,6 +568,9 @@ describe('BottomSheet', () => {
it('keeps a standalone modal sheet presented through its exit animation', () => {
render(<ExitHarness />);
const dialog = screen.getByRole('dialog', {name: 'Filters'});
+ // With focus elsewhere at the close, the exiting sheet is inert and
+ // hidden at once (BottomSheetCloseFocus.test.tsx covers focus inside).
+ act(() => (document.activeElement as HTMLElement | null)?.blur());
fireEvent.click(screen.getByRole('button', {name: 'Close sheet'}));
diff --git a/packages/core/src/BottomSheet/BottomSheet.tsx b/packages/core/src/BottomSheet/BottomSheet.tsx
index 9fcab3a3f8..01355e7fe2 100644
--- a/packages/core/src/BottomSheet/BottomSheet.tsx
+++ b/packages/core/src/BottomSheet/BottomSheet.tsx
@@ -75,6 +75,7 @@ import {
import {useDevWarning} from '../hooks/useDevWarning';
import {useScrollLock} from '../hooks/useScrollLock';
import {useMergedRefs} from '../hooks/useMergedRefs';
+import {observeMutations} from '../utils/sharedMutationObserver';
import {mergeProps} from '../utils/mergeProps';
import {LayerDepthProvider} from '../Layer/LayerDepthContext';
import {ModalAnnounceProvider} from '../hooks/ModalAnnounceProvider';
@@ -212,6 +213,10 @@ const styles = stylex.create({
transitionTimingFunction: 'linear',
},
},
+ // A closing sheet that keeps focus takes no pointer input during its exit.
+ exitHoldingFocus: {
+ pointerEvents: 'none',
+ },
positioner: {
position: 'absolute',
insetInline: 0,
@@ -260,6 +265,24 @@ function stackPositionerStyles(view: BottomSheetStackView) {
}
/** The `data-sheet-stack` value for a host: only set while sheets stack. */
+/** Stops a click, from any input, before it reaches its target. */
+function ignoreActivation(event: React.MouseEvent): void {
+ event.preventDefault();
+ event.stopPropagation();
+}
+
+/**
+ * Stops every key except Tab before it reaches the focused control, so no
+ * key handler runs and no text changes (a search field's Enter, a typed
+ * letter, Backspace, an arrow that reopens a list). Tab still moves focus.
+ */
+function ignoreKeyDuringExit(event: React.KeyboardEvent): void {
+ if (event.key !== 'Tab') {
+ event.preventDefault();
+ event.stopPropagation();
+ }
+}
+
function stackStateAttribute(
view: BottomSheetStackView,
isOpen: boolean,
@@ -450,10 +473,14 @@ function StandaloneBottomSheet({
// `isOpen` restarts the flag during render, and the layout effect below
// settles a close.
const [isCloseSettled, setIsCloseSettled] = useState(false);
+ // Whether focus was inside the sheet when it closed. Such a sheet stays out
+ // of `inert` and `aria-hidden` until its exit ends and focus has left.
+ const [isExitFocusHeld, setIsExitFocusHeld] = useState(false);
const [settledIsOpen, setSettledIsOpen] = useState(isOpen);
if (settledIsOpen !== isOpen) {
setSettledIsOpen(isOpen);
setIsCloseSettled(false);
+ setIsExitFocusHeld(false);
}
const panelState: BottomSheetPanelState = isOpen
? {kind: 'open', entering: stackView.isReplacing}
@@ -581,9 +608,8 @@ function StandaloneBottomSheet({
}, [hasScrim, shouldPresent, writeScrim]);
useLayoutEffect(() => {
if (!isOpen) {
- // Read before the browser's focus fixup for the exiting sheet's
- // `inert` runs (at the next rendering opportunity), so this is where
- // focus was when the person closed the sheet.
+ // Where focus was when the person closed the sheet. The closing sheet
+ // is not inert yet, so focus has not moved.
const dialog = dialogRef.current;
hadFocusAtCloseRef.current =
dialog != null && dialog.contains(dialog.ownerDocument.activeElement);
@@ -596,6 +622,8 @@ function StandaloneBottomSheet({
// that was not paired as a replace is an exit from here on.
// eslint-disable-next-line @eslint-react/set-state-in-effect -- settles the close once the registry has answered
setIsCloseSettled(true);
+ // Read with the close, before the sheet can go inert.
+ setIsExitFocusHeld(hadFocusAtCloseRef.current);
}
}, [hasScrim, isOpen, shouldPresent]);
@@ -699,7 +727,44 @@ function StandaloneBottomSheet({
);
const {ref: modalityRef} = useInteractionModalityTracking();
- const dialogComposedRef = useMergedRefs(dialogRef, modalityRef);
+ // Ends the exit hold once focus has left the sheet: moved elsewhere, or
+ // dropped to the page because the focused control was removed or disabled.
+ // Native listeners, because React drops the `focusout` a browser sends while
+ // React removes the focused element, and Firefox and WebKit send no
+ // `focusout` for a removed element at all, so a subtree change is read too.
+ // Each reads the focus after the event. They attach only while a closing
+ // sheet holds focus, so a closed or open sheet observes nothing.
+ const isWatchingExitFocus =
+ !isOpen && isPresented && !isReplaced && isExitFocusHeld;
+ const exitFocusRef = useCallback(
+ (dialog: HTMLDialogElement | null) => {
+ if (dialog == null || !isWatchingExitFocus) {
+ return;
+ }
+ const releaseIfFocusLeft = () => {
+ if (!dialog.contains(dialog.ownerDocument.activeElement)) {
+ setIsExitFocusHeld(false);
+ }
+ };
+ const onFocusOut = () => queueMicrotask(releaseIfFocusLeft);
+ dialog.addEventListener('focusout', onFocusOut);
+ const unobserve = observeMutations(
+ dialog,
+ {
+ childList: true,
+ subtree: true,
+ attributeFilter: ['disabled', 'hidden', 'inert'],
+ },
+ releaseIfFocusLeft,
+ );
+ return () => {
+ dialog.removeEventListener('focusout', onFocusOut);
+ unobserve();
+ };
+ },
+ [isWatchingExitFocus],
+ );
+ const dialogComposedRef = useMergedRefs(dialogRef, modalityRef, exitFocusRef);
useScrollLock(shouldPresent && hasScrim);
useDevWarning(
'BottomSheet',
@@ -769,7 +834,16 @@ function StandaloneBottomSheet({
// that contains no presented sheet is marked inert and hidden as well, so
// the state is explicit; one that does contain the top sheet is left alone,
// because inert on it would reach the top sheet too.
- const isInert = isExiting || stackView.isBlocked;
+ // A sheet that closes with focus inside it is neither inert nor hidden
+ // while that focus stays: `inert` would drop the focus to the page, and
+ // `aria-hidden` would hide the focused control. When the exit ends, the
+ // dialog closes and focus returns in the same task. When focus leaves the
+ // sheet first (into a sheet opened above it, for example), the sheet goes
+ // inert at once. Until the close settles, no closing sheet is inert, so the
+ // first commit of a close never hides focus.
+ const isExitHoldingFocus =
+ isExiting && !isReplaced && (!isCloseSettled || isExitFocusHeld);
+ const isInert = (isExiting && !isExitHoldingFocus) || stackView.isBlocked;
return (
<dialog
@@ -784,6 +858,7 @@ function StandaloneBottomSheet({
hasScrim && styles.scrim,
hasScrim && isEntrySettled && styles.scrimSettled,
hasScrim && isExiting && styles.scrimClosing,
+ isExitHoldingFocus && styles.exitHoldingFocus,
!hasScrim && styles.dialogNonModal,
)}
ref={dialogComposedRef}
@@ -805,6 +880,11 @@ function StandaloneBottomSheet({
hasScrim && stackView.depth > 0 ? stackView.depth : undefined
}
onCancel={handleCancel}
+ // A closing sheet that keeps focus takes no activation during its
+ // exit: no click and no key but Tab reaches the control that has focus.
+ onClickCapture={isExitHoldingFocus ? ignoreActivation : undefined}
+ onKeyDownCapture={isExitHoldingFocus ? ignoreKeyDuringExit : undefined}
+ onKeyUpCapture={isExitHoldingFocus ? ignoreKeyDuringExit : undefined}
// Presses inside the sheet do not reach handlers around where it is
// written. The dialog, not the panel, is the root, as in a switcher.
{...layerClickBoundary({onClick: handleClick})}>
diff --git a/packages/core/src/BottomSheet/BottomSheetCloseFocus.test.tsx b/packages/core/src/BottomSheet/BottomSheetCloseFocus.test.tsx
new file mode 100644
index 0000000000..c137d1b101
--- /dev/null
+++ b/packages/core/src/BottomSheet/BottomSheetCloseFocus.test.tsx
@@ -0,0 +1,270 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file BottomSheetCloseFocus.test.tsx
+ * @input Uses vitest, @testing-library/react and BottomSheet
+ * @output Tests the close order for focus: a sheet that closes with focus
+ * inside it is neither inert nor aria-hidden while that focus stays, takes
+ * no pointer or keyboard activation, and when the exit ends closes and
+ * returns focus to the opener; a sheet that focus leaves, or that closes
+ * with focus elsewhere, is inert and hidden at once
+ * @position Core testing; validates the exit inertness in BottomSheet.tsx
+ */
+
+import {act, fireEvent, render, screen} from '@testing-library/react';
+import {useState} from 'react';
+import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
+import {BottomSheet} from './BottomSheet';
+import {resetBottomSheetStackForTests} from './bottomSheetStack';
+import {__resetInteractionModalityForTest} from '../utils/interactionModality';
+
+beforeEach(() => {
+ resetBottomSheetStackForTests();
+ __resetInteractionModalityForTest();
+ HTMLDialogElement.prototype.showModal = vi.fn(function (
+ this: HTMLDialogElement,
+ ) {
+ this.setAttribute('open', '');
+ });
+ HTMLDialogElement.prototype.close = vi.fn(function (this: HTMLDialogElement) {
+ this.removeAttribute('open');
+ });
+ window.scrollTo = vi.fn();
+ vi.stubGlobal(
+ 'matchMedia',
+ vi.fn().mockReturnValue({
+ matches: false,
+ media: '',
+ onchange: null,
+ addEventListener: vi.fn(),
+ removeEventListener: vi.fn(),
+ addListener: vi.fn(),
+ removeListener: vi.fn(),
+ dispatchEvent: vi.fn(),
+ }),
+ );
+});
+
+afterEach(() => {
+ vi.unstubAllGlobals();
+});
+
+function Filters() {
+ const [isOpen, setIsOpen] = useState(false);
+ return (
+ <>
+ <button type="button" onClick={() => setIsOpen(true)}>
+ Filters
+ </button>
+ <BottomSheet isOpen={isOpen} onOpenChange={setIsOpen} label="Filters">
+ <button type="button" onClick={() => setIsOpen(false)}>
+ Done
+ </button>
+ </BottomSheet>
+ </>
+ );
+}
+
+function sheet(): HTMLDialogElement {
+ const dialog = document.querySelector<HTMLDialogElement>(
+ 'dialog[aria-label="Filters"]',
+ );
+ if (dialog == null) {
+ throw new Error('sheet not found');
+ }
+ return dialog;
+}
+
+function finishExit() {
+ const panel = sheet().querySelector<HTMLElement>('.astryx-bottom-sheet');
+ if (panel == null) {
+ throw new Error('sheet panel not found');
+ }
+ fireEvent.transitionEnd(panel, {propertyName: 'transform'});
+}
+
+function openFilters() {
+ render(<Filters />);
+ const opener = screen.getByRole('button', {name: 'Filters'});
+ act(() => opener.focus());
+ fireEvent.click(opener);
+ return opener;
+}
+
+describe('BottomSheet close order for focus', () => {
+ it('keeps a closing sheet out of inert and aria-hidden while focus is inside', () => {
+ openFilters();
+ const done = screen.getByRole('button', {name: 'Done'});
+ act(() => done.focus());
+
+ fireEvent.click(done);
+
+ const dialog = sheet();
+ expect(dialog).toHaveAttribute('open');
+ expect(dialog).not.toHaveAttribute('aria-modal');
+ expect(dialog).not.toHaveAttribute('inert');
+ expect(dialog).not.toHaveAttribute('aria-hidden');
+ expect(done).toHaveFocus();
+ });
+
+ it('does not run the closing control again during the exit', () => {
+ let presses = 0;
+ function Counting() {
+ const [isOpen, setIsOpen] = useState(true);
+ return (
+ <BottomSheet isOpen={isOpen} onOpenChange={setIsOpen} label="Filters">
+ <button
+ type="button"
+ onClick={() => {
+ presses += 1;
+ setIsOpen(false);
+ }}>
+ Done
+ </button>
+ </BottomSheet>
+ );
+ }
+ render(<Counting />);
+ const done = screen.getByRole('button', {name: 'Done'});
+ act(() => done.focus());
+
+ // The first activation closes; a repeated Enter or Space during the exit
+ // dispatches another click on the still-focused control.
+ fireEvent.click(done);
+ fireEvent.click(done);
+
+ expect(presses).toBe(1);
+ expect(done).toHaveFocus();
+ });
+
+ it('does not pass Enter or Space to the focused control during the exit', () => {
+ let submits = 0;
+ function Search() {
+ const [isOpen, setIsOpen] = useState(true);
+ return (
+ <BottomSheet isOpen={isOpen} onOpenChange={setIsOpen} label="Filters">
+ <input
+ aria-label="Search"
+ onKeyDown={event => {
+ if (event.key === 'Enter') {
+ submits += 1;
+ setIsOpen(false);
+ }
+ }}
+ />
+ </BottomSheet>
+ );
+ }
+ render(<Search />);
+ const search = screen.getByRole('textbox', {name: 'Search'});
+ act(() => search.focus());
+
+ fireEvent.keyDown(search, {key: 'Enter'});
+ fireEvent.keyDown(search, {key: 'Enter'});
+ fireEvent.keyDown(search, {key: ' '});
+
+ expect(submits).toBe(1);
+ expect(search).toHaveFocus();
+ });
+
+ it('stops every key but Tab during the exit', () => {
+ const keys: string[] = [];
+ function Search() {
+ const [isOpen, setIsOpen] = useState(true);
+ return (
+ <BottomSheet isOpen={isOpen} onOpenChange={setIsOpen} label="Filters">
+ <input
+ aria-label="Search"
+ onKeyDown={event => {
+ keys.push(event.key);
+ if (event.key === 'Enter') {
+ setIsOpen(false);
+ }
+ }}
+ />
+ </BottomSheet>
+ );
+ }
+ render(<Search />);
+ const search = screen.getByRole('textbox', {name: 'Search'});
+ act(() => search.focus());
+ fireEvent.keyDown(search, {key: 'Enter'});
+
+ const letter = fireEvent.keyDown(search, {key: 'a'});
+ const backspace = fireEvent.keyDown(search, {key: 'Backspace'});
+ const arrow = fireEvent.keyDown(search, {key: 'ArrowDown'});
+ const tab = fireEvent.keyDown(search, {key: 'Tab'});
+
+ // fireEvent returns false when the event was cancelled.
+ expect([letter, backspace, arrow]).toEqual([false, false, false]);
+ expect(tab).toBe(true);
+ expect(keys).toEqual(['Enter', 'Tab']);
+ });
+
+ it('goes inert and hidden once its focused control is removed during the exit', async () => {
+ function Removing({isDoneShown}: {isDoneShown: boolean}) {
+ const [isOpen, setIsOpen] = useState(true);
+ return (
+ <BottomSheet isOpen={isOpen} onOpenChange={setIsOpen} label="Filters">
+ {isDoneShown && (
+ <button type="button" onClick={() => setIsOpen(false)}>
+ Done
+ </button>
+ )}
+ </BottomSheet>
+ );
+ }
+ const {rerender} = render(<Removing isDoneShown />);
+ const done = screen.getByRole('button', {name: 'Done'});
+ act(() => done.focus());
+ fireEvent.click(done);
+ expect(sheet()).not.toHaveAttribute('inert');
+
+ rerender(<Removing isDoneShown={false} />);
+ await act(async () => {
+ await Promise.resolve();
+ });
+
+ expect(sheet()).toHaveAttribute('inert');
+ expect(sheet()).toHaveAttribute('aria-hidden', 'true');
+ });
+
+ it('goes inert and hidden once focus leaves it during the exit', async () => {
+ openFilters();
+ const done = screen.getByRole('button', {name: 'Done'});
+ act(() => done.focus());
+ fireEvent.click(done);
+ expect(sheet()).not.toHaveAttribute('inert');
+
+ await act(async () => {
+ screen.getByRole('button', {name: 'Filters'}).focus();
+ await Promise.resolve();
+ });
+
+ expect(sheet()).toHaveAttribute('inert');
+ expect(sheet()).toHaveAttribute('aria-hidden', 'true');
+ });
+
+ it('closes and returns focus to the opener when the exit ends', () => {
+ const opener = openFilters();
+ const done = screen.getByRole('button', {name: 'Done'});
+ act(() => done.focus());
+ fireEvent.click(done);
+
+ finishExit();
+
+ expect(opener).toHaveFocus();
+ expect(sheet()).not.toHaveAttribute('open');
+ });
+
+ it('marks a closing sheet inert and hidden at once when focus is elsewhere', () => {
+ openFilters();
+ const done = screen.getByRole('button', {name: 'Done'});
+ act(() => (document.activeElement as HTMLElement | null)?.blur());
+
+ fireEvent.click(done);
+
+ expect(sheet()).toHaveAttribute('inert');
+ expect(sheet()).toHaveAttribute('aria-hidden', 'true');
+ });
+});
diff --git a/packages/core/src/BottomSheet/BottomSheetStacking.test.tsx b/packages/core/src/BottomSheet/BottomSheetStacking.test.tsx
index 1b006efd13..c311eeed56 100644
--- a/packages/core/src/BottomSheet/BottomSheetStacking.test.tsx
+++ b/packages/core/src/BottomSheet/BottomSheetStacking.test.tsx
@@ -2502,9 +2502,10 @@ describe('R11 non-modal sheets', () => {
: nativeMatches(selectors),
);
fireEvent.click(screen.getByRole('button', {name: 'Swap'}));
- // The modal sheet is mid-exit: still an open modal dialog, but inert.
+ // The modal sheet is mid-exit: still an open modal dialog. Focus was
+ // inside it at the close, so it is not inert until its exit ends.
expect(modal).toHaveAttribute('open');
- expect(modal).toHaveAttribute('inert');
+ expect(modal).not.toHaveAttribute('aria-modal');
expect(modal.matches(':modal')).toBe(true);
expect(HTMLElement.prototype.showPopover).toHaveBeenCalledTimes(1);
expect(HTMLDialogElement.prototype.show).not.toHaveBeenCalled();
diff --git a/packages/core/src/BottomSheet/__tests__/BottomSheetExitFocus.a11y.browser.spec.ts b/packages/core/src/BottomSheet/__tests__/BottomSheetExitFocus.a11y.browser.spec.ts
new file mode 100644
index 0000000000..4a9e4b9a87
--- /dev/null
+++ b/packages/core/src/BottomSheet/__tests__/BottomSheetExitFocus.a11y.browser.spec.ts
@@ -0,0 +1,106 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+// @pr-a11y always
+
+/**
+ * @file BottomSheetExitFocus.a11y.browser.spec.ts
+ * @input The `Core/BottomSheet` exit-focus fixtures in a built Storybook: Done
+ * closes the sheet, and during the exit the Done control is removed or
+ * disabled.
+ * @output Real-engine proof that a closing sheet that held focus goes inert
+ * and aria-hidden as soon as that focus drops to the page, while its exit
+ * still runs.
+ * @position Chromium and WebKit; the disabled case runs in Chromium only. The
+ * removed case needs a real engine: React drops Chromium's focusout for an
+ * element it removes, and WebKit sends none.
+ */
+
+import {expect, test, type Page} from '@playwright/test';
+import {
+ DEFAULT_STORYBOOK_DIR,
+ serveStorybook,
+ type StaticServer,
+} from '@astryxdesign/a11y-spec/storybook';
+
+let storybook: StaticServer;
+test.beforeAll(async () => {
+ storybook = await serveStorybook(
+ process.env.ASTRYX_STORYBOOK_DIR ?? DEFAULT_STORYBOOK_DIR,
+ );
+});
+test.afterAll(async () => {
+ await storybook?.close();
+});
+
+/**
+ * Opens the fixture, closes it from Done with the keyboard, and resolves with
+ * whether the still-open dialog was ever inert and aria-hidden with focus
+ * outside it before it closed. The exit is short, so the page watches every
+ * attribute change instead of polling.
+ */
+async function sawInertExit(page: Page, story: string): Promise<boolean> {
+ await page.goto(
+ `${storybook.origin}/iframe.html?id=core-bottomsheet--${story}&viewMode=story`,
+ );
+ const opener = page.getByRole('button', {name: 'Open sheet', exact: true});
+ await opener.focus();
+ await page.keyboard.press('Enter');
+ const done = page.getByRole('button', {name: 'Done', exact: true});
+ await expect(done).toBeVisible();
+ // A close during the entrance reverses it; let the sheet settle first so
+ // the close plays a full exit.
+ const dialog = page.locator('dialog[aria-label="Exit focus"]');
+ await expect
+ .poll(async () =>
+ dialog.evaluate(node => node.getAnimations({subtree: true}).length),
+ )
+ .toBe(0);
+ await done.focus();
+ const result = page.evaluate(
+ async () =>
+ new Promise<boolean>(resolve => {
+ const dialog = document.querySelector<HTMLDialogElement>(
+ 'dialog[aria-label="Exit focus"]',
+ );
+ if (dialog == null) {
+ resolve(false);
+ return;
+ }
+ const check = () => {
+ if (!dialog.open) {
+ observer.disconnect();
+ resolve(false);
+ } else if (
+ dialog.hasAttribute('inert') &&
+ dialog.getAttribute('aria-hidden') === 'true' &&
+ !dialog.contains(document.activeElement)
+ ) {
+ observer.disconnect();
+ resolve(true);
+ }
+ };
+ const observer = new MutationObserver(check);
+ observer.observe(dialog, {
+ attributes: true,
+ attributeFilter: ['open', 'inert', 'aria-hidden'],
+ });
+ }),
+ );
+ await page.keyboard.press('Enter');
+ return result;
+}
+
+for (const [story, change] of [
+ ['exit-focus-control-removed', 'removed'],
+ ['exit-focus-control-disabled', 'disabled'],
+] as const) {
+ test(`goes inert once its focused control is ${change} during the exit`, async ({
+ page,
+ browserName,
+ }) => {
+ test.skip(
+ change === 'disabled' && browserName !== 'chromium',
+ 'Where focus goes from a disabled control is engine-specific; Chromium moves it to the page.',
+ );
+ expect(await sawInertExit(page, story)).toBe(true);
+ });
+}
diff --git a/packages/core/src/BottomSheet/bottomSheetStack.ts b/packages/core/src/BottomSheet/bottomSheetStack.ts
index 486716d073..7f70da5390 100644
--- a/packages/core/src/BottomSheet/bottomSheetStack.ts
+++ b/packages/core/src/BottomSheet/bottomSheetStack.ts
@@ -866,12 +866,16 @@ function openModalsOutside(element: Element): HTMLDialogElement[] {
if (dialog === element || dialog.contains(element)) {
continue;
}
- // A modal on its way out (a closing sheet keeps its dialog modal through
- // the exit animation, inert and hidden) blocks nothing any more: it is
- // gone for this decision.
+ // A modal on its way out blocks nothing any more: it is gone for this
+ // decision. A closing sheet keeps its dialog modal through the exit
+ // animation; it is inert and hidden then, unless focus was inside it at
+ // the close, so the registry's own record of the close counts too.
if (
dialog.hasAttribute('inert') ||
- dialog.getAttribute('aria-hidden') === 'true'
+ dialog.getAttribute('aria-hidden') === 'true' ||
+ state.entries.some(
+ entry => !entry.isOpen && entry.getElement() === dialog,
+ )
) {
continue;
}
diff --git a/packages/core/src/MultiSelector/MultiSelector.test.tsx b/packages/core/src/MultiSelector/MultiSelector.test.tsx
index c8785b57a7..d280f5ada1 100644
--- a/packages/core/src/MultiSelector/MultiSelector.test.tsx
+++ b/packages/core/src/MultiSelector/MultiSelector.test.tsx
@@ -2583,7 +2583,9 @@ describe('MultiSelector', () => {
rerender(selector(true));
- await waitFor(() => expect(dialog).toHaveAttribute('inert'));
+ // The sheet closes with focus inside it, so it stays out of inert
+ // through its exit (component:BottomSheet FR9).
+ await waitFor(() => expect(dialog).not.toHaveAttribute('aria-modal'));
fireEvent.transitionEnd(panel!, {propertyName: 'transform'});
const readOnlyTrigger = screen.getByRole('combobox', {name: 'Fruit'});
await waitFor(() => expect(readOnlyTrigger).toHaveFocus());
diff --git a/packages/core/src/Selector/Selector.test.tsx b/packages/core/src/Selector/Selector.test.tsx
index c87c7c9256..7d767f73ce 100644
--- a/packages/core/src/Selector/Selector.test.tsx
+++ b/packages/core/src/Selector/Selector.test.tsx
@@ -3112,7 +3112,9 @@ describe('Selector', () => {
rerender(selector(true));
- await waitFor(() => expect(dialog).toHaveAttribute('inert'));
+ // The sheet starts its exit; focus stays inside it until the exit
+ // ends, so it is not inert yet.
+ await waitFor(() => expect(dialog).not.toHaveAttribute('aria-modal'));
fireEvent.transitionEnd(panel!, {propertyName: 'transform'});
const readOnlyTrigger = screen.getByRole('combobox', {name: 'Fruit'});
await waitFor(() => expect(readOnlyTrigger).toHaveFocus());
diff --git a/packages/core/src/Toast/ToastViewport.modalHost.test.tsx b/packages/core/src/Toast/ToastViewport.modalHost.test.tsx
index 511e6a0ca2..1b600c1281 100644
--- a/packages/core/src/Toast/ToastViewport.modalHost.test.tsx
+++ b/packages/core/src/Toast/ToastViewport.modalHost.test.tsx
@@ -534,10 +534,10 @@ describe('ToastViewport above a BottomSheet', () => {
expect(viewport.closest('dialog')).toBe(getDialog('Filters'));
fireEvent.click(screen.getByRole('button', {name: 'Close Filters'}));
- // The sheet stays an open modal through its exit animation, but inert and
- // hidden; toasts must not go down with it.
+ // The sheet stays an open dialog through its exit animation, no longer
+ // modal and taking no presses; toasts must not go down with it.
expect(getDialog('Filters')).toHaveAttribute('open');
- expect(getDialog('Filters')).toHaveAttribute('inert');
+ expect(getDialog('Filters')).not.toHaveAttribute('aria-modal');
expect(viewport.closest('dialog')).toBe(getDialog('Edit'));
expect(viewport.closest('[inert], [aria-hidden="true"]')).toBeNull();
});
diff --git a/packages/core/src/Tokenizer/TokenizerBottomSheet.test.tsx b/packages/core/src/Tokenizer/TokenizerBottomSheet.test.tsx
index 6aec0631f6..d561b409f3 100644
--- a/packages/core/src/Tokenizer/TokenizerBottomSheet.test.tsx
+++ b/packages/core/src/Tokenizer/TokenizerBottomSheet.test.tsx
@@ -1271,7 +1271,9 @@ describe('Tokenizer sheet presentation (single-sheet touch flow)', () => {
/>,
);
expect(trigger).toHaveAttribute('aria-expanded', 'false');
- expect(dialog).toHaveAttribute('aria-hidden', 'true');
+ // Focus is in the search field, so the closing sheet stays out of inert
+ // and aria-hidden until its exit ends (component:BottomSheet FR9).
+ expect(dialog).not.toHaveAttribute('aria-modal');
// BottomSheet hands focus back after its exit motion.
fireEvent.transitionEnd(document.querySelector('.astryx-bottom-sheet')!, {
propertyName: 'transform',
diff --git a/packages/core/src/hooks/useAnnounce.modal.test.tsx b/packages/core/src/hooks/useAnnounce.modal.test.tsx
index ff33d672c8..afd54d2459 100644
--- a/packages/core/src/hooks/useAnnounce.modal.test.tsx
+++ b/packages/core/src/hooks/useAnnounce.modal.test.tsx
@@ -848,6 +848,9 @@ describe('useAnnounce inside Astryx modals (spec:AST-086 FR14)', () => {
const sheet = document.querySelector<HTMLDialogElement>('dialog')!;
await nextFrame();
fireEvent.click(screen.getByRole('button', {name: 'Say'}));
+ // Focus is outside the sheet, so it goes inert from the close
+ // (component:BottomSheet FR9).
+ act(() => (document.activeElement as HTMLElement | null)?.blur());
fireEvent.click(screen.getByRole('button', {name: 'Done'}));
// The sheet keeps its dialog open and modal while it leaves, but takes
// it out of the accessibility tree; the page body is behind an active
@@ -884,6 +887,9 @@ describe('useAnnounce inside Astryx modals (spec:AST-086 FR14)', () => {
const sheet = document.querySelector<HTMLDialogElement>('dialog')!;
await nextFrame();
fireEvent.click(screen.getByRole('button', {name: 'Busy'}));
+ // Focus is outside the sheet, so it goes inert from the close
+ // (component:BottomSheet FR9).
+ act(() => (document.activeElement as HTMLElement | null)?.blur());
fireEvent.click(screen.getByRole('button', {name: 'Done'}));
// Held for the real close, as the sheet-exit test shows...
expect(sheet).toHaveAttribute('inert');
@@ -1108,6 +1114,9 @@ describe('useAnnounce inside Astryx modals (spec:AST-086 FR14)', () => {
const sheet = screen.getByRole('dialog', {name: 'Sheet'});
await nextFrame();
fireEvent.click(screen.getByRole('button', {name: 'Say'}));
+ // Focus is outside the sheet, so it goes inert from the close
+ // (component:BottomSheet FR9).
+ act(() => (document.activeElement as HTMLElement | null)?.blur());
fireEvent.click(screen.getByRole('button', {name: 'Done'}));
// The sheet, still an open modal through its exit, covers the Dialog:
// nothing is exposed yet, so the words wait rather than being written
diff --git a/packages/core/src/hooks/useAnnounce.replace.test.tsx b/packages/core/src/hooks/useAnnounce.replace.test.tsx
index 1244d0ce60..7c48752f2e 100644
--- a/packages/core/src/hooks/useAnnounce.replace.test.tsx
+++ b/packages/core/src/hooks/useAnnounce.replace.test.tsx
@@ -296,6 +296,9 @@ describe('useAnnounce({hasReplace}) inside an Astryx modal (spec:AST-086 FR14)',
render(<ExitingSheet />);
const sheet = document.querySelector<HTMLDialogElement>('dialog')!;
await nextFrame();
+ // Focus is outside the sheet, so it goes inert from the close
+ // (component:BottomSheet FR9).
+ act(() => (document.activeElement as HTMLElement | null)?.blur());
fireEvent.click(screen.getByRole('button', {name: 'Done'}));
// Open but inert and aria-hidden through its exit: the words are held
// for the real close (reach the controls by element).
@@ -374,6 +377,9 @@ describe('useAnnounce({hasReplace}) inside an Astryx modal (spec:AST-086 FR14)',
await nextFrame();
// Written, and the sheet starts its exit before the words are exposed.
fireEvent.click(screen.getByRole('button', {name: 'Count'}));
+ // Focus is outside the sheet, so it goes inert from the close
+ // (component:BottomSheet FR9).
+ act(() => (document.activeElement as HTMLElement | null)?.blur());
fireEvent.click(screen.getByRole('button', {name: 'Done'}));
expect(sheet).toHaveAttribute('inert');
// The sheet's provider sees the exit and hands the words off.
diff --git a/packages/lab/src/MobilePowerSearch/MobilePowerSearch.test.tsx b/packages/lab/src/MobilePowerSearch/MobilePowerSearch.test.tsx
index b5f9c564a0..e13e4d7f69 100644
--- a/packages/lab/src/MobilePowerSearch/MobilePowerSearch.test.tsx
+++ b/packages/lab/src/MobilePowerSearch/MobilePowerSearch.test.tsx
@@ -1859,6 +1859,10 @@ describe('MobilePowerSearch content search', () => {
expect(
within(sheet()).getByRole('heading', {name: 'Filters'}),
).toBeTruthy();
+ // The search sheet held focus as it closed, so words sent with the close
+ // wait for its exit to end (component:BottomSheet FR9, spec:AST-086
+ // FR14); settle that exit.
+ act(() => settleSheets());
// The add is announced inside the sheet the flow is now on, not on the
// page body, which assistive technology does not expose under a native
// modal dialog.
@@ -1893,6 +1897,10 @@ describe('MobilePowerSearch content search', () => {
within(sheet()).getByRole('button', {name: '"release notes"'}),
);
await waitFor(() => expect(isSheetOpen()).toBe(true));
+ // The search sheet held focus as it closed, so words sent with the close
+ // wait for its exit to end (component:BottomSheet FR9, spec:AST-086
+ // FR14); settle that exit.
+ act(() => settleSheets());
await waitFor(() =>
expect(sheetRegion().textContent).toBe(
'Added "release notes" 20 results',
diff --git a/packages/lab/src/MobileTokenizer/MobileTokenizer.test.tsx b/packages/lab/src/MobileTokenizer/MobileTokenizer.test.tsx
index f0e23d8c48..3df60093e4 100644
--- a/packages/lab/src/MobileTokenizer/MobileTokenizer.test.tsx
+++ b/packages/lab/src/MobileTokenizer/MobileTokenizer.test.tsx
@@ -1248,6 +1248,7 @@ describe('MobileTokenizer Core-sheet parity', () => {
);
}
render(<Flow />);
+ const trigger = screen.getByRole('button', {name: /Tags/});
const sheet = await openSheet();
// Pending from open until the bootstrap settles.
expect(within(sheet).getByRole('img', {name: 'Loading'})).toBeTruthy();
@@ -1264,11 +1265,8 @@ describe('MobileTokenizer Core-sheet parity', () => {
// The field becomes disabled while open: the sheet closes and the query
// is kept; re-enabled and reopened, it starts from "en", settled.
fireEvent.click(screen.getByRole('button', {name: 'Toggle'}));
- expect(screen.getByRole('button', {name: /Tags/})).toHaveAttribute(
- 'aria-expanded',
- 'false',
- );
- act(() => screen.getByRole('button', {name: /Tags/}).focus());
+ expect(trigger).toHaveAttribute('aria-expanded', 'false');
+ act(() => trigger.focus());
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
fireEvent.click(screen.getByRole('button', {name: 'Toggle'}));
const reopened = await openSheet();