ui-kit0.0

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.

Close button

closeButton adds a × to every toast (shown on hover or focus with a mouse, always on touch screens). Set dismissible: false on a toast to turn off swipe, the × button and Esc.

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?)

PropTypeDefaultDescription
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.
descriptionReactNode—Second line.
durationnumber4000Milliseconds, or Infinity. Loading toasts default to Infinity.
action / cancel{ label, onClick? }—Buttons. They dismiss the toast unless you preventDefault().
iconReactNode | false—Custom icon, or false for none.
idstring | number—Reuse an id to update a toast in place.
dismissiblebooleantrueAllow swipe, the × button and Esc.
importantbooleanfalseAnnounce assertively (role="alert"). Errors always are.
closeButtonboolean—Show × on this toast, overriding the Toaster.
toasterIdstring—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

PropTypeDefaultDescription
position'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right''bottom-right'Where the stack docks.
visibleToastsnumber3How many toasts show; older ones wait out of sight.
expandbooleanfalseKeep the stack expanded.
richColorsbooleanfalseTint toasts by type.
closeButtonbooleanfalseShow × on every toast.
gapnumber14Space between expanded toasts, px.
offsetnumber | string24pxDistance from the screen edge (16px on phones).
durationnumber4000Default auto-dismiss time, ms.
labelstring'Notifications'Accessible name of the region.
idstring—Name for this Toaster, so toasts can target it with toasterId.

Keyboard

KeyAction
Alt + TMoves focus to the notifications region and expands the stack.
F8Same as Alt + T.
TabMoves through the action, cancel and close buttons of the visible toasts.
EscOn a toast: dismisses it. On the region: returns focus to where you were.

Accessibility

  • The viewport is a region named “Notifications” and a polite live region, so new toasts are announced without taking focus. Errors and important toasts use role="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.