Feedback
Toast
Free17.7 KB gzippedThe toast card: a raised, rounded surface with a tone icon in a tinted circle, a bold title, a description, an optional action, and a close button. ToastProvider renders these for you; use Toast directly for custom render content or static previews.
Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · Keys: F8, Tab, Escape · Full report
Import
import { Toast, ToastProvider } from "@vjdesigns/vjdesigns-ui";
Importing only Toast adds about 17.7 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.
Examples
Tones
Wrap your app in ToastProvider once, then call toast() from useToast(), or import the standalone toast to call it outside React. Press F8 to move focus to the notifications.
import { Button, Flex, useToast } from "@vjdesigns/vjdesigns-ui";
export function Tones() {
const { toast } = useToast();
return (
<Flex gap={3} wrap="wrap" justify="center">
<Button variant="outline" tone="neutral" onClick={() => toast({ title: "Draft saved" })}>
Neutral
</Button>
<Button variant="outline" tone="success" onClick={() => toast.success("Invite sent", { description: "Sam will get an email shortly." })}>
Success
</Button>
<Button variant="outline" tone="warning" onClick={() => toast.warning("You're offline", { description: "Changes will sync when you reconnect." })}>
Warning
</Button>
<Button variant="outline" tone="danger" onClick={() => toast.error("Couldn't upload photo", { description: "The file is larger than 10 MB." })}>
Error
</Button>
</Flex>
);
}
With action
An action gives people a way to respond. altText tells screen reader users how to do it without the button.
import { Button, useToast } from "@vjdesigns/vjdesigns-ui";
export function WithAction() {
const { toast } = useToast();
return (
<Button
variant="outline"
tone="neutral"
onClick={() =>
toast({
title: "Conversation archived",
action: {
label: "Undo",
altText: "Find it again under Archived",
onClick: () => toast.success("Conversation restored"),
},
})
}
>
Archive conversation
</Button>
);
}
From apromise
toast.promise shows a loading toast that turns into success or error when the promise settles.
import { Button, useToast } from "@vjdesigns/vjdesigns-ui";
export function FromAPromise() {
const { toast } = useToast();
const publish = () => new Promise((resolve) => setTimeout(resolve, 1800));
return (
<Button
onClick={() =>
toast.promise(publish, {
loading: "Publishing…",
success: "Published to production",
error: "Publishing failed",
})
}
>
Publish
</Button>
);
}
Accessibility
Toasts are announced without moving focus. Their auto-close time is raised to a readable minimum (4 s plus 250 ms per word), and F8 moves focus to the notifications so keyboard users can reach them before they close.
import { Button, Flex, useToast } from "@vjdesigns/vjdesigns-ui";
export function Accessibility() {
const { toast } = useToast();
return (
<Flex gap={3} wrap="wrap" justify="center">
<Button variant="outline" tone="neutral" onClick={() => toast.success("Settings saved")}>
Save settings
</Button>
<Button
variant="outline"
tone="danger"
onClick={() => toast.error("Couldn't send message", { description: "Check your connection and try again." })}
>
Send message
</Button>
</Flex>
);
}
Translated
A ToastProvider inside a LocaleProvider uses the locale for the close button, the spoken tone and the region's name (Japanese here). The message is your own text. Each store gets one set of notifications, so a second provider on the same store, like this one inside the app's, would only reuse the app's. Give it its own createToastStore() to show separate ones.
import { useState } from "react";
import {
Button,
useToast,
LocaleProvider,
ToastProvider,
createToastStore,
} from "@vjdesigns/vjdesigns-ui";
import ja from "@vjdesigns/vjdesigns-ui/locales/ja";
function JapaneseToastButton() {
const { toast } = useToast();
return (
<Button variant="outline" tone="neutral" onClick={() => toast.success("保存しました", { description: "変更はチーム全員に表示されます。" })}>
保存
</Button>
);
}
export function Translated() {
const [store] = useState(createToastStore);
return (
<LocaleProvider locale="ja" messages={ja}>
<ToastProvider store={store} placement="bottom-end">
<JapaneseToastButton />
</ToastProvider>
</LocaleProvider>
);
}
Right to left
The first example again, inside a right-to-left LocaleProvider (Arabic). Layout, spacing and arrow icons mirror, and the components' built-in text is translated. The example's own text stays in English.
Tones
import { LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";
// Tones is the "Tones" example above.
<LocaleProvider locale="ar" messages={ar}>
<Tones />
</LocaleProvider>
Usage notes
The card itself is not a live region; the viewport announces toasts through its own persistent regions. When rendered outside a viewport, announce it yourself if needed.
API reference
Toast
| Prop | Type | Default |
|---|---|---|
toneSemantic color and default icon. | "loading""neutral""success""warning""danger""info" | "neutral" |
titleBold display headline. | ReactNode | — |
descriptionSupporting text under the title. | ReactNode | — |
iconReplaces the tone's default icon (decorative). Pass | ReactNode | — |
actionAction button. Pressing it calls | ToastAction | — |
dismissibleShows the close button. | boolean | true |
onDismissCalled by the close button and after an action. | () => void | — |
closeLabelAccessible name of the close button. Localize it here. | string | "Dismiss notification" |
toneLabelScreen reader prefix that names the tone, so it is not conveyed by color and icon alone. | string | "Success", "Error", "Warning", "Info", "Loading"; none for neutral |
progressDurationShows a thin decorative bar that empties over this many milliseconds. Omit (or pass | number | — |
progressKeyChanging this value restarts the progress bar (e.g. after the toast is updated). | string | number | — |
pausedFreezes the progress bar (the viewport sets this while timers are paused). | boolean | false |
childrenExtra content under the description. | ReactNode | — |
Also accepts native <div> attributes, plus className, style and ref.
ToastProvider
Renders the toast viewport (in a portal) and provides useToast(). Place it once near the root of your app, inside your LocaleProvider so its built-in text (like "+2 more notifications") is in the app's language. Each store gets one viewport: a second provider on the same store (nested or not) only provides useToast(), so toasts are never drawn twice.
Accessibility:
- The viewport is a labelled region ("Notifications (F8)"). The hotkey moves focus to the newest toast; Tab moves through toasts and their buttons; Escape closes the focused toast; focus then moves to the next toast, or back to where it was before.
- Announcements go through persistent live regions that exist before any toast appears:
role="status"for most tones androle="alert"fordanger. - Timers pause while the viewport is hovered or focused and while the window is blurred or hidden. Toasts with an action, and
loadingtoasts, stay until dismissed by default.
| Prop | Type | Default |
|---|---|---|
childrenYour app. Anything inside can call | ReactNode | — |
storeStore to render. Defaults to the shared store used by the exported | ToastStore | — |
placementCorner or edge of the screen. Below 640px wide toasts always sit full width at the bottom. | "top-start""top-center""top-end""bottom-start""bottom-center""bottom-end" | "bottom-end" |
maxMost toasts shown at once. Extra toasts wait in a queue and appear as others close. | number | 3 |
durationDefault auto-close time in milliseconds. Raised to a readable minimum (4s plus 250ms per word). Pass | number | 5000 |
gapSpace between toasts (a | Space | 3 |
labelAccessible name of the viewport region. The hotkey is appended, e.g. "Notifications (F8)". | string | "Notifications" |
hotkeyKeys that move focus to the newest toast, as | readonly string[] | ["F8"] |
showProgressShows a decorative bar for each toast's remaining time. | boolean | false |
toneLabelsScreen reader labels read before each toast's message, per tone. Localize them here. | Partial<Record<ToastTone, string>> | — |
closeLabelAccessible name of every close button. | string | "Dismiss notification" |
queuedLabelText for the queue count shown when more than | (count: number) => string | "+N more notifications" |
classNameClass name for the viewport region. | string | — |
See what changed in each version in the Changelog.
Accessibility report
Toast targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.
axe-core audit (live)
Checking the examples above…
Lighthouse audit
Light mode
Score 10035 passed · 0 failed · 30 not applicable · 10 to check by hand
Dark mode
Score 10035 passed · 0 failed · 30 not applicable · 10 to check by hand
Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.
Built-in behavior
Keyboard
| Key | Action |
|---|---|
| F8 | Moves focus to the newest toast (hotkey on ToastProvider). |
| Tab | Moves through toasts and their buttons. |
| Escape | Closes the focused toast; focus moves to the next toast, or back to where it was. |
Timers pause while the viewport is hovered or focused.
Roles and states
| Element | Role | States and properties |
|---|---|---|
| Viewport | region | aria-label ("Notifications (F8)") |
| Announcements | status, or alert for danger | Persistent live regions, present before any toast |
Manual checks
Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.
| Check | What to test | WCAG 2.2 |
|---|---|---|
| Keyboard | Every action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck. | 2.1.1 (A), 2.1.2 (A) |
| Focus | Focus moves in a logical order, is always visible, and isn't hidden behind sticky headers. | 2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA) |
| Screen readers | Names, roles and states are announced correctly, and status changes are announced without moving focus. | 1.3.1 (A), 4.1.2 (A), 4.1.3 (AA) |
| Color | Meaning never depends on color alone; your own colors meet contrast in both modes. | 1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA) |
| Zoom and reflow | At 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed. | 1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA) |
| Pointer targets | Click and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap. | 2.5.8 (AA), 2.5.5 (AAA) |
| Motion | Animations respect the reduced-motion setting. | 2.3.3 (AAA) |