Toast
Timed live notifications with hover/focus pause, keyboard shortcuts, and explicit actions.
Toast displays brief, non-blocking notifications with auto-dismiss timers that pause on hover or focus, keyboard navigation shortcuts, and optional action buttons. The examples on this page use the Shadcn Rhea style preset.
Preview
Section titled “Preview”<proto-ui-shadcn-style-scope id="toast-scope">
<proto-ui-shadcn-button id="toast-trigger">
Show Toast
</proto-ui-shadcn-button>
<proto-ui-shadcn-toast-viewport id="toast-viewport">
<proto-ui-shadcn-toast-root id="toast-root">
<div class="flex items-start justify-between gap-4">
<div class="grid gap-1">
<proto-ui-shadcn-toast-title>
Event has been created
</proto-ui-shadcn-toast-title>
<proto-ui-shadcn-toast-description>
Sunday, December 03, 2023 at 9:00 AM
</proto-ui-shadcn-toast-description>
</div>
<div class="flex items-center gap-2 shrink-0">
<proto-ui-shadcn-toast-action id="toast-action">
Undo
</proto-ui-shadcn-toast-action>
<proto-ui-shadcn-toast-close>
Dismiss
</proto-ui-shadcn-toast-close>
</div>
</div>
</proto-ui-shadcn-toast-root>
</proto-ui-shadcn-toast-viewport>
</proto-ui-shadcn-style-scope>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
setElementProps(document.querySelector('#toast-scope'), {
styleProfile: 'rhea',
});
setElementProps(document.querySelector('#toast-trigger'), {
variant: 'outline',
});
setElementProps(document.querySelector('#toast-viewport'), {
a11yLabel: 'Notifications',
});
setElementProps(document.querySelector('#toast-root'), {
defaultOpen: false,
duration: 5000,
});
setElementProps(document.querySelector('#toast-action'), {
a11yLabel: 'Undo event creation',
});
document
.querySelector('#toast-trigger')
.addEventListener('click', () => {
document
.querySelector('#toast-root')
.getExposes()
.openToast();
});
</script>Installation
Section titled “Installation”Available starting in 0.3.0-rc.1 and later releases. Import the prototypes directly from @proto.ui/prototypes-shadcn/toast and adapt them for your target runtime.
import { toastViewport, toastRoot, toastTitle, toastDescription, toastAction, toastClose,} from '@proto.ui/prototypes-shadcn/toast';<ShadcnToastViewport a11yLabel="Notifications"> <ShadcnToastRoot defaultOpen={false} duration={5000}> <ShadcnToastTitle>Event has been created</ShadcnToastTitle> <ShadcnToastDescription>Sunday, December 03, 2023 at 9:00 AM</ShadcnToastDescription> <ShadcnToastAction a11yLabel="Undo event creation">Undo</ShadcnToastAction> <ShadcnToastClose>Dismiss</ShadcnToastClose> </ShadcnToastRoot></ShadcnToastViewport>Toast consists of Root, Viewport, Title, Description, Action, and Close:
Rootstays open for5000msby default before requesting dismissal; setduration={0}to keep a notification open until explicitly dismissed.- Hovering over the toast or focusing
ActionorClosepauses the remaining timer until the pointer or focus leaves. - Clicking
Close, pressingEscapewhile focused, or activatingActionrequests dismissal; your application handles the action’s side effects. - In controlled mode (
opensupplied), reaching the timeout emits a single dismissal request until your state updates. Viewportlabels the notification region (defaultNotifications) and provides theF8shortcut to jump focus directly to the viewport. Managing a queue of multiple toasts stays in your application state.
Examples
Section titled “Examples”Set type (default, success, info, warning, error, or loading) to classify the notification, and pair error notices with politeness="assertive".
<proto-ui-shadcn-style-scope id="toast-types-scope">
<div class="flex flex-wrap gap-2">
<proto-ui-shadcn-button data-toast-open="default">
Default
</proto-ui-shadcn-button>
<proto-ui-shadcn-button data-toast-open="success">
Success
</proto-ui-shadcn-button>
<proto-ui-shadcn-button data-toast-open="info">
Info
</proto-ui-shadcn-button>
<proto-ui-shadcn-button data-toast-open="warning">
Warning
</proto-ui-shadcn-button>
<proto-ui-shadcn-button data-toast-open="error">
Error
</proto-ui-shadcn-button>
</div>
<proto-ui-shadcn-toast-viewport id="toast-types-viewport">
<proto-ui-shadcn-toast-root id="toast-default">
<proto-ui-shadcn-toast-title>
Event has been created
</proto-ui-shadcn-toast-title>
<proto-ui-shadcn-toast-description>
Sunday, December 03, 2023 at 9:00 AM
</proto-ui-shadcn-toast-description>
</proto-ui-shadcn-toast-root>
<proto-ui-shadcn-toast-root id="toast-error">
<proto-ui-shadcn-toast-title>
Request failed
</proto-ui-shadcn-toast-title>
<proto-ui-shadcn-toast-description>
Event could not be created.
</proto-ui-shadcn-toast-description>
</proto-ui-shadcn-toast-root>
</proto-ui-shadcn-toast-viewport>
</proto-ui-shadcn-style-scope>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
setElementProps(document.querySelector('#toast-types-scope'), {
styleProfile: 'rhea',
});
setElementProps(document.querySelector('#toast-default'), {
defaultOpen: false,
type: 'default',
});
setElementProps(document.querySelector('#toast-error'), {
defaultOpen: false,
type: 'error',
politeness: 'assertive',
});
</script>Action
Section titled “Action”Use Action for explicit undo or retry intents. Activating it emits action before requesting dismissal.
<proto-ui-shadcn-style-scope id="toast-action-scope">
<proto-ui-shadcn-button id="schedule-btn">
Schedule Meeting
</proto-ui-shadcn-button>
<proto-ui-shadcn-toast-viewport>
<proto-ui-shadcn-toast-root id="scheduled-toast">
<div class="flex items-start justify-between gap-4">
<div class="grid gap-1">
<proto-ui-shadcn-toast-title>
Meeting scheduled
</proto-ui-shadcn-toast-title>
<proto-ui-shadcn-toast-description>
Design review set for Tuesday at 2:00 PM.
</proto-ui-shadcn-toast-description>
</div>
<proto-ui-shadcn-toast-action id="undo-action">
Undo
</proto-ui-shadcn-toast-action>
</div>
</proto-ui-shadcn-toast-root>
</proto-ui-shadcn-toast-viewport>
</proto-ui-shadcn-style-scope>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
setElementProps(document.querySelector('#toast-action-scope'), {
styleProfile: 'rhea',
});
setElementProps(document.querySelector('#schedule-btn'), {
variant: 'outline',
});
setElementProps(document.querySelector('#scheduled-toast'), {
defaultOpen: false,
duration: 6000,
});
document
.querySelector('#schedule-btn')
.addEventListener('click', () => {
document
.querySelector('#scheduled-toast')
.getExposes()
.openToast();
});
</script>Promise
Section titled “Promise”Keep a loading toast open with type="loading" and duration={0} while an async task runs, then switch to a result toast once it finishes.
<proto-ui-shadcn-style-scope id="toast-promise-scope">
<proto-ui-shadcn-button id="create-event-btn">
Create Event
</proto-ui-shadcn-button>
<proto-ui-shadcn-toast-viewport>
<proto-ui-shadcn-toast-root id="loading-toast">
<proto-ui-shadcn-toast-title>
Creating event…
</proto-ui-shadcn-toast-title>
<proto-ui-shadcn-toast-description>
Syncing calendar details with participants.
</proto-ui-shadcn-toast-description>
</proto-ui-shadcn-toast-root>
<proto-ui-shadcn-toast-root id="done-toast">
<proto-ui-shadcn-toast-title>
Event created
</proto-ui-shadcn-toast-title>
<proto-ui-shadcn-toast-description>
Invitations have been sent to all attendees.
</proto-ui-shadcn-toast-description>
</proto-ui-shadcn-toast-root>
</proto-ui-shadcn-toast-viewport>
</proto-ui-shadcn-style-scope>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const loading = document.querySelector('#loading-toast');
const done = document.querySelector('#done-toast');
setElementProps(document.querySelector('#toast-promise-scope'), {
styleProfile: 'rhea',
});
setElementProps(loading, {
defaultOpen: false,
duration: 0,
type: 'loading',
});
setElementProps(done, {
defaultOpen: false,
duration: 4000,
type: 'success',
});
document
.querySelector('#create-event-btn')
.addEventListener('click', () => {
loading.getExposes().openToast();
setTimeout(() => {
loading.getExposes().close('programmatic');
done.getExposes().openToast();
}, 1500);
});
</script>Position
Section titled “Position”Set position on Viewport (top-left, top-center, top-right, bottom-left, bottom-center, or bottom-right) to anchor the notification stack in any viewport corner or edge, and call dismissAll() to clear active notifications together.
<proto-ui-shadcn-toast-viewport
position="top-center"
a11y-label="Positioned notifications"
>
<proto-ui-shadcn-toast-root type="info" duration="4000">
<proto-ui-shadcn-toast-title>
Toast (Top Center)
</proto-ui-shadcn-toast-title>
<proto-ui-shadcn-toast-description>
Viewport position set to "top-center".
</proto-ui-shadcn-toast-description>
<proto-ui-shadcn-toast-close>
Dismiss
</proto-ui-shadcn-toast-close>
</proto-ui-shadcn-toast-root>
</proto-ui-shadcn-toast-viewport>Rich Colors & Status Icons
Section titled “Rich Colors & Status Icons”Enable richColors on Root to pair built-in semantic status icons (success, info, warning, error, loading) with tinted surfaces. type="loading" stays persistent until resolved or explicitly timed out, and type="error" defaults to politeness="assertive".
<proto-ui-shadcn-toast-viewport position="bottom-right" expand>
<proto-ui-shadcn-toast-root type="success" rich-colors>
<proto-ui-shadcn-toast-title>
Deployment succeeded
</proto-ui-shadcn-toast-title>
<proto-ui-shadcn-toast-description>
Release 0.3.0 is live in production.
</proto-ui-shadcn-toast-description>
<proto-ui-shadcn-toast-close>
Dismiss
</proto-ui-shadcn-toast-close>
</proto-ui-shadcn-toast-root>
</proto-ui-shadcn-toast-viewport>Controlled & Persistent
Section titled “Controlled & Persistent”Supply open and duration={0} when your application controls when a critical notification appears and closes.
<proto-ui-shadcn-style-scope id="toast-persistent-scope">
<proto-ui-shadcn-button id="open-persistent">
Show Persistent Toast
</proto-ui-shadcn-button>
<proto-ui-shadcn-toast-viewport>
<proto-ui-shadcn-toast-root id="persistent-toast">
<div class="flex items-start justify-between gap-4">
<div class="grid gap-1">
<proto-ui-shadcn-toast-title>
Connection lost
</proto-ui-shadcn-toast-title>
<proto-ui-shadcn-toast-description>
Changes are paused until you reconnect or dismiss this
notice.
</proto-ui-shadcn-toast-description>
</div>
<proto-ui-shadcn-toast-close>
Dismiss
</proto-ui-shadcn-toast-close>
</div>
</proto-ui-shadcn-toast-root>
</proto-ui-shadcn-toast-viewport>
</proto-ui-shadcn-style-scope>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const root = document.querySelector('#persistent-toast');
setElementProps(
document.querySelector('#toast-persistent-scope'),
{ styleProfile: 'rhea' }
);
setElementProps(root, {
open: false,
duration: 0,
politeness: 'assertive',
type: 'warning',
});
document
.querySelector('#open-persistent')
.addEventListener('click', () =>
setElementProps(root, { open: true })
);
root.addEventListener('openChange', (event) =>
setElementProps(root, { open: event.detail.open })
);
</script>| Prop | Type | Default |
|---|---|---|
open | boolean | — |
defaultOpen | boolean | true |
duration | number | 5000 (0 for loading) |
paused | boolean | false |
politeness | 'polite' 'assertive' | 'polite' ('assertive' for error) |
type | 'default' 'success' 'info' 'warning' 'error' 'loading' | 'default' |
dismissible | boolean | true |
richColors | boolean | false |
position | 'top-left' 'top-center' 'top-right' 'bottom-left' 'bottom-center' 'bottom-right' | Inherited from Viewport |
appear | boolean | false |
enterDuration | number | 0 |
leaveDuration | number | 0 |
interrupt | 'reverse' 'wait' 'immediate' | 'reverse' |
styleProfile | ShadcnStyleId | Inherited from scope |
Viewport, Action & Close
Section titled “Viewport, Action & Close”| Prop | Type | Default |
|---|---|---|
Viewport.a11yLabel | string | 'Notifications' |
Viewport.hotkey | string | 'F8' |
Viewport.position | 'top-left' 'top-center' 'top-right' 'bottom-left' 'bottom-center' 'bottom-right' | 'bottom-right' |
Viewport.expand | boolean | false |
Viewport.visibleToasts | number | 3 |
Viewport.duration | number | — |
Viewport.swipeDirection | 'right' 'left' 'up' 'down' 'none' | 'right' |
Action.disabled | boolean | false |
Action.a11yLabel | string | — |
Action.keepOpen | boolean | false |
Close.disabled | boolean | false |
Events and exposed methods:
- Events:
RootemitsopenChange({ open: boolean; reason: string });Actionemitsaction(void). - Methods:
RootexposesopenToast(),close(reason?),pause(), andresume();ViewportexposesfocusFirst(),pauseAll(),resumeAll(), anddismissAll(reason?).