Toast
A brief report that something already happened. Covers toast and
toast-region.
Toast or alert
| Toast | Alert | |
|---|---|---|
| Sits | over the page, fixed | in the flow, with the thing it is about |
| Lasts | seconds | until the reason is gone |
| Is about | something that just happened | the state of the page |
| Announces | polite | polite, or assertive for danger |
Anything the reader must act on is not a toast. A toast is missable by design: it is on screen for a few seconds, it is somewhere their eyes are not, and on a phone it may be under a thumb. A failure that needs a retry belongs in an alert next to the thing that failed.
The region is always rendered
toast-region goes in the layout once, and stays there empty.
A live region only announces content that arrives after it is already in the document. Render the region at the same moment as the first toast and the first toast is silent — which is the one a reader most needs to hear, and the failure is invisible unless you are listening.
{{-- in the layout, always --}}
<x-ds::toast-region position="bottom-right" />
position: bottom-right (default) | top-right | bottom-center |
top-center.
flash (with flashTone, flashTitle, flashDuration): a message flashed
to this page load. Echoed after the slot as
div.contents[data-ds-toast-flash][x-data] holding a template x-if, true
200 ms after x-init, so the toast arrives after the region and is
announced. Blank: nothing is printed and the region is byte-identical.
The region is pointer-events-none and each toast is pointer-events-auto, so
the empty container never swallows clicks on the page underneath — an invisible
full-width strip that eats clicks is a bug nobody attributes to the toast system.
polite, never assertive
A toast reports something that already happened. assertive interrupts whatever
the screen reader is currently saying, and interrupting someone to tell them a
thing they already did worked is exactly the rudeness polite exists to avoid.
Anything that genuinely must interrupt is not a toast — it is an alert or a modal.
Surface, not wash
A toast is surface with a border and shadow-float, unlike the alert's
tinted wash.
It floats over arbitrary content instead of sitting in the flow, so it has to paint an opaque ground — a wash over an unknown background is unreadable at the one moment it matters. The tone lives in the icon alone, which is enough at this size and stops four stacked toasts from becoming a colour chart.
tone: neutral (default) | accent | success | warning | danger.
What the host owns
The list and the removal. The component holds no list: dismiss takes an
Alpine expression and renders the close control. A toast with no auto-dismiss
and no dismiss is permanent, which is not a toast.
The undo toast: duration, actionLabel, shortcut (batch 20)
"Message archived — Undo", with a hairline along the bottom that empties.
┌────────────────────────────────────┐
│ ▣ Message archived. ✕ │ ← root: data-ds-toast, x-data,
│ [Undo] Ctrl+Z │ data-ds-countdown-scope
│▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ │ ← span[data-ds-countdown], aria-hidden
└────────────────────────────────────┘
duration(ms) draws the bar and times the toast. The bar's CSS animation (ds-countdown, in theme.css) IS the timer: the toast ends on itsanimationend, so the bar and the timeout cannot disagree, and pausing the animation pauses the time. It pauses while the pointer is over the toast, while focus is inside it (:hover,:focus-within), and while the page is hidden (data-ds-paused, set fromvisibilitychange: a hidden tab's animations keep their clock). At the end it dispatchestimeoutfrom the toast, then runsdismiss(or removes the element when there is none).- Reduced motion: the bar is
invisibleand still runs, so the time is the same and nothing moves on screen. actionLabeldraws a ghost button that dispatchesactionfrom the toast, then runsdismiss. Pressing it marks the toast settled, so a countdown that ends during the host's dismissal is not reported as a timeout. Theactionslot stays for anything else; the host wires that itself.- WCAG 2.2.1, Timing Adjustable. With an action (the label or the slot), a
durationunder 5000 is raised to 5000. The pauses on hover, focus and a hidden page are the "extend" half. shortcut("mod+z") draws ads::kbdhint beside the action. A hint only: the host binds the key.- Without any of the three, the toast renders byte for byte as before
(
ToastUnchangedTest). With any, it needs Alpine.
Keyboard
The toast never takes focus when it appears: a reader in the middle of typing
must not be pulled away. The region is a landmark (role="region", named), so
a screen reader reaches it from its landmark list, and Tab reaches the action
from wherever the toast sits in the document. Focus inside pauses the timer.
Offer a shortcut for the action where the host can bind one.
| Key | Where | Does |
|---|---|---|
| Tab | anywhere | reaches Undo and ✕ in document order |
| Enter / Space | on Undo | dispatches action, then dismisses |
the shortcut | host-bound | whatever the host wires, usually the same as Undo |
Events
| Event | From | When |
|---|---|---|
action | the toast root, bubbling | the built-in action button was pressed |
timeout | the toast root, bubbling | the countdown ran out unpaused |
The soft delete pattern: mark the record deleted at once, restore it on
action, and make it final on timeout. The toast is not the only route to
either: a toast closed with ✕, or a page left before the time, commits
nothing, so the server purges soft-deleted rows on its own schedule too.
Do not
- Do not stack more than about three. Four toasts is a log, and a log belongs on a page.
- Do not put a form in one. It can vanish mid-typing.
- Do not use one for a validation error. The field needs the message; see input.md.
- Do not use one for anything the reader has to keep. There is no history.
- Do not put the only copy of an "Undo" behind a timer without a permanent path to the same action.
- Do not move focus to a toast when it appears, even one with an action.
- Do not commit a deletion on anything but
timeout(or your own later purge).actionmeans the reader took it back.
From the package repo: edit this page on GitHub.