Components
Back to catalog
Component detail entry
Feedback
@vean/ui
SToast

Toast

Toast belongs to the Feedback category. Start with demos and usage, then use the API tables to finish integration and styling decisions.

Use the quick jump panel to reach overview, usage, demos, and API first, then continue through the full page.

Quick jump

Related components

If you are composing interactions in the same family, these components usually pair well together.

Toast

Overview

Transient notifications that appear in a viewport and auto-dismiss. SToastProvider renders the toast viewports and the toast imperative API creates, updates, dismisses, and inspects notifications. It supports six types, six positions, stacking/expansion, swipe-to-dismiss, promise toasts, rich color and inverted themes, and a keyboard hotkey to focus the list.

Use it for global, non-blocking feedback (saved, errors, upload progress). Prefer alert for inline callouts near content, and dialog for blocking confirmations that need a decision.

Usage

Mount one SToastProvider near your app root. If your app is already wrapped with SConfigProvider, a default SToastProvider is rendered automatically unless customToast is set to true.

Features

  • ⚡ Imperative API — toast() plus toast.success/error/warning/info/loading/custom/message/promise/dismiss
  • 🎨 6 types — default/success/info/warning/error/loading with default icons
  • 📍 6 positions — top-left/top-right/top-center/bottom-left/bottom-right/bottom-center
  • 🗂️ Stacking — visibleCounts limits visible toasts per position; hover expands the stack (defaultExpanded)
  • 👆 Swipe to dismiss — drag left/right/up/down (configurable swipeDirections) to remove
  • ⏱️ Auto-dismiss — duration per toast/provider; 0 or Infinity disables; pauses on hover and hidden-tab
  • 🔮 Promise toasts — toast.promise(promise, { loading, success, error }) with HTTP/Error handling
  • 🎛️ Actions — action/cancel buttons with callbacks; custom for fully custom content
  • ♿ Accessible — aria-live="polite" region, focus management with focus return, and a hotkey (default Alt+T) to focus the list

Component family

  • SToastProvider (styled) — the entry provider; injects toastVariants and the animation stylesheet
  • ToastProvider (Aria) — thin wrapper over Toaster
  • Toaster (Aria) — the state owner; subscribes to ToastState, manages stack/expand/focus, renders the 6 viewports
  • Toast (Aria) — a single toast; auto-close timer, swipe logic, height measurement, action/cancel/close
  • toast (imperative) — the shared toast controller (ToastState observer) exposed on @vean/ui

Demos

Basic

Promise

Action

Control

Appearance

Stack

API

Aria Layer

2

Toaster

25 Props
Props
PropTypeDefaultDescription
id
string
—
Id.
dir
Direction
—
Reading direction of the component.
hotkey
string[]
—
Hotkey.
customAriaLabel
string
—
Custom aria label.
containerAriaLabel
string
—
Container aria label.
position
ToastPosition
—
Position.
defaultExpanded
boolean
—
Whether default expanded.
duration
number
—
The duration (in milliseconds) before the toast automatically closes. Set to `0` or `Infinity` to disable auto-dismissal.
gap
number
—
Gap.
offset
ToastOffset
3
The maximum number of visible toasts per position.
visibleCounts
number
—
Visible counts.
swipeDirections
SwipeDirection[]
—
Swipe directions.
showIcon
boolean
—
Whether to show an icon.
showClose
boolean
true
Whether toasts show a close button by default. A toast-level `showClose` takes precedence over this default.
icons
Partial<Record<ToastIconType, IconValue>>
—
Icons.
toastProps
LiHTMLAttributes
—
Properties forwarded to the toast element.
wrapperProps
HTMLAttributes
—
Properties forwarded to the wrapper element.
contentProps
HTMLAttributes
—
Properties forwarded to the content element.
titleProps
HTMLAttributes
—
Properties forwarded to the title element.
descriptionProps
HTMLAttributes
—
Properties forwarded to the description element.
iconProps
HTMLAttributes
—
Properties forwarded to the icon component.
footerProps
HTMLAttributes
—
Properties forwarded to the footer element.
actionProps
HTMLAttributes
—
Properties forwarded to the action element.
cancelProps
HTMLAttributes
—
Properties forwarded to the cancel element.
closeProps
HTMLAttributes
—
Properties forwarded to the close element.

