Skip to main content

Toast

A toast is a non-modal notification that appears temporarily to provide feedback or information to the user. Toasts can be dismissed manually or automatically after a timeout.

Import

Basic Usage

Sub-components

Provider

Provides toast context to the viewport and toast components. Key Props:
  • manager (ToastManager): The toast manager instance

Viewport

The container where toasts are rendered. Key Props:
  • limit (number): Maximum number of visible toasts (default: 3)
  • offset (number): Offset in pixels between stacked toasts (default: 16)
  • hotkey (string[]): Keyboard shortcut to focus toasts (default: ['F8'])

Root

Groups all parts of an individual toast. Renders a <div> element. Key Props:
  • toast (ToastObject): The toast object to render
  • swipeDirection (‘up’ | ‘down’ | ‘left’ | ‘right’ | Array): Direction(s) to swipe to dismiss (default: ['down', 'right'])

Title

The title of the toast.

Description

The description/message of the toast.

Close

A button that closes the toast.

Action

An action button within the toast.

Content

The main content container of the toast.

Portal

Portals the toast to a different part of the DOM.

Positioner

Positions the toast using Floating UI.

Arrow

An optional arrow for positioned toasts.

Toast Manager

createToastManager()

Creates a toast manager instance.

useToastManager(manager)

A React hook that subscribes to toast updates.

Toast Manager Methods

  • show(options): Shows a new toast
  • close(id): Closes a specific toast
  • closeAll(): Closes all toasts
  • update(id, options): Updates a toast’s content

Styling Example

Key Features

  • Swipe to dismiss in configurable directions
  • Automatic stacking with configurable limits
  • High-priority toasts with alertdialog role
  • Pause on hover or focus
  • Keyboard navigation with hotkey support
  • CSS variables for dynamic positioning (--toast-index, --toast-offset-y, --toast-height)
  • Touch-friendly swipe gestures

Accessibility

  • Uses role="dialog" for normal toasts and role="alertdialog" for high-priority toasts
  • Title and description are automatically linked via aria-labelledby and aria-describedby
  • Keyboard accessible with configurable hotkey
  • Respects prefers-reduced-motion
  • Timers pause when toasts receive focus
  • High-priority toasts are marked with aria-hidden when not focused