Overview
Reference usage
ToastRegion provides live toast notifications and a useToast() controller for descendants.
Usage
Undo, failure and the other toasts
Toasts follow one rule about how long they stay: an Undo toast stays until the person acts or leaves the page, a failure stays until it is dismissed, and everything else dismisses itself.
- Undo:
toast.show('Memory forgotten.', { undo: () => restore() })shows an "Undo" action that calls the function. The toast has no timer and no close button, so the Undo is not lost to a stray click. Calltoast.dismissUndo()when the page changes, so an Undo never outlives the page it would undo a change on. - Room under a toast that stays: while a bottom-anchored region shows a toast with no timer (an Undo, a failure), the document element carries the token
--cinder-toast-reserve-padding, how far up from the viewport's bottom edge the region reaches, in pixels, and it is back to its0pxdefault once no such toast is left. A page's scrolling area keeps that much room at its end (a spacer after its content, so a docked bar's sticky place does not move), so what it holds can be scrolled clear of the toast; a toast that leaves on its own reserves nothing. - Closing:
onCloseis called once when a toast starts to close, however it closes (its timer, its close button, its action after the action runs,dismiss,dismissAll,dismissUndo, a newer toast pushing it out, or the region unmounting). A page that holds a change back until its Undo toast is gone sends the change fromonClose. - Failure: a
dangertoast has no timer, shows the warning triangle, and keeps its dismiss button. Pair it with an action:toast.show("Couldn't export memories", { variant: 'danger', action: { label: 'Try again', onAction } }). - Everything else:
info,successandwarningtoasts dismiss themselves afterdefaultDuration. "Back online. Updated just now." is one of these, not a banner, so the page does not shift twice.
An explicit duration or dismissible overrides each default.
Where the region sits
A bottom-anchored region sits above whatever is docked to the bottom of the page and inside the bottom safe area, so a toast never covers Send or Connect a provider. Its offset is the on-screen keyboard (--_cinder-keyboard-inset) plus the distance from the bottom of the viewport to the top of the highest bar docked there: a DockedActionBar, sticky FormActions or a bottom NavigationBar. Bars that stack, such as a phone's tab bar with a docked action bar on it, count to the top of the higher one (--_cinder-docked-action-bar-height, which already includes the bars' safe-area padding); with no bar docked the offset is env(safe-area-inset-bottom). A bar is docked while its bottom edge is the bottom of the viewport, above the keyboard, or the top of a docked bar under it, or stops short of it by less than the bar's own height (the page's padding under a composer); a drawn bar that is not docked, such as a sticky bar resting at the end of a short page, still lifts the toasts by its own height.
A surface docked to the bottom that is not one of these bars, such as a chat's composer with the rows stacked above it, counts the same way through the dockedToBottom() attachment, exported from the package root: <div class="composer-dock" {@attach dockedToBottom()}>. It positions nothing; it only tells the region where the surface's top edge is, so a toast sits above the composer at every width, and above the tab bar under it on a phone.
On a phone the region spans the screen between two 12px gutters, and an action is a 44px target on touch and on a phone.
Undo fired: 0, Pause fired: 0
When to use
- Surfacing transient, non-blocking confirmations or errors that auto-dismiss after a short duration.
- Announcing the outcome of a background action that the user does not need to acknowledge.
- Communicating a persistent page-level message — use banner so it stays until dismissed.
- Reporting an urgent error that must remain on screen — use alert.
Examples
Basic toast region
Click the trigger to dispatch a transient toast into the live region.
Dismissible sticky toast
duration: 0 keeps the toast until the user dismisses it.
Failure toast
A danger toast stays until it is dismissed, shows the warning triangle, and keeps its dismiss button next to the action.
Keyboard dismiss
Focus a toast control and press Escape to dismiss the active notification.
Modal-scoped region
Nest <ToastRegion> inside a Modal to scope toasts to the modal content. When the modal body unmounts on close, the region tears down with it and pending timers are cleared.
Toasts above a docked bar
The region lifts above a docked action bar by its height and the safe area, so a toast never covers Send or Cancel run. Pin the bar to the screen to see it at the bottom edge, as it sits on a page. The Undo toast has no timer; the success toast dismisses itself.
Pause on hover
Pointer hover and keyboard focus pause auto-dismiss for the whole stack.
Positions
Anchor the toast region to any viewport corner or horizontal center.
Programmatic dismiss
show() returns the toast id. Capture it to dismiss a specific toast, or call dismissAll() to clear both stacks.
Promise
Show a sticky loading toast that resolves into success or danger output.
Stacking
Rapid notifications stack with bounded overflow and visual depth.
Swipe to dismiss
Dismiss a toast by dragging it horizontally past the threshold.
Undo toast
An Undo toast stays until the person presses Undo or leaves the page, and has no close button, so Undo is not lost to a stray click. Other toasts dismiss themselves. Call dismissUndo() when the page changes.
All four variants
info, success, and warning route to the polite (status) region; danger routes to the assertive (alert) region.
Props
Name | Type | Default | Description |
|---|---|---|---|
maxStack | number | 5 | Maximum simultaneous toasts in each region. Default 5. |
defaultDuration | number | 5000 | Default auto-dismiss duration in ms. Default 5000. Set to 0 for sticky. |
position | 'top-left''top-center''top-right''bottom-left''bottom-center''bottom-right' | 'bottom-right' | Viewport anchor for both live-region channels. Default bottom-right. |
children | snippet | Optional children. When provided, the region wraps them so descendants
can call useToast() and read the region's context. Most apps mount
<ToastRegion> as a self-closing tag at the root of their layout and
leave this empty — but some patterns (modal-scoped regions, tests)
benefit from explicit child composition. |