structyl

The full prop reference for the Toast component. A succinct message that is displayed temporarily.

Import

tsx
import { Toast } from '@structyl/styled';

Props

Provider

Toast context provider — wraps your app to enable toast functionality

PropTypeDefault
children#React.ReactNode

The app content that can access toast context

label#string

Aria label for the toast region

'Notifications'
duration#number

Time in ms to auto-dismiss toasts; set to Infinity to disable

5000
swipeDirection#'up' | 'down' | 'left' | 'right'

Direction users can swipe to dismiss toasts

'right'
swipeThreshold#number

Distance in px to consider a swipe a dismissal

50

Viewport

Container that holds and positions all toasts; automatically styled in the styled layer

PropTypeDefault
asChild#boolean

Render as child element instead of creating wrapper

hotkey#string[]

Keyboard keys to focus the toast viewport

['F8']
label#string

Aria label for the toast list

'{hotkey} hotkey to focus toasts'
className#string

Additional CSS classes (styled layer provides sensible defaults)

...rest#React.ComponentPropsWithoutRef<'ol'>

All native ol HTML attributes (style, role, aria-*, etc.)

Root

Individual toast component — represents a single toast notification

PropTypeDefault
type#'foreground' | 'background'

Aria-live priority: foreground=assertive, background=polite

'foreground'
open#boolean

Controlled: whether the toast is visible

defaultOpen#boolean

Uncontrolled: initial visibility state

true
onOpenChange#(open: boolean) => void

Fired when toast visibility changes

duration#number

Overrides Provider duration for this toast; Infinity to keep open

forceMount#boolean

Always render in DOM (even when closed) for animation control

onEscapeKeyDown#(event: KeyboardEvent) => void

Fired when Escape key is pressed on focused toast

onPause#() => void

Fired when toast auto-dismiss timer pauses (hover/focus)

onResume#() => void

Fired when toast auto-dismiss timer resumes

onSwipeStart#(event: React.PointerEvent) => void

Fired when swipe gesture begins

onSwipeMove#(event: React.PointerEvent) => void

Fired continuously while swiping

onSwipeEnd#(event: React.PointerEvent) => void

Fired when swipe distance exceeds threshold and toast closes

onSwipeCancel#(event: React.PointerEvent) => void

Fired when swipe is released but below threshold

variant#'default' | 'destructive' | 'error' | 'success' | 'warning' | 'info'

Visual style variant (styled layer only)

'default'
className#string

Additional CSS classes (merges with variant styles)

...rest#React.ComponentPropsWithoutRef<'li'>

All native li HTML attributes (role, data-*, etc.)

Title

Toast title text — renders inside Toast.Root

PropTypeDefault
asChild#boolean

Render as child element instead of creating wrapper

className#string

Additional CSS classes (styled layer provides typography defaults)

children#React.ReactNode

Title text or content

...rest#React.ComponentPropsWithoutRef<'div'>

All native div HTML attributes

Description

Toast description text — renders inside Toast.Root

PropTypeDefault
asChild#boolean

Render as child element instead of creating wrapper

className#string

Additional CSS classes (styled layer provides typography defaults)

children#React.ReactNode

Description text or content

...rest#React.ComponentPropsWithoutRef<'div'>

All native div HTML attributes

Action

Action button in the toast — automatically closes toast on click

PropTypeDefault
altText#string

Required alt text for screen readers (hidden visually)

asChild#boolean

Render as child element instead of creating button

className#string

Additional CSS classes (styled layer provides button styles)

children#React.ReactNode

Button label or content

...rest#React.ComponentPropsWithoutRef<'button'>

All native button HTML attributes (onClick, disabled, etc.)

Close

Close/dismiss button in the toast — automatically closes toast on click

PropTypeDefault
asChild#boolean

Render as child element instead of creating button

className#string

Additional CSS classes (styled layer provides default icon and styles)

children#React.ReactNode

Button content (styled layer provides X icon by default)

...rest#React.ComponentPropsWithoutRef<'button'>

All native button HTML attributes (onClick, disabled, etc.)

Portal

