Web · Components
Toaster
Places notifications shown with toast on the screen.
Live example
Preview
Code
Events
- Events appear here when you interact with the preview.
Import
Places notifications shown with toast on the screen. Add it once to the root layout.
Features:
- Stack: Notifications stack by default and expand on mouse hover (see
ToasterProps.stack). When a notification arrives, closes or changes height, the others move smoothly. - Always on top: It sits in the Popover API's top layer; it doesn't end up behind an open Dialog. While a modal Dialog is open, notifications stay clickable and are read by screen readers; when a Dialog opens or closes they stay in place, don't re-animate and their timers don't reset.
- The timer pauses smartly: It doesn't run while the mouse is over, keyboard focus is inside or the tab is in the background; the user doesn't miss a notification they didn't see.
- Mobile: Full width, respects notch and home bar insets, swipe to dismiss (bottom ones down, top ones up; toward the edge on wide screens).
- Accessibility: Notifications are read to screen readers (errors immediately, others in turn). F8 jumps to the notification area.
- Renders empty on the server; no hydration mismatch.
Examples
toast
constantShows a short notification (toast) and returns its id. Can be called from anywhere on the client (event handler, server action result, code outside components); for it to show, there must be a Toaster in the root layout. Does nothing if called on the server.
Examples
ToastVariant
typeType of the notification; determines its color, icon and screen reader behavior.
ToastAction
interfaceAction button in the notification.
| Name | Type | Description |
|---|---|---|
label | ReactNode | Button text or content (e.g. icon and text). |
onClick | () => void | Called when clicked; then the notification closes. |
ToastOptions
interfaceOptions that can be given when showing a notification with toast.
| Name | Type | Default | Description |
|---|---|---|---|
id? | string | Id of the notification. If called again with the same id, no new notification opens; the existing one is updated (e.g. "Loading" → "Saved"). | |
description? | ReactNode | Description below the title. | |
variant? | ToastVariant | "default" | Type of the notification. |
icon? | IconProp | Icon before the title: name ("heart") or element. If omitted, the type's own icon is used; with false no icon is shown. | |
duration? | number | Auto-close duration (ms). With Infinity it stays until the user closes it. If omitted, the Toaster setting is used; the "loading" type doesn't close by itself. | |
action? | ToastAction | Action button in the notification (e.g. "Undo"). | |
onDismiss? | () => void | Called when the notification closes in any way. |
ToastData
interfaceRecord of a notification shown on screen.
| Name | Type | Description |
|---|---|---|
id | string | Id of the notification. |
title | ReactNode | Title of the notification. |
variant | ToastVariant | Type of the notification. |
closing | boolean | Is the closing animation playing? |
description? | ReactNode | Description below the title. |
icon? | IconProp | Icon before the title: name ("heart") or element. If omitted, the type's own icon is used; with false no icon is shown. |
duration? | number | Auto-close duration (ms). With Infinity it stays until the user closes it. If omitted, the Toaster setting is used; the "loading" type doesn't close by itself. |
action? | ToastAction | Action button in the notification (e.g. "Undo"). |
onDismiss? | () => void | Called when the notification closes in any way. |
ToastPromiseMessages
interfacetoast.promise messages; success and error messages can be produced from the result.
| Name | Type | Description |
|---|---|---|
loading | ReactNode | Title shown while the promise is pending. |
success | ReactNode | ((value: T) => ReactNode) | Title shown when the promise resolves; can also be produced from the result value. |
error | ReactNode | ((error: unknown) => ReactNode) | Title shown when the promise rejects; can also be produced from the error. |
ToastFunction
interfaceType of the toast function.
| Name | Type | Description |
|---|---|---|
success | VariantShortcut | Shows a success notification. |
error | VariantShortcut | Shows an error notification; read to screen readers immediately. |
warning | VariantShortcut | Shows a warning notification. |
loading | VariantShortcut | Shows a "loading" notification that stays until the user closes or updates it. |
dismiss | (id?: string): void | Closes the notification. If no id is given, closes all of them. |
ToastPosition
typeOn-screen position of the toasts.
ToasterProps
interfaceProps of the Toaster component.
Extends: Omit<ComponentProps<"ol">, "children">
| Name | Type | Default | Description |
|---|---|---|---|
position? | ToastPosition | "bottom-right" | Position on wide screens. On small screens notifications are always full width and only the top/bottom choice is kept. |
stack? | boolean | true | Stacks notifications: the newest in front, older ones slightly visible behind it. On mouse hover, when keyboard focus enters or when the stack is tapped on a touch screen, notifications expand into a list; they collapse again on leaving. With false they are always listed. |
duration? | number | 5000 | Default auto-close duration (ms). |
visibleToasts? | number | 3 | Maximum number of notifications visible at once. Extras queue up and are shown when space frees; their timers don't run while queued. |
hotkey? | string | null | "F8" | Shortcut key for jumping to the notification area with the keyboard (KeyboardEvent.key (https://developer.mozilla.org/docs/Web/API/KeyboardEvent/key)). Turned off with null. |
label? | string | the `notifications` text (`"Bildirimler"`) | Region name for screen readers. |
effect? | EffectProp | Effect or effects of each notification (e.g. "beam", ["border", "shine"]). If omitted, UIProvider appearance.defaults.toast.effect. See BuiltinEffect. |