Toaster
Hosts the toast stack once per page and persists it across Turbo Drive navigations. It is the host element for every
toast fired from a redirect's flash message, by appended Turbo Streams, by <hw:toast />, or from your
own JavaScript.
The component renders a private card blueprint and maps to the toaster Stimulus controller. On connect, the
controller validates and clones that blueprint, manages stacking and timers, and publishes the manager as
window.toaster. There is no third-party dependency.
Setup
Place the viewport once in your main layout, typically before </body>:
<!DOCTYPE html>
<html lang="en">
<head>...</head>
<body>
{{ $slot }}
<hw:toaster />
</body>
</html>
That single tag is the whole layout-side setup: the viewport reads the session flash itself, so a redirect carrying a message shows a toast with nothing else on the page.
The viewport defaults to id="toaster" and ships with data-turbo-permanent, so it survives Turbo Drive
navigations and keeps the stack alive. The default id is also what Turbo Streams target:
return turbo_stream()->update('task_1', $view)->toast('success', 'Saved!');
Order does not matter: a toast emitted before the viewport connects is buffered and drained as soon as it does.
Session flash
A redirect flashes the toast; the viewport renders it on the page that follows.
return to_route('tasks.show', $task)
->toast('success', 'Task updated', 'Your changes are now live.');
The toast() macro takes the same notification arguments as its Turbo Stream twin —
type, message, and the optional description, position and duration — so both branches of a controller read alike:
if ($request->wasFromTurboFrame() && $request->wantsTurboStream()) {
return turbo_stream()
->closeOverlay($request->overlayOrigin())
->toast('success', 'Task updated', 'Your changes are now live.');
}
return to_route('tasks.show', $task)->toast('success', 'Task updated', 'Your changes are now live.');
Laravel's conventional flash keys work too, and need no macro:
| Session key | Toast type | Message |
|---|---|---|
toast |
from payload | ['type' => …, 'message' => …, 'description' => …, 'position' => …, 'duration' => …], or a bare string |
success |
success |
The flashed string |
error |
error |
The flashed string |
errors |
error |
The first message in the MessageBag |
warning |
warning |
The flashed string |
info |
info |
The flashed string |
return redirect()->back()->with('success', 'Item created successfully!');
The keys are read in the order above and the first usable message wins. A failed validation therefore surfaces its
first error as a toast on its own, with no extra wiring, named bags (validateWithBag, withErrors(…, 'login'))
included. An empty message — including withErrors([]) — renders nothing rather than an empty card.
The keys are read from the session whether they were flashed or stored, so put them there with ->with(…) or
session()->flash(…). A value written with session([…]) persists across requests and would raise its toast again
on each one.
Exactly one toast is rendered per request from the flash. If your layout still carries a standalone
<hw:toast />, whichever of the two renders first claims the message and the other stays silent, so
upgrading does not double up. Set :flash="false" to hand the session back to <hw:toast /> entirely.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
id |
string |
toaster |
Element id — also the default target for Turbo Stream appends |
position |
string |
bottom-center |
top-start, top-center, top-end, bottom-start, bottom-center, bottom-end |
duration |
int |
4000 |
Milliseconds before a toast dismisses itself; 0 keeps it until dismissed |
visible-toasts |
int |
3 |
Maximum number of toasts visible at once |
close-button |
bool |
true |
Renders a close button on each toast |
expand |
bool |
false |
Keeps the stack expanded instead of collapsing it when the pointer leaves |
auto-disconnect |
bool |
false |
Destroys the manager when the controller disconnects |
turbo-permanent |
bool |
true |
Renders data-turbo-permanent on the viewport |
flash |
bool |
true |
Renders the session flash message as a toast; disable to place <hw:toast /> yourself |
class |
string |
'' |
CSS class applied to the viewport <div> itself |
class-name |
?string |
null |
Extra classes applied to every rendered toast |
container-aria-label |
?string |
Notifications |
aria-label on the viewport landmark |
On position
The first segment is a physical side, the second a logical alignment — the same split as side and align on
Popover, Dropdown and Hover Card. start and end follow the document's writing direction, so bottom-end sits on
the right in a left-to-right document and on the left in a right-to-left one.
Customization examples
Top-right, 5s duration:
<hw:toaster position="top-end" :duration="5000" />
Expanded stack, no close button:
<hw:toaster :close-button="false" :expand="true" />
Custom landmark label:
<hw:toaster container-aria-label="Alerts" />
Custom id, useful for a second Turbo Stream anchor:
<hw:toaster id="my-toaster" />
Emitting from JavaScript
The manager is published as window.toaster after <hw:toaster> mounts. Nothing needs to be imported:
window.toaster.success("Saved");
window.toaster.error("Upload failed", { description: "The file was rejected." });
window.toaster.warning("Storage almost full");
window.toaster.info("Heads up", { position: "top-end" });
const id = window.toaster.toast("Working…", { duration: 0 });
window.toaster.dismiss(id);
| Method | Description |
|---|---|
toast(message, options?) |
Emits an untyped toast and returns its id |
success(message, options?) |
Same, typed success |
error(message, options?) |
Same, typed error — announced assertively |
warning(message, options?) |
Same, typed warning |
info(message, options?) |
Same, typed info |
dismiss(id) |
Plays the exit animation for one toast and removes it |
destroy() |
Clears the stack and removes every listener, timer and observer |
options accepts description, duration, position and className. Anything else on the instance is internal
and may change without notice.
Styling hooks
Appearance lives in the preset, keyed on data-slot; the geometry of the stack lives in structural.css. Both are
driven by custom properties you can override anywhere in your own CSS:
| Property | Default | Controls |
|---|---|---|
--toast-width |
preset | Card width (24rem in Nova; 26rem in Bloom) |
--toast-offset |
1rem |
Distance from the viewport edges |
--toast-mobile-offset |
1rem |
Same, below 600px |
--toast-gap |
0.75rem |
Space between cards when the stack is expanded |
--toast-peek |
0.75rem |
How much of each card behind shows when collapsed |
--toast-depth-scale |
0.1 |
How much each card behind shrinks per step |
/* Nudge the stack away from the edge and tighten the collapsed fan */
[data-slot="toaster"] {
--toast-offset: 2rem;
--toast-peek: 0.5rem;
}
Slots: data-slot="toaster", data-slot="toast", data-slot="toast-icon", data-slot="toast-content",
data-slot="toast-body", data-slot="toast-title", data-slot="toast-description", and
data-slot="toast-close".
The manager exposes these stable state hooks on each cloned card:
data-type="default|success|error|warning|info"data-position="top-start|top-center|top-end|bottom-start|bottom-center|bottom-end"data-state="open|closed"data-expanded="true|false"
Use data-type for semantic treatments and data-state for entry/exit appearance. Position is physical on the block
axis and logical on the inline axis. Expanded state is mirrored on the viewport and every card so visual rules can
coordinate with the structural stack.
The controller-written --toast-height, --toast-index, --toast-offset-y and --toast-frontmost-height variables
are reserved for the stack mechanics. The derived --toast-scale, --toast-shrink, --toast-exit-y and
--toast-stack-direction variables, plus transient data-behind, data-limited, data-measuring and data-presence
markers, are structural implementation details. A preset can change the public properties in the table above and style
the stable hooks, but should not assign or reinterpret these reserved values.
The seven card slots come from one internal <template> inside the viewport. The manager clones it for each
notification and fills title and description as text. The template is package infrastructure rather than a composition
API; use class-name, the slots above and preset CSS to customize cards instead of replacing its parts.
The flash message renders as an empty data-slot="toast-trigger" element next to the viewport. It carries the payload,
hands it to the manager on connect and removes itself, so it is never visible and needs no styling.
Accessibility
- The viewport is a labelled landmark (
role="region"), so screen readers can jump to it with their landmark commands.container-aria-labelsets the name. - F6 moves focus to the viewport when at least one toast is on screen, matching Radix and Base UI. This intercepts a key Chrome otherwise uses to cycle its own panes.
- Each toast announces its own content —
role="status"andaria-live="polite", orrole="alert"andaria-live="assertive"forerror. There is deliberately noaria-labelon the card, which would override the message. - Timers pause while the pointer is over the stack, while focus is inside it, and while the document is hidden.
- Swipe-to-dismiss is not implemented. Toasts are dismissed by the close button or by their timer.
- All toast movement and fades, including stack and content transitions, are disabled under
prefers-reduced-motion.
Turbo integration
- The viewport uses
data-turbo-permanentby default, so the stack stays alive across Turbo Drive navigations and a toast fired before a visit keeps counting down after it. Its source template is part of that permanent subtree. - Turbo Streams append rendered
<hw:toast />markup to the viewport — see thetoast()macro. - The flash trigger renders as a sibling of the viewport, never inside it. Turbo swaps the new page's
data-turbo-permanentelement — subtree included — for the current one, so anything nested in the viewport would be dropped on the very Drive visit that follows a redirect. For the same reason, do not wrap the viewport in adata-turbo-permanentelement of your own: that would discard the trigger along with it. - A response consumed as a Turbo Frame renders only the frame, so a flash message left in the layout never reaches the
page. Use
turbo_stream()->toast(...)for frame-driven flows. - Deployments that change the internal blueprint require a full page reload: Turbo preserves the already-mounted permanent subtree rather than hot-replacing its template.
See also
<hw:toast />— fires individual toasts from session or props