Skip to content

Sonner

The Sonner toaster themed by next-themes, with Keyline icons.

Mount one Toaster at the root of the app and call toast from sonner anywhere. Toaster reads the theme from useTheme of next-themes, so it follows a theme switch only inside that library's ThemeProvider; without one it follows the system setting.

Kinds of toast

Installation

npx shadcn@latest add @khaeli/sonner

Install @khaeli/foundation first: this item's styling lives in its tokens and [data-slot] rules.

Installs with

npm packages
  • @keyline-icons/react ^2.2.0
  • next-themes ^0.4.6
  • sonner ^2.0.8

Keyboard

Alt T
Moves focus to the list of toasts and spreads the stack out. Toasts stay while focus is in the list.
TabShift Tab
Move through the toasts and their action buttons.
EnterSpace
On an action button, run the action and close its toast.
Escape
With focus in the list, folds the stack again and lets the toasts close.

Accessible name

  • The toasts live in a region named Notifications that is aria-live="polite": a new toast is announced without moving focus.
  • The kind of a toast is shown by its icon alone. The icon has no text and the toast has no role, so say in the words whether it worked.
  • An action button is named by its label: a verb such as Undo.
  • A toast closes by itself after about four seconds and has no close button unless you pass closeButton, so never put the only copy of something in one.

Registry JSON

The item as the shadcn CLI reads it, with every file it ships: https://ui.khaeli.com/r/sonner.json