Skip to content

Toast

A succinct message that is displayed temporarily.

Install

Bash
npx @madeui/cli add toast

Usage

TSX
import { toast, Toaster, ToastProvider } from '@/components/ui/toast';

// 1. Wrap your app in <ToastProvider> and mount <Toaster /> once (e.g. in the root layout).
// 2. Call `toast` from anywhere — components, event handlers, stores:
toast('Saved', { description: 'Your changes were saved.' });
toast.success('Deployed');
toast.error('Could not save');

Stacking

Toasts pile up behind the newest one (up to the provider’s limit, 3 by default). Hovering or focusing the stack expands it to show every toast. Trigger the demo above a few times in a row to see it.

Swipe to dismiss

Drag a toast down or right (touch or mouse) to dismiss it. Configure with <Toaster swipeDirection={['down', 'right']} /> — any of 'up' | 'down' | 'left' | 'right', or a single value.

Promise

toast.promise shows a loading toast, then updates it in place when the promise settles.

Duration

Types

toast.success and toast.error set a type on the toast (mirrored as data-type on the rendered element). Styling is identical across types out of the box — since you own components/ui/toast.tsx, add a [data-type="…"] condition to styles.root to color-code them.

Action

Pass actionProps to render an action button inside the toast.

Position

The stack’s screen position lives in Toaster’s own styles; override it with the style prop, same as any other component in this library.

API reference

Built on Base UI Toast. The tables below cover the props this library adds or changes — every other prop is forwarded to the underlying Base UI part; see the Base UI Toast API reference for the full list.

toast(title, options?)

Imperative API backed by a module-level toast manager — no hook needed, works outside React. useToast() remains available for the hook form (useToast().add({ … })).

PropTypeDefaultDescription
titleReactNode—Toast heading.
descriptionReactNode—Supporting text.
timeoutnumber—Auto-dismiss delay in ms (Base UI default: 5000).
typestring—Toast type; toast.success / toast.error set it for you.
actionPropsobject—Props for the action button (e.g. { children: 'Undo', onClick }).

Also available: toast.promise(promise, { loading, success, error }), toast.update(id, options), toast.close(id).

Toaster

PropTypeDefaultDescription
swipeDirectionDirection | Direction[]['down', 'right']Direction(s) a toast can be swiped to dismiss.

Toaster renders the styled toast stack; to change its look, edit components/ui/toast.tsx directly — you own the source.

Was this page helpful?