This page as markdown: /toast.md · Index for agents: /llms.txt · Everything in one file: /llms-full.txt

Toast

Status: stable

Imperative notification system over Base UI Toast — auto-dismiss timers, swipe-to-dismiss, focus management, ARIA live-region announcements, and a limit-aware stack. Wrap the app in ToastProvider, then push toasts from anywhere with the global, Sonner-shaped toast() (toast.success/error/info/warning/loading/promise/dismiss) or the useToast() hook inside components.

Keywords: toast, notification, snackbar, feedback, success, error, promise, loading, undo

Usage

Use Toast for transient feedback caused by a user action: saved, failed, copied, queued, uploaded, or undone. Use Banner for persistent page/app state and InlineStatus or Field errors for feedback that must remain attached to content.

Best practices

Anatomy

Part Required Description
Viewport yes The positioned live-region stack rendered by ToastProvider.
Surface yes The individual ToastRoot containing title, description, action, and close affordance.
Title yes Short outcome text, used as the accessible name.
Description no Optional detail or context beneath the title.
Action no Optional inline action such as Undo or Retry.

Subcomponents

Name Type Description
ToastRoot Base UI Toast.Root props + className (requires the toast object) A single toast surface. Animates enter/leave via data-[starting-style]/data-[ending-style]; swipe-to-dismiss is wired by Base UI.
ToastContent Base UI Toast.Content props + className The toast's contents as one row. In a stacked viewport it fades on the cards behind the front one and returns when the stack fans out. Wrap a hand-composed toast's parts in it so a stacked viewport can hide them.
ToastTitle Base UI Toast.Title props + className The toast headline (text-title-sm). Auto-associated as the toast's accessible name.
ToastDescription Base UI Toast.Description props + className Supporting body copy beneath the title (text-body-sm, muted). Auto-associated as the toast's accessible description.
ToastClose Base UI Toast.Close props + className Dismiss button. Base UI handles the close and leave animation; labelled "Dismiss" by default (dismissLabel). Its 24px glyph box keeps a 44px target under a coarse pointer.
ToastAction Base UI Toast.Action props + className Inline action button (e.g. Undo). The imperative path renders one on every toast and Base UI sources its label and handler from that toast's actionProps, rendering nothing when there are none — so toast(msg, { actionProps }) is all an action needs. Reach for the component directly only when composing a toast by hand; compose with render={<Button … />}.

Props

Name Type Default Description
ToastProvider { children, timeout?, limit?, closeIcon?, dismissLabel?, position?, stacked?, viewportClassName? } — Wraps Base UI Toast.Provider and renders the themed Viewport + toast list. Mount once near the app root, above any caller of useToast().
position "top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right" "top-right" Screen anchor for the toast stack.
stacked boolean false Stack the toasts like a deck of cards, the newest in front and the older ones peeking out behind it, a step smaller, instead of listing them one under another. Hovering or focusing the stack fans it out into the list. Use it when an app can raise several toasts in a row, so they don't take over the corner of the page.
viewportClassName string — Extra classes merged LAST onto the fixed viewport region — for safe-area insets or an offset (e.g. clearing a sidebar).
timeout number 5000 Default auto-dismiss time in ms for toasts. 0 keeps a toast until it is dismissed. Error toasts, loading toasts, and any toast carrying actionProps default to 0 regardless of this value; a per-toast timeout overrides both.
limit number 3 Maximum toasts shown at once; older toasts are pushed out when the limit is exceeded.
closeIcon ReactNode Override the dismiss-button glyph. The default already follows the injected icon set.
dismissLabel string "Dismiss" Accessible name of every toast's dismiss button. Translate it here; ToastClose takes the same prop when composing by hand.
useToast / useToastManager () => { toasts, add, close, update, promise } — Manager hook for use inside components. add({ title, description, timeout?, type?, priority?, actionProps? }) returns the new toast id and applies the same persistence default as toast.* — an error, loading, or actionProps toast stays until dismissed unless you pass a timeout. close(id), update(id, opts), and promise(p, opts) round out the API, with the same default: an update that turns a toast into an error or gives it actionProps, and a promise that settles into an error (or a success with actionProps), persist unless that update or outcome names a timeout.
toast (message, options?) => string & { success, error, warning, info, message, loading, promise, dismiss, update, add, custom } — Imperative singleton callable OUTSIDE React (event handlers, utilities, non-React code) — the Sonner-shaped surface that makes migrating a lib/toast wrapper a near drop-in. Requires a mounted (it binds the shared manager). Each call returns the toast id; toast.dismiss(id?) closes one or all; toast.promise(p, { loading, success, error }) and toast.update(id, opts) handle async + in-place updates; a settled error, and an update into an error, persist like toast.error unless they name a timeout.
type (toast option) "success" | "error" | "warning" | "info" | "loading" — Set by the toast.* helpers. Drives a leading status glyph from the shared tone list, the same one Note and InlineStatus use (success→success, error→destructive, warning→warning, info→info), which blooms in as the toast lands; loading shows a spinner, and the glyph blooms in its place when the toast settles. Both loading and error persist until updated or dismissed unless the call supplies a timeout.

Tokens used

popover, popover-foreground, border, muted-foreground, accent, accent-foreground, secondary, secondary-foreground, ring, success, tone-warning, tone-info, destructive

Motion

Accessibility

Related

Examples

Imperative (from anywhere)

import { toast } from "@sableui/react"

toast.success("Saved", { description: "Your post is live." })

Promise (loading → success / error)

import { toast } from "@sableui/react"

toast.promise(publish(), { loading: "Publishing…", success: "Published", error: "Could not publish. Check your connection and try again." })

Persistent loading, updated in place

import { toast } from "@sableui/react"

const id = toast.loading("Uploading report…"); /* later */ toast.update(id, { title: "Uploaded", type: "success", timeout: 4000 })

Custom toast markup (composed parts)

import { Icon, toast, ToastClose, ToastDescription, ToastRoot, ToastTitle, ToastViewport, useToast } from "@sableui/react"

const { toasts } = useToast()
<ToastViewport>{toasts.map((t) => (<ToastRoot key={t.id} toast={t}><div className="flex min-w-0 flex-col gap-1"><ToastTitle>{t.title}</ToastTitle><ToastDescription>{t.description}</ToastDescription></div><ToastClose><Icon name="xmark" /></ToastClose></ToastRoot>))}</ToastViewport>

Undo action

import { toast } from "@sableui/react"

toast.message("Post archived", { actionProps: { children: "Undo", onClick: () => restorePost() } })

Stacked

import { ToastProvider } from "@sableui/react"

<ToastProvider stacked position="bottom-right">{children}</ToastProvider>

Provider with app chrome

import { AppShell, Button, Region, toast, ToastProvider } from "@sableui/react"

<ToastProvider position="bottom-right" limit={3}><AppShell><Region max="feed"><Button onClick={() => toast.success("Saved")}>Save</Button></Region></AppShell></ToastProvider>