diff --git a/.changeset/toast-zero-inset.md b/.changeset/toast-zero-inset.md new file mode 100644 index 0000000000000..3e0760bdcc9ff --- /dev/null +++ b/.changeset/toast-zero-inset.md @@ -0,0 +1,7 @@ +--- +'@astryxdesign/core': patch +--- + +[fix] A `toast.inset` edge set to `0` now puts toasts flush to that edge. Before, a zero edge counted as unset, so the toast viewport kept the provider's inset there. + +@cixzhang diff --git a/docs/specs/components/Toast/Toast.spec.md b/docs/specs/components/Toast/Toast.spec.md index 506b320e314c1..bc15176405341 100644 --- a/docs/specs/components/Toast/Toast.spec.md +++ b/docs/specs/components/Toast/Toast.spec.md @@ -138,10 +138,9 @@ Consumer migration instructions belong in consumer docs and release notes. entrance, the row collapse, and the swipe's throw run for 0.01 ms on every pointer; a touch user gets no opacity fade, which `design:reduced-motion` DR2 calls for. -- **A zero toast inset does not override the provider.** A `toast.inset` edge - set to 0 keeps the provider's `layerInset` on that edge; `spec:AST-059` FR6 - has a set edge replace it. An inset edge opposite the position, such as - `top` for a bottom stack, moves the stack to that edge. +- **An inset edge opposite the position moves the stack.** A nonzero + `toast.inset` edge opposite the position, such as `top` for a bottom stack, + moves the stack to that edge. - **The viewport sets a page-level z-index.** The viewport carries `z-index: 500`; `spec:AST-027` FR1 keeps z-index local only, and FR8 orders floating surfaces through the browser top layer. @@ -190,23 +189,23 @@ FR4's first-move rule has two accepted tradeoffs, which are not gaps: ## Behavioral and layout contract -| ID | Invariant | Basis | -| ---- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| FR1 | A card carries `toast` with `type` and shows `body` and, on its first line, `endContent` then a dismiss Button named by `@astryx.toast.dismiss`; long body text wraps below. `renderContent` replaces that layout, receives `body`, `endContent`, `type`, timing, and a `dismiss` function, and gets no injected dismiss control. | Current source and tests | -| FR2 | With auto-hide on (the default for `info`, off for `error`), the card dismisses with reason `auto` after `autoHideDuration` ms. The timer pauses while the pointer is over the card, focus is inside it, a touch or pen gesture is active, or the window is blurred, and resumes with the remaining time (at least 1 s). Each pause condition holds the timer on its own: one ending resumes it only when no other still holds, and focus moving between the card's own controls keeps it held. A toast raised while the window is already blurred starts with its timer held. | Current source and tests | -| FR3 | The dismiss button, a swipe, a `dismiss` call, or the returned dismiss function dismiss with reason `manual`; `onHide` fires at most once, when the toast is dismissed, even when dismissed twice during its exit or before it shows. A toast replaced through `uniqueID` is not dismissed and reports no `onHide`. | Current source and tests | -| FR4 | A drag toward the position's block edge, from any pointer (`spec:AST-094` FR43), decides once, at release, per `spec:AST-094` FR36–FR37: projected travel past the commit point dismisses, and a release moving back toward the start cancels. A short drag snaps back; horizontal intent, a second touch, or a gesture starting on an interactive descendant does not dismiss. Native page scrolling continues until touch intent matches the dismiss edge. On a touch screen, the touch's first move decides: toward the dismiss edge, the swipe owns the touch. In the default layout the visible dismiss button stays as a non-gesture alternative; custom content supplies its own. Implementation gaps: the shipped rule dismisses on net travel past a distance threshold or a fast flick timed by its own average speed, even after the finger moves back, and recognizes only touch and pen drags, not a mouse (Current-state impact). | Current source and tests | -| FR5 | A new card slides in from its edge and fades in; a dismissed card collapses and fades before it unmounts; both slide only along the block axis. A dismissal without a swipe uses theme timing; a swipe's commit and snap-back start at the release velocity (`spec:AST-094` FR38). Under reduced motion the entrance and dismissal are an opacity-only fade of 200 ms or less on a coarse pointer or after a touch release (`design:reduced-motion` DR2) and immediate otherwise (DR3), and the card still unmounts. Implementation gaps: a swipe's settle is a CSS transition at theme timing, and under reduced motion every transition, including the row collapse and the swipe's throw, runs for 0.01 ms on every pointer (Current-state impact). | Current source and tests | -| FR6 | The viewport stacks toasts at `position`, newest nearest the configured edge, with an 8 px gap and no extra space at the edge beyond the safe-area gutter it keeps; it spans the inline axis within its inset, honoring start and end insets in either direction. The bottom gutter is 16 px beyond the bottom safe-area inset; under a coarse pointer it is 16 px beyond the larger of that inset and 34 px (`16px + max(env(safe-area-inset-bottom), 34px)`), so a toast clears the home indicator even where the page reports no inset. With a fine pointer and no inset it is 16 px. The 34 px floor is the iPhone home indicator's height; it applies on every coarse-pointer device, since browsers report the inset only when a page opts in. Each edge sits at the provider's `layerInset`, and a `toast.inset` edge, when set, replaces it (`spec:AST-059` FR6). Implementation gaps: a `toast.inset` edge set to 0 does not replace the provider's value, and an edge opposite the position, such as `top` for a bottom stack, moves the stack to that edge (Current-state impact). | Current source and tests | -| FR7 | With `maxVisible` of 1 or more, at most that many toasts show; when more are raised, the oldest wait hidden and return as visible toasts leave. `maxVisible={0}` shows every toast. | Current source and tests | -| FR8 | A toast whose `uniqueID` matches a toast the viewport holds, whether shown, hidden by the cap, or exiting, replaces it in place under `overwrite` (and is announced again; the card updates in place under the same key, so focus inside it stays on the same control, or moves per FR10 when that control no longer exists), and is dropped unshown and unannounced under `ignore`, even when both are raised before the first renders. Implementation gap: overwriting a toast hidden by the cap announces it while it is not shown, and nothing is announced when it surfaces (Current-state impact). | Current source and tests | -| 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. A top-layer viewport hosted in an open modal delivers through that modal's containers (`spec:AST-086` FR14); otherwise through the shared channel. A viewport the caller renders in place announces through `useAnnounce`, which delivers through an enclosing modal's containers (`spec:AST-086` FR14). The card never holds a live role. Unrelated renders do not re-announce. Implementation gap: the viewport 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. When focus reached the viewport by Tab or a click, dismissing the focused toast follows the same handoff: a control in a remaining toast, else the remembered element; with no control in the target toast, F6 leaves focus where it was, and a handoff never drops focus to the page body. | 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 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 | -| FR13 | Before Toast measures its painted surface (a server render, a static page), it picks its text side from the theme's resolved inverted surface (`--color-background-inverted`, or `--color-background-error-inverted` for `error`) by the same rule as the measurement. When that surface is not one opaque color `parseColor` reads, or either on-color is not a color it reads (a hex color, `rgb()`/`rgba()`, `black` or `white`), it falls back to the color mode: the dark side in light mode and for `error`, the light side in dark mode. | Current source and tests | -| FR14 | Once Toast measures its painted card, the text takes the on-color side (`--color-on-dark` or `--color-on-light`) that reads best on the card, and keeps the page's own text only when that reads at least as well as both. A card whose surface a theme makes pale keeps the page's text; a card whose page text reads but an on-color reads better takes the on-color. FR13 picks by the same rule. The top-layer viewport inherits the page's text color, so a card that keeps the page's text never shows the browser's popover `CanvasText`. | Current source; `useAutoMediaMode.test.ts` (`pickInvertedSide`); `check-toast-text-contrast.test.mjs`, which holds every first-party theme's info and error card text at WCAG 2.2 AA (SC 1.4.3, 4.5:1) in both modes; `ToastTextContrast.a11y.chromium.spec.ts`, which measures the rendered error card in the default top-layer viewport | -| FR15 | The dismiss button carries `toast-close` and draws in the card's text color, the color the card's body inherits, so a theme styles the close button apart from other buttons. | Current source and `themeIndicatorSeams.test.tsx` | +| ID | Invariant | Basis | +| ---- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| FR1 | A card carries `toast` with `type` and shows `body` and, on its first line, `endContent` then a dismiss Button named by `@astryx.toast.dismiss`; long body text wraps below. `renderContent` replaces that layout, receives `body`, `endContent`, `type`, timing, and a `dismiss` function, and gets no injected dismiss control. | Current source and tests | +| FR2 | With auto-hide on (the default for `info`, off for `error`), the card dismisses with reason `auto` after `autoHideDuration` ms. The timer pauses while the pointer is over the card, focus is inside it, a touch or pen gesture is active, or the window is blurred, and resumes with the remaining time (at least 1 s). Each pause condition holds the timer on its own: one ending resumes it only when no other still holds, and focus moving between the card's own controls keeps it held. A toast raised while the window is already blurred starts with its timer held. | Current source and tests | +| FR3 | The dismiss button, a swipe, a `dismiss` call, or the returned dismiss function dismiss with reason `manual`; `onHide` fires at most once, when the toast is dismissed, even when dismissed twice during its exit or before it shows. A toast replaced through `uniqueID` is not dismissed and reports no `onHide`. | Current source and tests | +| FR4 | A drag toward the position's block edge, from any pointer (`spec:AST-094` FR43), decides once, at release, per `spec:AST-094` FR36–FR37: projected travel past the commit point dismisses, and a release moving back toward the start cancels. A short drag snaps back; horizontal intent, a second touch, or a gesture starting on an interactive descendant does not dismiss. Native page scrolling continues until touch intent matches the dismiss edge. On a touch screen, the touch's first move decides: toward the dismiss edge, the swipe owns the touch. In the default layout the visible dismiss button stays as a non-gesture alternative; custom content supplies its own. Implementation gaps: the shipped rule dismisses on net travel past a distance threshold or a fast flick timed by its own average speed, even after the finger moves back, and recognizes only touch and pen drags, not a mouse (Current-state impact). | Current source and tests | +| FR5 | A new card slides in from its edge and fades in; a dismissed card collapses and fades before it unmounts; both slide only along the block axis. A dismissal without a swipe uses theme timing; a swipe's commit and snap-back start at the release velocity (`spec:AST-094` FR38). Under reduced motion the entrance and dismissal are an opacity-only fade of 200 ms or less on a coarse pointer or after a touch release (`design:reduced-motion` DR2) and immediate otherwise (DR3), and the card still unmounts. Implementation gaps: a swipe's settle is a CSS transition at theme timing, and under reduced motion every transition, including the row collapse and the swipe's throw, runs for 0.01 ms on every pointer (Current-state impact). | Current source and tests | +| FR6 | The viewport stacks toasts at `position`, newest nearest the configured edge, with an 8 px gap and no extra space at the edge beyond the safe-area gutter it keeps; it spans the inline axis within its inset, honoring start and end insets in either direction. The bottom gutter is 16 px beyond the bottom safe-area inset; under a coarse pointer it is 16 px beyond the larger of that inset and 34 px (`16px + max(env(safe-area-inset-bottom), 34px)`), so a toast clears the home indicator even where the page reports no inset. With a fine pointer and no inset it is 16 px. The 34 px floor is the iPhone home indicator's height; it applies on every coarse-pointer device, since browsers report the inset only when a page opts in. Each edge sits at the provider's `layerInset`, and a `toast.inset` edge, when set, replaces it (`spec:AST-059` FR6). A zero on the block edge opposite the position writes nothing. Implementation gap: a nonzero edge opposite the position, such as `top` for a bottom stack, moves the stack to that edge (Current-state impact). | Current source and tests | +| FR7 | With `maxVisible` of 1 or more, at most that many toasts show; when more are raised, the oldest wait hidden and return as visible toasts leave. `maxVisible={0}` shows every toast. | Current source and tests | +| FR8 | A toast whose `uniqueID` matches a toast the viewport holds, whether shown, hidden by the cap, or exiting, replaces it in place under `overwrite` (and is announced again; the card updates in place under the same key, so focus inside it stays on the same control, or moves per FR10 when that control no longer exists), and is dropped unshown and unannounced under `ignore`, even when both are raised before the first renders. Implementation gap: overwriting a toast hidden by the cap announces it while it is not shown, and nothing is announced when it surfaces (Current-state impact). | Current source and tests | +| 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. A top-layer viewport hosted in an open modal delivers through that modal's containers (`spec:AST-086` FR14); otherwise through the shared channel. A viewport the caller renders in place announces through `useAnnounce`, which delivers through an enclosing modal's containers (`spec:AST-086` FR14). The card never holds a live role. Unrelated renders do not re-announce. Implementation gap: the viewport 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. When focus reached the viewport by Tab or a click, dismissing the focused toast follows the same handoff: a control in a remaining toast, else the remembered element; with no control in the target toast, F6 leaves focus where it was, and a handoff never drops focus to the page body. | 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 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 | +| FR13 | Before Toast measures its painted surface (a server render, a static page), it picks its text side from the theme's resolved inverted surface (`--color-background-inverted`, or `--color-background-error-inverted` for `error`) by the same rule as the measurement. When that surface is not one opaque color `parseColor` reads, or either on-color is not a color it reads (a hex color, `rgb()`/`rgba()`, `black` or `white`), it falls back to the color mode: the dark side in light mode and for `error`, the light side in dark mode. | Current source and tests | +| FR14 | Once Toast measures its painted card, the text takes the on-color side (`--color-on-dark` or `--color-on-light`) that reads best on the card, and keeps the page's own text only when that reads at least as well as both. A card whose surface a theme makes pale keeps the page's text; a card whose page text reads but an on-color reads better takes the on-color. FR13 picks by the same rule. The top-layer viewport inherits the page's text color, so a card that keeps the page's text never shows the browser's popover `CanvasText`. | Current source; `useAutoMediaMode.test.ts` (`pickInvertedSide`); `check-toast-text-contrast.test.mjs`, which holds every first-party theme's info and error card text at WCAG 2.2 AA (SC 1.4.3, 4.5:1) in both modes; `ToastTextContrast.a11y.chromium.spec.ts`, which measures the rendered error card in the default top-layer viewport | +| FR15 | The dismiss button carries `toast-close` and draws in the card's text color, the color the card's body inherits, so a theme styles the close button apart from other buttons. | Current source and `themeIndicatorSeams.test.tsx` | ### Allowed variation @@ -271,7 +270,7 @@ button), so no anatomy part can own the `toast` target. | FR1, FR3 | `ToastViewport.test.tsx` layout, custom content, and onHide tests; `Layer/toastHost.test.tsx` and `toastHost.lateRegistration.test.tsx` toasts dismissed or replaced before they show | Default, custom content, double dismiss, a dismissal before the toast shows | Dropped controls or a repeated `onHide` fails. | `audit:Toast/behavior` | | FR2 | `ToastViewport.test.tsx` blur-pause, pause-source and raised-while-blurred tests | Window blur, toast raised while blurred, new toast during pause, overlapping pointer/focus/window holds, focus moving inside | A timer running while paused, or resuming while another hold remains, fails. | `audit:Toast/behavior` | | FR4, FR5 | `ToastViewport.test.tsx` gesture and motion tests; `ToastSwipeScroll.interaction.browser.spec.ts` first move toward and away from the edge, slow and quick, from three offsets | 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; `ToastSafeArea.a11y.chromium.spec.ts` bottom gutter, under a finger and a mouse, with insets of 0, 34 and 48 px | Each position, cap 1 and an explicit cap, overwrite, ignore | Wrong order, cap, or collision, or a bottom gap other than 16 px beyond the inset, or beyond the larger of the inset and 34 px under a coarse pointer, fails. | `audit:Toast/layout` | +| FR6–FR8 | `ToastViewport.test.tsx` placement, cap, and uniqueID tests, and the zero-inset cases (a zero on each edge replaces the provider's value on its own edge; a zero opposite the position writes nothing); `Layer/LayerProvider.test.tsx` inset tests; `ToastSafeArea.a11y.chromium.spec.ts` bottom gutter, under a finger and a mouse, with insets of 0, 34 and 48 px | Each position, cap 1 and an explicit cap, overwrite, ignore | Wrong order, cap, or collision, or a bottom gap other than 16 px beyond the inset, or beyond the larger of the inset and 34 px under a coarse pointer, fails. | `audit:Toast/layout` | | FR9–FR11 | `ToastViewport.test.tsx` announcement, F6, focus, landmark and empty-viewport tests; `ToastEmptyViewport.interaction.browser.spec.ts` no box once the last toast leaves | Info, error, StrictMode, nested viewports | A repeated or wrong-urgency announcement, or focus to the body after F6 entry, fails. | `audit:Toast/accessibility` | | FR2, FR8–FR10 | `ToastViewport.test.tsx` "keeps focus on a control inside a toast that an overwrite updates", "hands focus off when an overwrite removes the focused control", "updates a settled toast in place when an overwrite replaces it through uniqueID", "announces an overwrite once, through the viewport only", "auto-hides a control-free replacement after the update removes the focused control" | Overwrite with focus inside; overwrite that removes the focused control | A remounted card, or focus dropping to the page body, fails. | `audit:Toast/accessibility` | | FR10 | `ToastViewport.test.tsx` "restores focus after a toast reached with Tab rather than F6 is dismissed", "restores the remembered element when only a control-free toast remains" | Tab- or click-reached toast dismissed; a control-free toast remaining | Focus dropping to the page body after a dismissal fails. | `audit:Toast/accessibility` | @@ -289,7 +288,6 @@ Read from source, with no focused test yet: - FR5: a swipe's settle starting at the release velocity, and the reduced-motion fade and immediate change; the motion tests assert today's 0.01 ms transitions. -- FR6: a set `toast.inset` edge replacing the provider's value at 0. - FR7: the default cap of 5, and `maxVisible={0}` showing every toast. - FR9: delivery through an open modal's containers by a top-layer viewport hosted in that modal; the modal-host test covers an in-place viewport diff --git a/packages/core/src/Toast/ToastViewport.test.tsx b/packages/core/src/Toast/ToastViewport.test.tsx index 43368e16ce5f7..8a4d0b6610e43 100644 --- a/packages/core/src/Toast/ToastViewport.test.tsx +++ b/packages/core/src/Toast/ToastViewport.test.tsx @@ -283,6 +283,59 @@ describe('Toast responsive layout', () => { expect(viewport.style.insetInlineEnd).toBe('40px'); expect(getComputedStyle(viewport).width).not.toBe('100%'); }); + it('lets an inset edge of 0 replace the provider value on that edge, in LTR and RTL', () => { + const edges = [ + ['top', 'top', 'topEnd'], + ['bottom', 'bottom', 'bottomEnd'], + ['start', 'insetInlineStart', 'bottomEnd'], + ['end', 'insetInlineEnd', 'bottomEnd'], + ] as const; + for (const direction of ['ltr', 'rtl'] as const) { + for (const [edge, property, position] of edges) { + render( +