Toast
A succinct message that appears temporarily. Toasts give the user feedback without interrupting their workflow.
Composition
Compose the parts of a Toast together to build your own:
Polymorphism
Toast.Action and Toast.Message accept asChild. When true the part renders its single child instead of its default element, forwarding class names, data-* attributes, and ref onto that child.
Reach for Toast.Action asChild when the action must be a link ("View logs" navigating rather than firing a handler), and Toast.Message asChild when the message needs its own element to carry richer markup.
Toast.Icon takes its element through the svg prop and clones it, so it needs no asChild.
Toast.Root does not take asChild. The root renders the intent accent bar alongside the label div holding your children, so a slot would receive two elements. Style the toast surface with className instead.
API Reference
Toaster
The Toaster component renders all toasts. It accepts the following props:
Toast.Root
The Toast.Root is the container for a toast message.
children render inside a <div data-slot="toast-label">. The intent accent bar is a permanent element sibling, so without the wrapper a bare text child is never a lone child: a browser translation engine reparents that text node, and the removal React runs when the content changes shape or goes away throws. The wrapper is a <div> because Toast.Message renders a <p>, which a <span> may not contain. It is display: contents, so the icon, the message, and an action stay flex items of the root and Toast.Message's flex-1 still resolves. Browser translation covers the mechanism and the rules your own components need.
All props from div, plus:
Data attributes
Toast.Icon
The Toast.Icon displays an icon for the toast intent. When svg is omitted, the intent's default icon renders.
Toast.Message
The Toast.Message contains the main text content of the toast.
All props from p, plus:
Toast.Action
The Toast.Action is a button that dismisses the toast when clicked.
All props from button, plus:
To keep the toast open on click, call event.preventDefault() in your onClick handler.
makeToast
The makeToast function creates and displays a toast. It accepts the following parameters: