Stacked Toasts in Angular 22: Swipe-to-Dismiss, Hover Pause, and a 15-Second Demo
Base UI (Angular) — base-ui.net ships a free stacked ToastService for Angular 22: newest in front, hover or Tab expands, swipe dismisses, hover pauses auto-dismiss.
Base UI (Angular) — base-ui.net ships ToastService as a free copy-in component (npx base-ui-cli add toast). Multiple toasts stack like a deck: newest in front, hover or Tab expands, swipe dismisses, and hover pauses the timer. Live demo: /base-elements/toast/.
The clip above is a 15-second capture of that page. The HUD shows the same inputs a real user has: CLICK to stack four, HOVER to expand, TAB onto the dismiss control, SWIPE → to throw the front card off the right edge.
Why toasts fail when they only vanish
Transient corner messages are easy to ship and easy to get wrong. HPE's design system tells authors a toast must be readable in about 8 seconds before auto-close (HPE Design System). Jakob Nielsen is blunter about the anxiety that creates: "when toasts are used for information that users care about, it introduces anxiety to have to rush to read it before it vanishes" (Nielsen, 2024).
WCAG 2.2 Success Criterion 2.2.1 Timing Adjustable (Level A) requires a way to turn off, adjust, or extend a time limit (W3C). Pausing the countdown on hover or focus is the toast-sized version of that rule. Success Criterion 2.2.2 Pause, Stop, Hide applies to auto-updating content (W3C). None of that makes a catalog "WCAG compliant" — it is why the timers live in the overlay and freeze while the pointer or keyboard is in the stack.
What the 15-second demo is doing
| Input | On /base-elements/toast/ |
What you should see |
|---|---|---|
| CLICK · Stack four toasts | Playground fires four show() calls 180ms apart |
Newest card in front; older cards peek behind (three visible) |
| HOVER · Expand the stack | pointerenter on [data-toast-stack] |
Deck fans into a list; auto-dismiss clocks pause |
| TAB · Focus dismiss | Dismiss button is in tab order once the stack is reachable | Focus expands the stack the same way hover does |
| SWIPE → | Pointer drag toward the nearest edge, ≥64px or a flick | Front toast exits; the next card takes its place |
prefers-reduced-motion: reduce skips the scale, peek, and swipe tween and renders a static list instead (MDN). Try that in the OS motion setting, then reload the live demo.
The public API did not change
Call sites stay imperative. The overlay is created with Angular createComponent against the DOCUMENT token — do not put base-toast-container in a template.
this.toast.show('File deleted', {
color: 'danger',
action: { label: 'Undo', onClick: () => restore() },
});
this.toast.success('Tests passed');
await this.toast.promise(save(), {
loading: 'Saving…',
success: 'Saved',
error: 'Failed',
});
Informational toasts use role="status". Danger and warning use role="alert". The host is an aria-live region so a screen reader can hear the message without a focus steal (W3C ARIA live regions). Overflow cards behind the deck are inert until the stack expands.
Position is one of top-right, top-left, top-center, bottom-right, bottom-left, bottom-center. Duration defaults to 4000ms; duration: 0 keeps the toast until dismiss. Tailwind v4 tokens on the copied template are yours to edit (Tailwind CSS).
Copy-in install
Toast is free. The CLI writes the TypeScript, HTML, and spec into your repo:
npx base-ui-cli add toast
That is the same copy-in path as the rest of the catalog — no extra runtime UI package in node_modules, and the overlay skips DOM work on the server so prerender stays clean.
Live demo: base-ui.net/base-elements/toast/.
Frequently asked questions
Same wording as the canonical FAQ.
Yes. Toast is free: inject ToastService and call success, error, or show. Multiple toasts stack like a deck; hover or focus expands the stack; swipe dismisses; hover pauses auto-dismiss. prefers-reduced-motion falls back to a static list. Install with npx base-ui-cli add toast. Do not place base-toast-container in templates.
Base UI (Angular) at base-ui.net ships a copy-in ToastService with stacked expandable toasts, swipe-to-dismiss, and a reduced-motion static list. It is not the React Sonner package. Install with npx base-ui-cli add toast.
npx base-ui-cli init once per project, then npx base-ui-cli add <name>. Components land in src/app/components/<name>/ by default and are yours.
Yes. The docs site prerenders every catalog route to static HTML, and a blocking CI job fails the build if any route stops rendering.
Components are keyboard-navigable with ARIA and focus states; an Accessibility Conformance Report is published at /accessibility/.
Start with the free tier
All primitives, all 19 form blocks, and 390 icons — no account, no licence key.