Skip to content

Toast

Transient notifications sent from anywhere in the app through a shared manager.

hero.tsx

Usage guidelines

  • Use a toast for short-lived feedback on something the user just did or that just happened in the background, such as a save, an export or a failed request with no other place on the page. A status that stays true while the user works on the page is an Alert, and a decision the user must answer is an AlertDialog.
  • Do not use a toast for a form rejection. A field error goes to that field through Form errors, and a rejection that belongs to no field stays inside the form as an Alert.
  • Create one manager in a module with createToastManager() and export createToast(manager) from it. The returned toast is a plain function, so event handlers, mutation callbacks and code outside React all call it the same way.
  • Render one Toaster for that manager near the application root, inside the isolated root element. Toaster includes the provider and portals its viewport to document.body, so the app needs no other wrapper. It sets the default timeout (5000 ms) and the visible stack limit (3).
  • Create another manager with its own Toaster only when a part of the app needs a separate stack, for example a test or an embedded surface. Toasts never cross between managers.
  • The title is the message and names the notification for assistive technology; add a description only for detail. Every toast has a type that sets its icon and halo.
  • A toast closes on its own, so its action must not be the only way to reach that outcome. Use timeout: 0 for a toast that stays until the user or the code closes it.

Anatomy

tsx
tsx

Toaster renders the cards itself: icon, title, description, an optional action button and a close button. Call sites pass content through the toast API rather than composing parts.

Note:

The demos on this page share one manager from a notifications.ts module like the one above. The hero demo renders its Toaster, standing in for the application root, and the other demos only call toast.

Examples

Types

toast.success, toast.info, toast.warning and toast.error fix the type. The callable form toast(title, { type }) takes it as an option.

types.tsx

Action

actionProps renders one Button in the card and accepts its variant. The caller closes the original toast when the action completes.

action.tsx

Promise

toast.promise shows a loading toast and updates the same card to success or error when the promise settles. Each state takes a title string or an options object, and the result states can derive it from the resolved value or the error. It returns the original promise, so handle its rejection, and keep the trigger in loading until it settles so the action cannot start twice.

promise.tsx

Updating and dismissing

Every call returns the toast ID. Pass it to toast.update to change the card in place, or to toast.dismiss to close it; toast.dismiss() without an ID closes every toast of the manager. A call with an existing id option also updates that card instead of adding another. The queued toast below uses timeout: 0 and stays; the update passes a timeout so the finished card closes on its own.

update.tsx

Keyboard

KeyAction
F6Moves focus to the notifications region while a toast is shown.
TabMoves focus from the region into the front toast, then to its action and close buttons.
Shift+TabReturns focus from the region to the element that was focused before F6.
EnterorSpaceActivates the focused action or close button.
EscapeCloses the toast that contains focus and returns focus to the element focused before F6.

API reference

Toaster

Provides the toast context, portaled viewport, and stacked notification cards. Renders a portaled <div> viewport.

Pass a manager from createToastManager() and trigger notifications via createToast(manager). Users can move focus to the notifications with F6.

Base UI Toast.Provider docs

Props
PropTypeDefaultDetails
toastManager requiredToastManagerNo default
offset{ right?: Property.Right<string | number> | undefined; top?: Property.Top<string | number> | undefined; }No default
Base UI Toast.Provider docs

createToast

Creates the toast API for a manager. Call it with a title and a type, or use a shortcut such as toast.success(title).

Parameters
ParameterTypeDescription
manager requiredToastManagerNo description

Returns

ToastApi

Call signatures

  • (title: React.ReactNode, options: ToastOptions) => string
Return properties
MemberTypeDescription
success required(title: React.ReactNode, options?: TypedToastOptions) => string

Shows a success toast and returns its ID.

error required(title: React.ReactNode, options?: TypedToastOptions) => string

Shows an error toast and returns its ID.

warning required(title: React.ReactNode, options?: TypedToastOptions) => string

Shows a warning toast and returns its ID.

info required(title: React.ReactNode, options?: TypedToastOptions) => string

Shows an info toast and returns its ID.

dismiss required(toastId?: string) => void

Closes the toast with the given ID, or every toast when no ID is passed.

update required(toastId: string, options: ToastUpdateOptions) => void

Updates the toast with the given ID.

promise required<Value>(promiseValue: Promise<Value>, options: ToastPromiseOptions<Value>) => Promise<Value>

Shows a loading toast that becomes a success or error toast when the promise settles. Returns a promise that settles with the same result.

createToastManager

Creates a toast manager to pass to both Toaster and createToast.

Returns

ToastManager