Toast
Temporary notifications.
MarkdownExamples
useToast()
Place <UiToastViewport /> once near the app root.
Action
action adds a button, e.g. Undo. Pressing it runs onClick and dismisses the toast.
In your inbox
API
ToastViewport
| Prop | Type | Default |
|---|---|---|
labelAccessible name of the live region. Defaults to the | string | — |
| Slot | Props |
|---|---|
defaultRenders each toast, replacing the message and close button. | { toast: Toast; dismiss: () => void; } |
close-iconReplaces each close button's icon. | — |
Types
export interface Toast {
id: number;
message: string;
tone: ToastTone;
/** Milliseconds before auto-dismiss; `0` keeps it until dismissed. */
duration: number;
/** A button in the toast, e.g. "Undo". Pressing it also dismisses the toast. */
action?: ToastAction;
}
export type ToastTone = "success" | "danger" | "info";
export interface ToastAction {
label: string;
onClick: () => void;
}Copy codeToastItem
| Prop | Type | Default |
|---|---|---|
toast*The toast to render, from | Toast | — |
| Event | Payload |
|---|---|
dismissTimed out or closed. | [id: number] |
| Slot | Props |
|---|---|
defaultReplaces the message and close button. | { toast: Toast; dismiss: () => void; } |
close-iconReplaces the close button's icon. | — |
Types
export interface Toast {
id: number;
message: string;
tone: ToastTone;
/** Milliseconds before auto-dismiss; `0` keeps it until dismissed. */
duration: number;
/** A button in the toast, e.g. "Undo". Pressing it also dismisses the toast. */
action?: ToastAction;
}
export type ToastTone = "success" | "danger" | "info";
export interface ToastAction {
label: string;
onClick: () => void;
}Copy codeStyling
- Parts
toast-viewporttoasttoast-messagetoast-actiontoast-close- States
data-toast-tone
- Parts
toasttoast-messagetoast-actiontoast-close- States
data-toast-tone
Accessibility
- Toasts are announced politely; errors are announced right away.
- Timers pause on hover, focus and hidden tabs, then resume with the time left.
duration: 0keeps a toast until dismissed. - Shown above an open modal dialog, but the browser makes it inert there: it can't be clicked or announced until the dialog closes.