Skip to content
Vertical Jump Designs-uiFront-End Studio
Get Pro

v3.9 is out.

Feedback

Toast

Free17.7 KB gzipped

The 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

tsx
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.

tsx
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.

tsx
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.

tsx
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.

tsx
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.

tsx
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

tsx
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

Toast props
PropTypeDefault
tone

Semantic color and default icon. loading shows a Spinner.

"loading""neutral""success""warning""danger""info""neutral"
title

Bold display headline.

ReactNode—
description

Supporting text under the title.

ReactNode—
icon

Replaces the tone's default icon (decorative). Pass null to hide the icon.

ReactNode—
action

Action button. Pressing it calls action.onClick, then onDismiss unless the handler calls event.preventDefault().

ToastAction—
dismissible

Shows the close button.

booleantrue
onDismiss

Called by the close button and after an action.

() => void—
closeLabel

Accessible name of the close button. Localize it here.

string"Dismiss notification"
toneLabel

Screen 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
progressDuration

Shows a thin decorative bar that empties over this many milliseconds. Omit (or pass Infinity) for no bar.

number—
progressKey

Changing this value restarts the progress bar (e.g. after the toast is updated).

string | number—
paused

Freezes the progress bar (the viewport sets this while timers are paused).

booleanfalse
children

Extra 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 and role="alert" for danger.
  • Timers pause while the viewport is hovered or focused and while the window is blurred or hidden. Toasts with an action, and loading toasts, stay until dismissed by default.
ToastProvider props
PropTypeDefault
children

Your app. Anything inside can call useToast().

ReactNode—
store

Store to render. Defaults to the shared store used by the exported toast(), so imperative calls from non-React code show up here. Pass one from createToastStore() to isolate a provider.

ToastStore—
placement

Corner 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"
max

Most toasts shown at once. Extra toasts wait in a queue and appear as others close.

number3
duration

Default auto-close time in milliseconds. Raised to a readable minimum (4s plus 250ms per word). Pass Infinity to keep toasts until dismissed.

number5000
gap

Space between toasts (a --space-* step).

Space3
label

Accessible name of the viewport region. The hotkey is appended, e.g. "Notifications (F8)".

string"Notifications"
hotkey

Keys that move focus to the newest toast, as KeyboardEvent.key or .code values plus optional modifiers ("Alt", "Control", "Meta", "Shift"), e.g. ["Alt", "KeyT"]. Pass [] to turn it off.

readonly string[]["F8"]
showProgress

Shows a decorative bar for each toast's remaining time.

booleanfalse
toneLabels

Screen reader labels read before each toast's message, per tone. Localize them here.

Partial<Record<ToastTone, string>>—
closeLabel

Accessible name of every close button.

string"Dismiss notification"
queuedLabel

Text for the queue count shown when more than max toasts are waiting.

(count: number) => string"+N more notifications"
className

Class 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)

Running accessibility audit

Checking the examples above…

Lighthouse audit

Light mode

Score 100

35 passed · 0 failed · 30 not applicable · 10 to check by hand

Dark mode

Score 100

35 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

Keyboard
KeyAction
F8Moves focus to the newest toast (hotkey on ToastProvider).
TabMoves through toasts and their buttons.
EscapeCloses 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

Roles and states
ElementRoleStates and properties
Viewportregionaria-label ("Notifications (F8)")
Announcementsstatus, or alert for dangerPersistent 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.

Manual accessibility checks
CheckWhat to testWCAG 2.2
KeyboardEvery 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)
FocusFocus 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 readersNames, 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)
ColorMeaning 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 reflowAt 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 targetsClick 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)
MotionAnimations respect the reduced-motion setting.2.3.3 (AAA)