Skip to content

Design system

Documentation

DesignComponents / Toast

Components / Toast

Beta

Toast

Use Toast for short, non-blocking feedback that can disappear automatically or be dismissed by the person.

On this page

Examples

Basic notification

A short, non-blocking message confirms a completed action.

Toast provider, viewport, and add action

Semantic types

Success, information, warning, and error use a readable title and description.

Toast semantic types

Update by ID

A pending operation can update to success or error without adding another toast.

Toast that updates from pending to success

Action and manual close

Optional actions and an explicit close control remain keyboard reachable.

Toast with action and close

Limited stack

The provider limit prevents a burst of notifications from taking over the viewport.

Toast provider with a visible limit

When to use

Use Toast to confirm a background operation or provide a short status update without blocking the current task. Use Dialog for confirmation and visible inline feedback for errors that must be acted on before continuing.

Usage

toast-basic.tsx
"use client";

import { Button } from "@phuctech/ui/components/button";
import { ToastClose, ToastContent, ToastDescription, ToastRoot, ToastTitle, ToastProvider, ToastViewport, useToastManager } from "@phuctech/ui/components/toast";

function ToastList() {
  const { toasts } = useToastManager();
  return toasts.map((toast) => <ToastRoot key={toast.id} toast={toast}><ToastContent><div className="min-w-0 flex-1"><ToastTitle /><ToastDescription /></div><ToastClose aria-label="Dismiss notification" /></ToastContent></ToastRoot>);
}

function AddToast() {
  const manager = useToastManager();
  return <Button onClick={() => manager.add({ title: "Changes saved", description: "Your workspace is up to date." })}>Save changes</Button>;
}

export function Example() {
  return <ToastProvider><AddToast /><ToastViewport><ToastList /></ToastViewport></ToastProvider>;
}

Wrap each notification surface in ToastProvider, render one ToastViewport, and call useToastManager from a descendant. The provider owns timeout and visible-stack limits.

Lifecycle

  • Use manager.add for a new message; an existing id updates that toast in place.
  • Use timeout=0 for work that stays visible until it is updated or closed.
  • Use manager.update for pending → success/error transitions and manager.close for an imperative dismissal.
  • Keep destructive confirmation in Dialog; Toast is not a confirmation control.

API

Component API
PropTypeDefaultDescriptionConstraints
ToastProvidertimeout / limit / manager5000 / 3Provides lifecycle and manager context.Place one provider around the related notification surface.
ToastViewportHTMLDivElement propsfixed bottom-rightResponsive portaled stack boundary.Render once per provider.
useToastManager{ toasts, add, update, close }Reads and changes the current toast collection.Call inside ToastProvider.
ToastRoottoast objectRenders one item in the stack.Map stable toast IDs as React keys.
ToastTitle / ToastDescriptionheading / paragraphAnnounced title and supporting text.Keep messages concise and specific.
ToastIcontype?: stringOptional semantic icon; pass toast.type to render success, error, warning, or info.Decorative reinforcement only; the readable title still carries the meaning.
ToastAction / ToastClosebutton propsOptional action and explicit dismissal.Keep both keyboard reachable and labeled.

Tokens

Component tokens
TokenRoleEffective valueUsage
--elevation-lgToast depthshared large shadowSeparates transient feedback from the page.
--radius-xlToast geometryshared large radiusKeeps the stack aligned with other elevated surfaces.
--color-success / --color-danger / --color-info / --color-warningSemantic typessemantic rolesType styling reinforces readable status text.

Accessibility

  • Toast titles and descriptions are announced by the Base UI manager; keep them meaningful without color.
  • Provide a close control for persistent or long messages and make actions keyboard reachable.
  • Do not put required instructions, form errors, or destructive confirmations only in a transient Toast.
  • Dialog handles blocking confirmation and focused work.
  • Settings shows inline save-state feedback around a form.
  • Accessibility documents live feedback review.