ToastProvider

27 Props
Props
PropTypeDefaultDescription
size
ThemeSize
—
Visual size of the component.
ui
ToastUi
—
Per-slot class overrides for the component.
id
string
—
Id.
dir
Direction
—
Reading direction of the component.
hotkey
string[]
—
Hotkey.
customAriaLabel
string
—
Custom aria label.
containerAriaLabel
string
—
Container aria label.
position
ToastPosition
—
Position.
defaultExpanded
boolean
—
Whether default expanded.
duration
number
—
The duration (in milliseconds) before the toast automatically closes. Set to `0` or `Infinity` to disable auto-dismissal.
gap
number
—
Gap.
offset
ToastOffset
3
The maximum number of visible toasts per position.
visibleCounts
number
—
Visible counts.
swipeDirections
SwipeDirection[]
—
Swipe directions.
showIcon
boolean
—
Whether to show an icon.
showClose
boolean
true
Whether toasts show a close button by default. A toast-level `showClose` takes precedence over this default.
icons
Partial<Record<ToastIconType, IconValue>>
—
Icons.
toastProps
LiHTMLAttributes
—
Properties forwarded to the toast element.
wrapperProps
HTMLAttributes
—
Properties forwarded to the wrapper element.
contentProps
HTMLAttributes
—
Properties forwarded to the content element.
titleProps
HTMLAttributes
—
Properties forwarded to the title element.
descriptionProps
HTMLAttributes
—
Properties forwarded to the description element.
iconProps
HTMLAttributes
—
Properties forwarded to the icon component.
footerProps
HTMLAttributes
—
Properties forwarded to the footer element.
actionProps
HTMLAttributes
—
Properties forwarded to the action element.
cancelProps
HTMLAttributes
—
Properties forwarded to the cancel element.
closeProps
HTMLAttributes
—
Properties forwarded to the close element.

Imperative toast methods

MethodDescription
toast(message, data?)Show a default toast; returns the toast id.
toast.success/error/warning/info/loading(message, data?)Show a typed toast.
toast.custom(component, data?)Show a fully custom VNode.
toast.promise(promise, { loading, success, error, description, finally })Bind a promise lifecycle to a toast.
toast.dismiss(id?)Dismiss one toast, or all toasts when no id is given.
toast.getHistory()Read all created toasts.
toast.getToasts()Read the currently active (non-dismissed) toasts.

Common data options: description, position, duration, action/cancel (+ onAction/onCancel), icon, richColor, inverted, showClose, dismissible, toasterId, id, ui.

Notes

Architecture and benchmark differences

Toaster is a self-contained state owner that subscribes to a module-level ToastState observer and drives stacking/expansion, swipe, focus management and the auto-close timers, while SToastProvider only injects the recipe classes and the animation stylesheet. This is an imperative-first model like Ant Design’s message/notification, Element Plus ElMessage, Mantine notifications and Naive UI useMessage — unlike shadcn/ui which has no global toast primitive. VeanUI distinguishes itself with stacked/expandable toasts, swipe-to-dismiss, promise toasts, and a focus hotkey, matching the ergonomics of Sonner while keeping an Aria/styled split.

CapabilityVeanUIshadcn/uiAnt Design messageElement Plus ElMessageMantine notificationsNaive UI useMessage
Imperative API✅—✅✅✅✅
Types (success/error/…)✅—✅✅✅✅
Positions (6)✅—✅✅✅✅
Stack / expand✅———✅—
Swipe to dismiss✅—————
Promise toasts✅—✅—✅✅
Rich color / inverted✅—✅———
Pause on hover / hidden tab✅—✅✅✅✅
Focus hotkey✅—————

— = unsupported or a different interaction model.

