An open source design system that's fully customizable and agent ready
TypeScript
fix(Drawer): a scrimless drawer announces its top-layer entry, so toasts stay above it (#9594)
Cindy Zhang0f12096d3c69
diff --git a/.changeset/drawer-nonmodal-toasts.md b/.changeset/drawer-nonmodal-toasts.mdnew file mode 100644index 0000000000..b223ae3567--- /dev/null+++ b/.changeset/drawer-nonmodal-toasts.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] A toast shown before a `Drawer` without its scrim (`hasScrim={false}`) opens now stays above the drawer, as it already does above a scrimless `BottomSheet`. Before, the drawer painted over it, so where the drawer covered the toast's corner its action could not be seen or pressed.++@cixzhang @duytbpdiff --git a/apps/storybook/stories/Toast.stories.tsx b/apps/storybook/stories/Toast.stories.tsxindex f61bb76fb2..98fc3aa887 100644--- a/apps/storybook/stories/Toast.stories.tsx+++ b/apps/storybook/stories/Toast.stories.tsx@@ -832,6 +832,54 @@ export const AppToastOverDrawer: StoryObj = {},};+export const AppToastOverNonModalDrawer: StoryObj = {+ render: function AppToastOverNonModalDrawerStory() {+ const [isOpen, setIsOpen] = useState(false);+ const [status, setStatus] = useState('The filters are saved.');+ const toast = useToast();+ return (+ <ToastViewport>+ <Stack gap={2}>+ <p>{status}</p>+ <Button+ label="Save filters"+ onClick={() =>+ toast({+ body: 'Filters saved',+ isAutoHide: false,+ endContent: (+ <Button+ label="Undo"+ variant="secondary"+ size="sm"+ onClick={() => setStatus('The save is undone.')}+ />+ ),+ })+ }+ />+ <Button label="Open filters" onClick={() => setIsOpen(true)} />+ </Stack>+ <Drawer+ isOpen={isOpen}+ onOpenChange={setIsOpen}+ hasScrim={false}+ label="Filters">+ <p>Filter options</p>+ </Drawer>+ </ToastViewport>+ );+ },+ parameters: {+ docs: {+ description: {+ story:+ "The app's own `ToastViewport` and a `Drawer` without its scrim: a toast shown before the drawer opens stays above it, so its action stays clickable while the drawer covers its corner.",+ },+ },+ },+};+function SheetToastContent({openLabel}: {openLabel: string}) {const [isOpen, setIsOpen] = useState(false);const [status, setStatus] = useState('The item is in your inbox.');diff --git a/docs/architecture/layer-runtime.md b/docs/architecture/layer-runtime.mdindex 8a6ee9e8e2..226a93adb3 100644--- a/docs/architecture/layer-runtime.md+++ b/docs/architecture/layer-runtime.md@@ -426,14 +426,14 @@ outlets, and a non-modal top-layer surface that blocks nothing and announcesitself — a `hasScrim={false}` BottomSheet in the top layer with no backdrop(while a modal that does not contain it is open it stays beneath that modal,outside the top layer, and enters — announcing then — once that modal has-gone). How such a surface is put in the top layer is the component's own-today, inside the INV14 gap below; the rule here is only that it announces-its entry through the same registry, and that the viewport then leaves and-re-enters the top layer in place, keeping focus inside it, so toasts paint-above it too. A non-modal top-layer surface that does not announce itself is-outside the rule: a `hasScrim={false}` Drawer (`popover="manual"`,-`showPopover()`) shown after the viewport covers toasts raised while it is-open; the rule does not cover it. In a stack of scrim BottomSheets the latest+gone), and a `hasScrim={false}` Drawer, which announces once its+`showPopover()` has put it in the top layer. How such a surface is put in the+top layer is the component's own today, inside the INV14 gap below; the rule+here is only that it announces its entry through the same registry, and that+the viewport then leaves and re-enters the top layer in place, keeping focus+inside it, so toasts paint above it too. A non-modal surface shown with+`show()` below the Popover API support floor is not in the top layer and+announces nothing. In a stack of scrim BottomSheets the latestoutlet is the top sheet, so toasts paint above the whole stack. Toast statelives inside the viewport. A viewport rendered with `isTopLayer={false}` staysin place.diff --git a/docs/specs/components/Drawer/Drawer.spec.md b/docs/specs/components/Drawer/Drawer.spec.mdindex 09ff0736c7..a65cee4a90 100644--- a/docs/specs/components/Drawer/Drawer.spec.md+++ b/docs/specs/components/Drawer/Drawer.spec.md@@ -174,6 +174,7 @@ Consumer prop syntax and examples remain in `Drawer.doc.mjs`.| FR16 | The Content area pads caller content by the drawer's container inset, `--spacing-4` by default as in Dialog, and publishes the applied inset to descendants as a container publisher would; `architecture:container-padding` does not yet admit Drawer as one (Current-state impact). Its block-end edge applies the container inset plus the home-indicator safe area while publishing the inset alone, so a bleed child subtracts only the inset and the safe area survives below it. The root dialog keeps the container-padding reset (FR12). | `architecture:container-padding`; container padding suite || FR17 | A Drawer open on the server renders closed until hydration (no open styles, no `aria-modal`, the markup of a closed Drawer) 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 || FR18 | While a modal Drawer (`hasScrim`) is open it supplies its `<dialog>` as the passive global outlet, so app-global surfaces such as toasts render inside it, paint above it, and stay operable and reachable by keyboard; it stops supplying when it starts to close, so they return to their place and are not carried out with the exit. Moving them keeps toast entries, timers, and focus handoff (`spec:AST-003` FR18, FR19). A non-modal Drawer supplies no outlet (`architecture:layer-runtime`). | `spec:AST-003` FR18 |+| FR19 | When a non-modal Drawer (`hasScrim={false}`) enters the top layer through `showPopover()`, 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 drawer; the drawer supplies no outlet, and its close moves and re-enters nothing (`architecture:layer-runtime`). | `architecture:layer-runtime` |### Allowed variation@@ -325,6 +326,7 @@ block is optional during migration, so the map is deferred.| AR6 | `DrawerDirection.test.tsx` DOM-direction and closed/entry parity suites plus exact-head Storybook RTL evidence | start/end; self-applied, inherited, and nested opposite `dir`; closed and opening transforms | Any effective DOM direction or local override moves the panel from a different edge than its logical placement, or closed and opening transforms diverge. | `audit:Drawer/accessibility` || FR17 | `Drawer.ssr.test.tsx` | Open on the server; hydration; a closed Drawer'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:Drawer/accessibility` || FR18 | `ToastViewport.modalHost.test.tsx` "ToastViewport above a Drawer" suite; `DrawerToastOutlet.a11y.chromium.spec.ts` (hit testing, click and Tab at desktop and phone widths) | modal drawer opened over a page toast; toast raised from inside the drawer; drawer closing; drawer without a scrim | A toast viewport left outside an open modal drawer, a toast carried out with the closing drawer, a remounted toast row, or a non-modal drawer that takes the viewport fails. | `audit:Drawer/accessibility` |+| FR19 | `ToastViewport.modalHost.test.tsx` "ToastViewport above a Drawer" non-modal case; `DrawerToastOutlet.a11y.chromium.spec.ts` non-modal case | a toast shown before a scrimless drawer opens over its corner; the drawer closing | A toast the scrimless drawer covers, a viewport moved into the drawer, or a re-entry on close fails. | `audit:Drawer/accessibility` |Read from source, with no focused test yet:diff --git a/docs/specs/components/Toast/Toast.spec.md b/docs/specs/components/Toast/Toast.spec.mdindex 6e29506136..0c4a314606 100644--- a/docs/specs/components/Toast/Toast.spec.md+++ b/docs/specs/components/Toast/Toast.spec.md@@ -193,7 +193,7 @@ Consumer migration instructions belong in consumer docs and release notes.| FR9 | Each shown toast has one announcement owner (`spec:AST-086` FR1): the viewport announces it once, when it is shown, `error` assertively and `info` politely, using the toast's text content, through its own persistent polite and assertive containers, which move with it into a modal (`spec:AST-086` FR10). Unrelated renders do not re-announce. Implementation gaps: the viewport announces through the shared body-level channel, which a modal hides, and announces at dispatch rather than when a toast appears (Current-state impact). | `spec:AST-086`; tests || FR10 | F6 moves focus to the first control in the newest toast. Focus entering the viewport, by F6, Tab or a click, records where it was. Dismissing a toast that holds focus moves focus to a control in a remaining toast, or back to the remembered element when none remain. Implementation gap: with no control in the target toast, F6 leaves focus where it was and the handoff drops focus to the page (Current-state impact). | Current source and tests || FR11 | While a toast is visible the viewport is a `region` landmark named by `@astryx.toast.viewport`, without `aria-modal`; it exposes no landmark when empty, so an empty nested viewport adds none. Implementation gap: nested viewports that each hold a toast expose two landmarks (Current-state impact). | Current source and tests |-| FR12 | A top-layer viewport moves into the latest open Dialog, modal Drawer, scrim sheet, or modal flow step, following the top of a stack and handing back to the one beneath when it closes, and returns to its place when none remains, keeping each toast, its timer, and focus inside the viewport. It re-enters the top layer in place when a non-modal sheet opens after it, and stays in place when rendered in place, or when an inline dialog, a sheet without a scrim, or a non-modal flow opens. | `spec:AST-003`; tests |+| FR12 | A top-layer viewport moves into the latest open Dialog, modal Drawer, scrim sheet, or modal flow step, following the top of a stack and handing back to the one beneath when it closes, and returns to its place when none remains, keeping each toast, its timer, and focus inside the viewport. It re-enters the top layer in place when a non-modal sheet or a drawer without a scrim opens after it, and stays in place when rendered in place, or when an inline dialog, a sheet without a scrim, or a non-modal flow opens. | `spec:AST-003`; tests |### Allowed variation@@ -260,7 +260,7 @@ button), so no anatomy part can own the `toast` target.| FR4, FR5 | `ToastViewport.test.tsx` gesture and motion tests | Pen and touch thresholds, short drag, horizontal intent, second touch, interactive descendant, RTL | A dismissal from a rejected gesture, a lost snap-back, or off-axis drift fails. | `audit:Toast/behavior` || FR6–FR8 | `ToastViewport.test.tsx` placement, cap, and uniqueID tests; `Layer/LayerProvider.test.tsx` inset tests | Each position, cap 1 and an explicit cap, overwrite, ignore | Wrong order, cap, or collision fails. | `audit:Toast/layout` || FR9–FR11 | `ToastViewport.test.tsx` announcement, F6, focus, landmark tests | Info, error, StrictMode, nested viewports | A repeated or wrong-urgency announcement, or focus to the body after F6 entry, fails. | `audit:Toast/accessibility` |-| FR12 | `ToastViewport.modalHost.test.tsx` | Dialog, nested dialogs, modal drawers, sheets and sheet stacks, modal flows | A lost toast, timer, or focus, or the wrong outlet, fails. | `audit:Toast/layering` |+| FR12 | `ToastViewport.modalHost.test.tsx` | Dialog, nested dialogs, modal and scrimless drawers, sheets and sheet stacks, modal flows | A lost toast, timer, or focus, or the wrong outlet, fails. | `audit:Toast/layering` |Read from source, with no focused test yet:diff --git a/packages/core/src/Drawer/__tests__/DrawerToastOutlet.a11y.chromium.spec.ts b/packages/core/src/Drawer/__tests__/DrawerToastOutlet.a11y.chromium.spec.tsindex 6fd556b517..2e09799ee0 100644--- a/packages/core/src/Drawer/__tests__/DrawerToastOutlet.a11y.chromium.spec.ts+++ b/packages/core/src/Drawer/__tests__/DrawerToastOutlet.a11y.chromium.spec.ts@@ -6,7 +6,8 @@* @input The built Core/Toast AppToastOverDrawer story; real Chromium hit* testing, mouse and keyboard input* @output Browser evidence that a toast fired from an open modal Drawer is- * hit-testable above the drawer, takes a click, and is reached with Tab+ * hit-testable above the drawer, takes a click, and is reached with Tab, and+ * that a toast shown before a scrimless Drawer opens stays above it* @position Chromium proof for Drawer's modal outlet (Layer/modalOutlet.ts).* jsdom has no top layer and no modal inertness, so* Toast/ToastViewport.modalHost.test.tsx can only check where the viewport@@ -101,3 +102,36 @@ test('Tab reaches the toast action from inside a modal drawer', async ({}expect(reached).toBe(true);});++// A scrimless drawer is a manual popover that enters the top layer after the+// viewport: the viewport re-enters above it. Phone width, so the drawer+// covers the toast's corner.+test('a toast shown before a scrimless drawer opens stays above it', async ({+ page,+}) => {+ await page.setViewportSize({width: 390, height: 844});+ await page.goto(+ `${storybook.origin}/iframe.html?id=core-toast--app-toast-over-non-modal-drawer&viewMode=story`,+ );+ await holdMotionStill(page);+ await page.getByRole('button', {name: 'Save filters', exact: true}).click();+ const undo = page.locator('[popover] button', {hasText: 'Undo'});+ await expect(undo).toBeVisible();+ await page.getByRole('button', {name: 'Open filters', exact: true}).click();+ await expect(page.getByRole('dialog', {name: 'Filters'})).toBeVisible();++ const box = await undo.boundingBox();+ if (box == null) {+ throw new Error('the Undo button has no box');+ }+ const x = box.x + box.width / 2;+ const y = box.y + box.height / 2;+ const hit = await page.evaluate(+ ([px, py]) =>+ document.elementFromPoint(px, py)?.closest('button')?.textContent ?? null,+ [x, y],+ );+ expect(hit).toBe('Undo');+ await page.mouse.click(x, y);+ await expect(page.getByText('The save is undone.')).toBeVisible();+});diff --git a/packages/core/src/Drawer/useDrawerDialogPresence.ts b/packages/core/src/Drawer/useDrawerDialogPresence.tsindex 56b7ea34c3..a7c006a7ea 100644--- a/packages/core/src/Drawer/useDrawerDialogPresence.ts+++ b/packages/core/src/Drawer/useDrawerDialogPresence.ts@@ -32,6 +32,7 @@ import {type SetStateAction,} from 'react';import {flushSync} from 'react-dom';+import {notifyTopLayerEntry} from '../Layer/modalOutlet';/** Slack past the computed transition before the backstop gives up waiting. */const EXIT_BACKSTOP_BUFFER_MS = 50;@@ -71,6 +72,9 @@ function showDrawerHost(dialog: HTMLDialogElement, isModal: boolean): void {dialog.showModal();} else if (typeof dialog.showPopover === 'function') {dialog.showPopover();+ // The drawer is now the newest top-layer entry: global hosts shown before+ // it (the toast viewport) re-enter above it, as they do above a modal.+ notifyTopLayerEntry();} else {// Reduced fallback for browsers below the Popover API support floor.dialog.show();diff --git a/packages/core/src/Toast/ToastViewport.modalHost.test.tsx b/packages/core/src/Toast/ToastViewport.modalHost.test.tsxindex cdbf1c0629..254dfc4a67 100644--- a/packages/core/src/Toast/ToastViewport.modalHost.test.tsx+++ b/packages/core/src/Toast/ToastViewport.modalHost.test.tsx@@ -741,18 +741,44 @@ describe('ToastViewport above a Drawer', () => {);});- it('stays in place when a drawer without a scrim opens', () => {- trackPopoverState();+ it('re-enters the top layer in place when a drawer without a scrim opens after it', () => {+ // A `hasScrim={false}` drawer is a manual popover: it enters the top+ // layer above the viewport and blocks nothing, so the viewport stays+ // where it is and leaves and re-enters to paint above the drawer again.+ const {showPopover, hidePopover} = trackPopoverState();const {container} = render(<ToastViewport>+ <ToastButton /><DrawerFixture label="Candidate" hasScrim={false} /></ToastViewport>,);+ const viewport = getViewport();+ const onViewport = (spy: typeof showPopover) =>+ spy.mock.contexts.filter(context => context === viewport).length;+ fireEvent.click(screen.getByRole('button', {name: 'Show toast'}));+ expect(onViewport(showPopover)).toBe(1);+fireEvent.click(screen.getByRole('button', {name: 'Open Candidate'}));- // A non-modal drawer leaves the page operable, so it supplies no outlet.+ expect(getDialog('Candidate')).toHaveAttribute('popover', 'manual');+ // Re-entered (hide, then show) after the drawer's own showPopover, and+ // not moved: a non-modal drawer is not an outlet.+ expect(onViewport(hidePopover)).toBe(1);+ expect(onViewport(showPopover)).toBe(2);+ const drawerShow = showPopover.mock.contexts.indexOf(+ getDialog('Candidate'),+ );+ expect(drawerShow).toBeGreaterThan(-1);+ expect(showPopover.mock.contexts.lastIndexOf(viewport)).toBeGreaterThan(+ drawerShow,+ );expect(getViewport().closest('dialog')).toBeNull();expect(container.contains(getViewport())).toBe(true);expect(getActiveModalOutlet()).toBeNull();++ // Closing the drawer moves nothing and re-enters nothing.+ fireEvent.click(screen.getByRole('button', {name: 'Close Candidate'}));+ expect(onViewport(hidePopover)).toBe(1);+ expect(onViewport(showPopover)).toBe(2);});});