Skip to content

Toast

A short message that appears at the edge of the screen and goes by itself (DGA: Notification Toast). Five kinds, an action, a close button, and announced to screen readers.

Version 0.4.1 ·

Toast

Installation

bunx --bun shadcn@latest add @dga/toast

Usage

page.tsx
tsx
import { Button } from "@/components/ui/button";
import { Toaster, toast } from "@/components/ui/toast";

// Once, at the root of the app (for example in layout.tsx).
export function Providers({ children }: { children: React.ReactNode }) {
  return (
    <>
      {children}
      <Toaster closeLabel="Close" regionLabel="Notifications" />
    </>
  );
}

export function SubmitButton() {
  return (
    <Button
      onClick={() =>
        toast.add({
          type: "success",
          title: "Request submitted",
          description: "Your reference number is 24810.",
        })
      }
    >
      Submit
    </Button>
  );
}

Use a Toast to confirm something that just happened and needs no reply: a request was sent, a draft was saved. Do not use it for an error that blocks the person (show it next to the field, or in an Inline Alert), or for anything they must act on before it disappears. Mount one Toaster at the root and call toast.add({ title, description, type }) from anywhere, even outside React. type is neutral, info, success, warning or error. A toast goes after 6 seconds; pass timeout: 0 for one that stays until it is closed, and use that for errors people need to read. Keep the message to one short sentence; an actionProps button gives one quick action (such as Undo).

Anatomy

  • Toaster (role="region", a live region): the list at the bottom end of the screen. It holds up to 3 toasts.
  • Toast: 484px wide (full width on phones), radius-md, shadow-3xl, on background-notification-white.
  • Bar: 8px on the start side, in the kind's 400 colour.
  • Icon, title, description, an optional action and a close button.

Examples

Kinds

Press a button to add a toast. error and warning are announced at once (priority: "high"), the others politely. Success here has an action.

Kinds

Timeout, priority and actions

A toast closes by itself after six seconds. Pass timeout: 0 to toast.add to keep it until the person closes it, and actionProps to add a button. Warnings and errors use priority: "high", so a screen reader announces them at once; the others wait their turn. Only three toasts show at once (limit on Toaster), and the rest queue behind them.

Timeout, priority and actions

RTL

Toasts appear at the bottom end of the screen: the bottom right in English and the bottom left in Arabic. The bar is on the start side, and a swipe toward the edge they came from dismisses them.

LTR (English)
RTL (Arabic)

Accessibility

KeyAction
F6Moves focus into the toast region (when there are toasts). Escape or a click elsewhere returns it.
TabMoves between the action and close buttons of the toasts.
EnterPresses the focused action or close button.
EscapeCloses the focused toast.
  • Built on Base UI Toast. The viewport is a live region: new toasts are announced without moving focus (polite, or assertive for priority: "high"). Announce short, complete sentences.
  • A toast does not go while the pointer is over it or focus is inside it, and the timer restarts after (WCAG 2.2.1). Use timeout: 0 for anything people may need more time to read.
  • The kind is shown by an icon and the title as well as the bar, never by colour alone. Text is 4.5:1 and icons 3:1 or better, in light and dark. The close button has an accessible name (closeLabel).
  • With reduced motion a toast appears and goes without sliding.

API Reference

Toaster

Put one Toaster at the root of the app (DGA: Notification Toast). It lists the toasts at the bottom end of the screen: bottom right on English pages, bottom left on Arabic pages. A toast is announced to screen readers when it appears (a polite live region, assertive for errors and warnings), stays while it is hovered or focused, and can be swiped away.

Toaster props
PropTypeDefault
number

The most toasts shown at once.

3
number

How long a toast stays, in milliseconds. `0` keeps it until it is closed.

6000
string

Accessible name of the close button. Translate it on Arabic pages.

"Close"
string

Accessible name of the region that holds the toasts. Translate it on Arabic pages.

"Notifications"

Also accepts every prop of the Base UI Toast (opens in a new tab).

Deviations from DGA

  • The neutral bar is border-neutral-primary: DGA draws it white, which is invisible on the white card. The bar is logical (the start side).
  • DGA specifies no timing or announcement. Toasts pause while hovered or focused, can be swiped away, are announced, and the Toaster sits on the bottom end of the screen.
ChangeReason
Toast: neutral bar, timing and live regionA message that disappears must be announced and must not vanish while someone is reading it (WCAG 4.1.3, 2.2.1).

View all 1 deviations for this component

Contrast

24 pairs checked · all pass WCAG 2.1 AAShow 12 states
Variant / stateLightDark
title14.53:1 AAA14.42:1 AAA
description10.17:1 AAA10.95:1 AAA
icon / neutral18.09:1 3:114.42:1 3:1
icon / info5.98:1 3:18.98:1 3:1
icon / success5.69:1 3:19.82:1 3:1
icon / warning5.42:1 3:110.27:1 3:1
icon / error6.57:1 3:18.18:1 3:1
action text16.44:1 AAA12.71:1 AAA
action text, hovered14.61:1 AAA6.95:1 AA
close icon18.09:1 3:114.42:1 3:1
close icon, hovered16.44:1 3:19.59:1 3:1
focus ring18.09:1 3:115.89:1 3:1

Text needs 4.5:1, icons and focus rings 3:1. Disabled states are exempt. Full contrast report