Feedback
Toast
Stacked notifications with promise states.
Types
Mount <Toaster /> once, then call toast() from anywhere. Each type has its own icon; the loading toast has no timer until you update or dismiss it.
When to use
- Confirming something the user just did that needs no further input: saved, sent, copied, deleted (with Undo).
- Background results the user is not looking at: an export finished, a deploy failed.
- Progress of a single async task — use
toast.promise.
Not for: errors the user must fix in a form (put them next to the field), messages that must stay on the page (use an alert), or anything that needs a decision and cannot be missed (use a dialog). Toasts disappear, so never put the only copy of important information in one.
Promise
toast.promise shows one toast and morphs it through loading, then success or error. Pass a function to build the message from the result.
Action and cancel
Give a toast one action (and optionally a cancel). Clicking either dismisses it, unless your handler calls event.preventDefault(). Keep toasts with actions on screen longer.
Positions
Six positions. New toasts enter from the docked edge, and swiping a toast toward that edge dismisses it. On phones the stack spans the full width.
Rich colours
richColors tints each toast by type. Text uses the status -text tokens, so contrast holds in light and dark.
Stack and expand
By default older toasts tuck behind the newest and the stack expands into a list on hover or focus, using each toast’s measured height. expand keeps it open; visibleToasts caps how many show.
Duration
The default is 4 seconds. The timer pauses on hover, on focus and while the tab is hidden. Infinity keeps a toast until it is dismissed.
Within a dialog
The viewport lives in the browser’s top layer (popover="manual"), so toasts show above modal dialogs. While a modal dialog is open the viewport moves inside it so it is not inert: you can still hover, swipe and click toasts.
JavaScript API
toast is a function, so it works outside components. Calling it again with the same id updates that toast in place and restarts its timer.
toast(title, options?)
| Prop | Type | Default | Description |
|---|---|---|---|
| toast / .success / .error / .warning / .info / .loading | (title, options?) => id | — | Create a toast of that type. Returns its id. |
| toast.promise | (promise | () => promise, { loading, success, error, description?, finally? }) => { id, unwrap } | — | One toast that morphs through the promise’s states. success and error may be a function. |
| toast.dismiss | (id?) => id | — | Dismiss one toast, or all when no id is given. |
| description | ReactNode | — | Second line. |
| duration | number | 4000 | Milliseconds, or Infinity. Loading toasts default to Infinity. |
| action / cancel | { label, onClick? } | — | Buttons. They dismiss the toast unless you preventDefault(). |
| icon | ReactNode | false | — | Custom icon, or false for none. |
| id | string | number | — | Reuse an id to update a toast in place. |
| dismissible | boolean | true | Allow swipe, the × button and Esc. |
| important | boolean | false | Announce assertively (role="alert"). Errors always are. |
| closeButton | boolean | — | Show × on this toast, overriding the Toaster. |
| toasterId | string | — | Target the Toaster with this id (only needed with several Toasters). |
| onDismiss / onAutoClose | (toast) => void | — | Called when dismissed by anything / by the timer. |
API
Toaster
| Prop | Type | Default | Description |
|---|---|---|---|
| position | 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right' | 'bottom-right' | Where the stack docks. |
| visibleToasts | number | 3 | How many toasts show; older ones wait out of sight. |
| expand | boolean | false | Keep the stack expanded. |
| richColors | boolean | false | Tint toasts by type. |
| closeButton | boolean | false | Show × on every toast. |
| gap | number | 14 | Space between expanded toasts, px. |
| offset | number | string | 24px | Distance from the screen edge (16px on phones). |
| duration | number | 4000 | Default auto-dismiss time, ms. |
| label | string | 'Notifications' | Accessible name of the region. |
| id | string | — | Name for this Toaster, so toasts can target it with toasterId. |
Keyboard
| Key | Action |
|---|---|
| Alt + T | Moves focus to the notifications region and expands the stack. |
| F8 | Same as Alt + T. |
| Tab | Moves through the action, cancel and close buttons of the visible toasts. |
| Esc | On a toast: dismisses it. On the region: returns focus to where you were. |
Accessibility
- The viewport is a
regionnamed “Notifications” and a polite live region, so new toasts are announced without taking focus. Errors andimportanttoasts userole="alert"(assertive). - Timers pause on hover, on focus and while the tab is hidden, so nothing vanishes while it is being read.
- Anything a toast offers must also be reachable elsewhere: toasts time out, so never make one the only way to finish a task.
- Toasts that wait behind the visible limit are inert, so they cannot take keyboard focus.
Motion
- New toasts rise from their edge with the soft-rise entrance (blur and scale clear); the stack re-settles on the smooth spring.
- Exits are faster than entrances. A swipe follows the pointer, then flies out if past 45px or faster than .11px/ms; otherwise it springs back.
- Promise toasts morph in place: the icon pops, the text cross-fades and the height follows the content.
- Reduced motion: the stack still changes state, the movement does not.