Cautions

  • A mounted SToastProvider is required to render toasts; SConfigProvider mounts one automatically (unless customToast).
  • duration of 0 or Infinity disables auto-dismiss; the timer pauses while the toast is hovered, expanded, or the tab is hidden.
  • visibleCounts (default 3) limits visible toasts per position; older toasts stack behind and expand on hover when defaultExpanded.
  • Toasts are swipe-dismissible by default; set dismissible: false to disable (e.g. for loading).
  • The viewport region is aria-live="polite"; the default hotkey Alt+T focuses the toast list. Override hotkey/containerAriaLabel as needed.

Roadmap

No blocking gaps identified for the core toast API.

FAQ

How do I show a basic toast?

import { toast } from '@vean/ui';

toast('Changes saved');

How do I show a typed toast?

toast.success('All good');
toast.error('Something went wrong');
toast.loading('Uploading…');

How do I show a promise toast?

toast.promise(fetchData(), {
  loading: 'Loading…',
  success: data => `Loaded ${data.length} items`,
  error: 'Failed to load'
});

How do I change the position or duration?

Pass data options to the call (or set provider defaults):

toast('Bottom left', { position: 'bottom-left', duration: 5000 });

How do I keep a toast from auto-dismissing?

Set duration: Infinity:

toast('Stays until dismissed', { duration: Infinity });

How do I render custom content?

Use toast.custom with a VNode, or the custom option:

toast.custom(h(VNode));

Changelog

Version history is grouped by release so you can quickly see what changed for this component across published versions.

v0.50.0

2026-10-02

Compare release

Style

honor per-toast showClose and tint close hover for rich colors

Scope: toastAuthors: soybeanjsView commit69fae

Style

honor per-toast showClose and tint close hover for rich colors

Scope: toastAuthors: soybeanjsView commit69fae

v0.40.0

2026-09-14

Compare release

Fix

constrain top-position translateY to pre-mount state

Scope: toastAuthors: soybeanfeView commitbd52d

Fix

constrain top-position translateY to pre-mount state

Scope: toastAuthors: soybeanfeView commitbd52d

v0.31.0

2026-08-31

Compare release

Refactor

widen toaster list ref element type

Scope: toastAuthors: soybeanfeView commit32a2e

v0.15.1

2026-04-27

Compare release

Feature

add ToastProvider component and refactor Toaster integration

Scope: toastAuthors: soybeanjs, CopilotView commite2491

v0.15.0

2026-04-26

Compare release

Optimization

optimize toast api and icon,button render

Scope: toastAuthors: soybeanjs, soybean-jsView commit080c2

Docs

update toast component documentation for clarity and usage examples

Scope: toastAuthors: soybeanjsView commit9e4f4

Chore

update mount reference from Toaster to SToaster in tests

Scope: toastAuthors: soybeanjsView commitacbd4

Optimization

optimize toast api and icon,button render

Scope: toastAuthors: soybeanjs, soybean-jsView commit080c2

Docs

update toast component documentation for clarity and usage examples

Scope: toastAuthors: soybeanjsView commit9e4f4

Chore

update mount reference from Toaster to SToaster in tests

Scope: toastAuthors: soybeanjsView commitacbd4

v0.14.0

2026-04-03

Compare release

Fix

add feature attribute to VisuallyHidden component

Scope: toastAuthors: soybeanjsView commit4dc6d

Fix

remove unnecessary aria attributes from VisuallyHidden and ToastAnnounce components

Scope: toastAuthors: soybeanjsView commit044dc

v0.8.0

2026-02-10

Compare release

Feature

add disableSwipe prop to control swipe-to-close functionality

Scope: toastAuthors: soybeanjsView commit32d53

v0.0.2

2025-11-18

Compare release

Feature

introduce Toast component with context management and swipe functionality

Scope: toastAuthors: soybeanjsView commit54299

Feature

enhance Toast component with viewport context, new props, and demo examples

Scope: toastAuthors: soybeanjsView commitaf068

Feature

introduce Toast component with context management and swipe functionality

Scope: toastAuthors: soybeanjsView commit54299

Feature

enhance Toast component with viewport context, new props, and demo examples

Scope: toastAuthors: soybeanjsView commitaf068