Reference

Toast API

The toast API is a small imperative dispatcher with a single declarative renderer, Toaster.

View as Markdown

The toast package exposes one imperative dispatcher and one portal renderer. The full contract is typed and works with styled or unstyled surfaces.

Methods

MethodResult
toast(message, options)Neutral toast id
toast.success/error/info/warning/message/loadingTyped toast id
toast.custom(content, options)Custom React content
toast.update(id, patchOrUpdater)Updates one toast
toast.dismiss(id?, reason?)Dismisses one or all
toast.promise(task, phases)Returns the original promise
tsx
const id = toast.loading("Uploading");

try {
  const file = await upload();
  toast.update(id, {
    type: "success",
    message: "Uploaded",
    description: file.name,
  });
} catch {
  toast.update(id, { type: "error", message: "Upload failed" });
}

ToastOptions

OptionTypeNotes
idstring or numberReusing an id updates one toast
typedefault, success, error, info, warning, loadingPrefer typed methods
descriptionReactNodeSecondary guidance
iconReactNodeReplaces the type icon
announcementstringExplicit screen-reader text
durationnumberLoading is persistent until updated or dismissed
dismissiblebooleanControls swipe, Escape, and close affordance
importantbooleanUses the assertive live region
action, cancel{ label, onClick }Return false from action to keep it open
closeButtonbooleanPer-toast override
closeButtonAriaLabelstringAccessible close label
className, descriptionClassName, classNamesstrings or mapFine-grained styling
styleCSSPropertiesPer-toast custom properties
unstyledbooleanRetains behavior and structural a11y only
onDismisscallbackIncludes dismissal reason
onAutoClosecallbackFires only for timeout closure

Toaster props

PropTypeDefault
positionviewport positionbottom-right
durationmilliseconds4000
gappixels14
stackbooleantrue
expandbooleanfalse
visibleToastsnumber3
closeButtonbooleantrue
richColorsbooleanfalse
swipeDirectionsdirection arraynearest viewport edge
hotkeykey descriptor array or null["altKey", "KeyT"]
pauseWhenPageIsHiddenbooleantrue
dirltr | rtl | autoauto
offsetnumber or CSS length24
containerAriaLabelstringNotifications
iconsicon mapbuilt-in glyphs
toastOptionsToastOptions{}
className, classNames, stylestyling hooks
unstyledbooleanfalse

Positions and swipe directions

Positions support top/bottom plus left/center/right, and logical start/end variants. Swipe directions support top, right, bottom, left, start, and end.

When swipeDirections is omitted, Velvet chooses the nearest viewport edge. Logical directions resolve from dir.

Promise phases

tsx
await toast.promise(() => saveDocument(), {
  loading: { message: "Saving", description: "Keeping this tab open" },
  success: (document) => ({
    message: "Saved",
    description: document.updatedAt,
  }),
  error: (error) => ({
    message: "Could not save",
    description: error.message,
  }),
  finally: () => releaseDraftLock(),
});

Each phase may be a ReactNode, an object, or a function. The promise returned by toast.promise keeps its original value and rejection behavior.

Accessibility behavior

Ordinary updates use a polite live region. Errors and important updates use an assertive region. Alt+T focuses the front toast by default; Escape dismisses the focused or front toast.

Actions are real buttons. After keyboard dismissal, focus moves to the next toast or returns to the element focused before the toast stack.

Dismiss reasons

programmatic, timeout, swipe, action, cancel, close-button, and escape are built in. Custom strings remain accepted for application-level analytics.