Portal helper — renders toast content into a specific DOM container

PropTypeDefault
children#React.ReactNode

Content to portal

container#Element | DocumentFragment | null

Target DOM node; defaults to document.body

Toaster

Singleton component — renders all imperative toasts. Drop once in your app root (e.g. layout.tsx)

PropTypeDefault
horizontal#'left' | 'center' | 'right'

Default horizontal alignment for all toasts

'right'
vertical#'top' | 'bottom'

Default vertical alignment for all toasts

'bottom'
maxToasts#number

Maximum number of toasts visible at once per position group

5
className#string

Additional CSS classes forwarded to viewport wrappers

...rest#React.ComponentPropsWithoutRef<typeof Viewport>

Viewport props (hotkey, label, style, aria-*, etc.)

toast.show()

Imperative API — fire a toast with full control over all options

PropTypeDefault
options.id#string

Reuse/update existing toast when same ID is fired again

options.title#string

Main toast text

options.description#string

Secondary toast text

options.variant#'default' | 'success' | 'error' | 'warning' | 'info' | 'loading'

Visual style and icon

'default'
options.duration#number

Auto-dismiss in ms; pass Infinity to keep until manually dismissed

4000
options.horizontal#'left' | 'center' | 'right'

Horizontal position (overrides Toaster default)

options.vertical#'top' | 'bottom'

Vertical position (overrides Toaster default)

options.action#{ label: string; onClick: () => void }

Custom action button; takes priority over retry if both provided

options.retry#() => void

Adds a Retry button (action takes priority for button label)

options.onDismiss#(id: string) => void

Callback fired when toast is dismissed (before animation)

toast.success()

Convenience method — fire a success toast

PropTypeDefault
title#string

Main toast text

options#Omit<ToastOptions, 'title' | 'variant'>

Same as toast.show() except title and variant are preset

toast.error()

Convenience method — fire an error toast

PropTypeDefault
title#string

Main toast text

options#Omit<ToastOptions, 'title' | 'variant'>

Same as toast.show() except title and variant are preset

toast.warning()

Convenience method — fire a warning toast

PropTypeDefault
title#string

Main toast text

options#Omit<ToastOptions, 'title' | 'variant'>

Same as toast.show() except title and variant are preset

toast.info()

Convenience method — fire an info toast

PropTypeDefault
title#string

Main toast text

options#Omit<ToastOptions, 'title' | 'variant'>

Same as toast.show() except title and variant are preset

toast.loading()

Convenience method — fire a loading toast (spinner icon, duration defaults to Infinity)

PropTypeDefault
title#string

Main toast text

options#Omit<ToastOptions, 'title' | 'variant'>

Same as toast.show() except title and variant are preset; duration defaults to Infinity

toast.promise()

Async helper — show loading toast, then update to success or error when promise settles

PropTypeDefault
promise#Promise<T>

The promise to track

messages.loading#string

Text while promise is pending

messages.success#string | ((data: T) => string)

Text when promise resolves; can be a function to format the resolved value

messages.error#string | ((err: unknown) => string)

Text when promise rejects; can be a function to format the error

options#Omit<ToastOptions, 'title' | 'variant'>

Same as toast.show() except title and variant are managed by promise state

toast.dismiss()

Close a toast with exit animation; omit id to dismiss all

PropTypeDefault
id#string

Toast ID to close; omit to dismiss all open toasts

toast.remove()

Instantly remove a toast from the store without animation

PropTypeDefault
id#string

Toast ID to remove

useToast()

Hook to subscribe to the toast store inside a React component

PropTypeDefault
return.toasts#ToastItem[]

Array of current toast items in the store

return.toast#typeof toast

The complete toast imperative API (show, success, error, etc.)

return.dismiss#(id?: string) => void

Close toast(s) with animation

return.remove#(id: string) => void

Instantly remove a toast

Keyboard interactions

KeyDescription
F8Jumps focus into the toast viewport.
TabMoves focus through the toast.
EscCloses the focused toast.

Source code

If you didn't find what you need here, read the component implementation .

structyl — Accessible React Component Library