Components

Toast

Toast provider, store, live announcements, viewport, and dismissible toast parts.

When to Use

Use Toast for a short update that does not block the current task, such as “Saved” or “Upload failed.” Use inline feedback when the message belongs beside a field, and use AlertDialog when the user must respond before continuing. Never put essential information only in a toast because it disappears.

Features

  • Supports declarative and imperative toast rendering.
  • Includes a global toast store and toast.* helpers.
  • Supports queueing with a maximum visible count.
  • Announces toast titles/descriptions through persistent live regions.
  • Supports hover/focus-loss pause behavior.
  • Supports custom viewport rendering.
  • Supports asChild and render on visual parts.

Import

import { Toast, toast } from "@flowstack-ui/atom";

Anatomy

<Toast.Provider>
  <Toast.Root>
    <Toast.Title />
    <Toast.Description />
    <Toast.Action />
    <Toast.Cancel />
    <Toast.Close />
  </Toast.Root>

  <Toast.Viewport />
</Toast.Provider>

API Reference

Provider

Shares queue, pause, expansion, and close-button defaults with declarative and imperative toasts. Provider renders only its children.

PropTypeDefault
maxVisiblenumber3
expandOnHoverbooleantrue
closeButtonbooleantrue
pauseOnHoverbooleantrue
pauseOnFocusLossbooleantrue

ARIA: Provider renders no element and adds no ARIA attributes.

Data attributes: Provider renders no element and exposes none.

Root

Owns one toast's lifecycle, timer, pause state, dismissal callbacks, and live announcement priority.

PropTypeDefault
asChildbooleanfalse
renderRenderProp-
toastToastData-
type"default" | "success" | "error" | "warning" | "info" | "loading""default"
durationnumberType default
pausedbooleanfalse
dismissiblebooleantrue
closeButtonbooleanProvider value
indexnumber-
expandedboolean-
removeDelaynumber200
forceMountbooleanfalse
onAutoClose() => void-
onDismiss() => void-
ARIA attributeValues
role"status" normally; "alert" for warning and error
aria-live"polite" normally; "assertive" for warning and error
aria-atomicAlways true
Data attributeValues
[data-slot]"toast"
[data-state]"entering" | "visible" | "exiting"
[data-type]Toast type
[data-index]Visible stack index
[data-expanded]Present when expanded

Title

Provides the concise heading announced as part of the current Root.

PropTypeDefault
asChildbooleanfalse
renderRenderProp-

ARIA: Title adds no role or ARIA attributes; Root's live region announces it.

Data attributeValues
[data-slot]"toast-title"

Description

Provides supporting message text announced with Title inside the current Root.

PropTypeDefault
asChildbooleanfalse
renderRenderProp-

ARIA: Description adds no role or ARIA attributes; Root announces it.

Data attributeValues
[data-slot]"toast-description"

Action

Action button. Clicking it dismisses the toast after the action runs.

PropTypeDefault
asChildbooleanfalse
renderRenderProp-
altTextstring-
ARIA attributeValues
aria-labelValue from altText when provided
Data attributeValues
[data-slot]"toast-action"

Cancel

Cancel button. Clicking it dismisses the toast after the cancel action runs.

PropTypeDefault
asChildbooleanfalse
renderRenderProp-
altTextstring-
ARIA attributeValues
aria-labelValue from altText when provided
Data attributeValues
[data-slot]"toast-cancel"

Close

Dismiss button.

PropTypeDefault
asChildbooleanfalse
renderRenderProp-
aria-labelstring"Dismiss notification"
ARIA attributeValues
aria-labelExplicit value or "Dismiss notification"
Data attributeValues
[data-slot]"toast-close"

Viewport

Portaled viewport that renders visible queued toasts. When asChild is used, the child element becomes the viewport and queued toasts still render inside that child.

PropTypeDefault
asChildbooleanfalse
renderRenderProp-
position"top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right""bottom-right"
containerHTMLElement | nulldocument.body after mount
portalDisabledbooleanfalse
renderToast(state: ToastViewportRenderState) => ReactNode-
ARIA attributeValues
aria-liveHidden announcers use "polite" and "assertive"
aria-atomicHidden announcers use true
Data attributeValues
[data-slot]"toast-viewport"
[data-position]Toast position
[data-expanded]Present when expanded
[data-slot="toast-announcer-polite"]Polite live region
[data-slot="toast-announcer-assertive"]Assertive live region

The flat API also exports the toast helper, store mutation/subscription functions, useToastStore, role/duration helpers, provider defaults, and the Provider/Root context hooks and providers for advanced integrations.

Examples

Imperative toast

import { Toast, toast } from "@flowstack-ui/atom";

export default function SaveToast() {
  return (
    <Toast.Provider>
      <button type="button" onClick={() => toast.success("Saved")}>Save</button>
      <Toast.Viewport />
    </Toast.Provider>
  );
}

Declarative toast

import { Toast } from "@flowstack-ui/atom";

export default function DeclarativeToast() {
  return (
    <Toast.Provider>
      <Toast.Root type="success">
        <Toast.Title>Saved</Toast.Title>
        <Toast.Description>Your changes were saved.</Toast.Description>
        <Toast.Close />
      </Toast.Root>
    </Toast.Provider>
  );
}

Custom viewport rendering

import { Toast } from "@flowstack-ui/atom";

export default function CustomToastViewport() {
  return (
    <Toast.Provider>
      <Toast.Viewport
        renderToast={({ toast: toastData, index, expanded }) => (
          <Toast.Root toast={toastData} index={index} expanded={expanded}>
            <Toast.Title />
            <Toast.Description />
            <Toast.Close />
          </Toast.Root>
        )}
      />
    </Toast.Provider>
  );
}

Accessibility

Toast uses WAI-ARIA live-region semantics: Root uses role="status" with polite announcements for ordinary messages and role="alert"/assertive announcements for warning and error messages. The viewport also maintains persistent hidden live regions so newly added toasts are announced reliably.

Actions and cancel controls dismiss the toast after their callbacks run. Use separate UI when an action must keep a toast open while async work completes.

Changelog

See CHANGELOG.md.