Toast

Reports something that happened out of view.

Kind

  • defaultdefault

  • success

  • warn

  • fail

  • loading

States

  • held

  • timer running

  • loading

Usage

When to use it
Use
A job the person started finished while they looked elsewhere: an export, a backfill.
Use
A background event changed: replication fell behind, a worker came back.
Use
An action can be undone for a short time: pause with Undo.
Not for
A problem with the view on screen. Use Alert.
Not for
A field's own error. Use Field.
Not for
A change the person can already see.

Rules

6 rules
Must
Mount one Toaster per app, inside the Sodium scope and its SodiumPortalProvider. Because each Toaster is its own live region, and two of them announce every toast twice.
Must
Make a toast's action reachable in the view too, such as Undo in the row's menu. Because the toast leaves on its timer, and a keyboard or screen reader user may never reach its button.
Never
Put a primary Button in a toast. Because a toast reports and never asks, and a slab in the corner takes the page's one primary.
Never
Toast after a change already on screen. Because a toast for what the person can see teaches them to ignore the stack, including the failure that matters.
Must
Use toast.fail for a failure; it holds until closed and is never hidden by the limit. Because a failure that times out unread is a failure nobody saw.
Should
Write a success title in the past tense with its object, under 48 characters.

State order

5 states, highest first
1
fail
2
loading
3
warn
4
success
5
default

Accessibility

4 checks
The stack is a live region named Notifications; a fail toast is announced assertively, the rest politely.
Status is the Status mark and a title that says it; the colour never stands alone.
F6 moves focus into the stack; the timer and its line stop while focus or the pointer is in it.
The close is a real button named Dismiss; the action is a real button.

Keyboard

3 keys
F6
Moves focus into the toast stack.
Tab
Moves between a toast's action and its Dismiss.
Escape
Closes the focused toast.

Edge cases

6 edge cases
A 120-character title
Wraps; the reading time grows with it, up to 12 seconds.
Five toasts at once
Three show; the newest routine one waits with its timer stopped; a fail always shows.
Phone, 390 wide
The stack spans the width 16px in and clears the home indicator; a swipe down dismisses.
A narrow stack
The action drops under the text, and the X keeps the first line.
Window in the background
The timer and its line pause until it comes back.
Reduced motion
No slide and no timer line; the toast still leaves on time.

API

7 props
toast(title, options)
(ReactNode, ToastOptions) => id
toast.promise(promise, labels)
{loading, success, fail}
toast.update(id, kind, title, options)
replaces in place
toast.dismiss(id?)
(string?) => void
options description, action, id, onClose
ReactNode, {label, onClick}, string, () => void
options timeout
number default reading time
Toaster limit, inline, manager
number, boolean, manager default 3, false

Tokens

15 tokens
--panel
#fafaf7
--line
#e2dfd5
--line-control
#8a8478
--toast
360px
--space-4
16px
--ok
#2c6a3a
--warn
#c25e00
--fail
#b3261e
--type-label
400 13px/16px var(--font-mono)
--type-body-sm
400 14px/20px var(--font-sans)
--text-1
#161512
--text-2
#55524a
--z-overlay
50
--dur-overlay
160ms
--ease-out
cubic-bezier(0.2, 0.8, 0.2, 1)

Install

For your coding agent

GitHub

Please star me pookie

198

A new design system every week

Leave your email before you copy the prompt.