Skip to content

Toast

Toast

A notification: status icon, visually hidden severity text, title, body, footer and a Dismiss button. Its parts are direct children: Toast.Title (the title row, with an optional action), Toast.Body (with an optional subtitle) and Toast.Footer (a row of actions); a Toast.Close anywhere inside makes its child dismiss the toast. The title prop and plain children are the 0.5 form and render as a Title and a Body.

Dispatch it with useToastController().dispatchToast(<Toast>โ€ฆ</Toast>), or render it yourself.

- **In a Toaster**: not a live region itself; the Toaster announces it once per dispatch through its permanent live regions (its severity text, then its title, body and the labels of its actions, never the Dismiss button, or, after the severity text, the dispatch's announcement), politely or, for error, assertively, and names its container by the severity text and title. Every Toast there shows the Dismiss button.
- **On its own** (your own container, an inline notice): a live region, as in 0.4 โ€” role="status" with aria-live="polite", or role="alert" with aria-live="assertive" for error (override with role/aria-live). A live region that is added together with its text is not announced by every screen reader, so render the Toast in advance and change its content, or dispatch it through a Toaster.

Sub-components are also exported under flat names (ToastTitle, ToastBody, ToastFooter, ToastClose): React Server Components import those, because dotted access (Toast.Title) needs a client file.

Examples

Default

Info:
Notification
This is an informational message.
export const Default: Story = {};

Success

Success:
Success
Operation completed successfully.
export const Success: Story = {
  args: {
    title: 'Success',
    status: 'success',
    children: 'Operation completed successfully.',
  },
};

Warning

Warning:
Warning
Please review the details.
export const Warning: Story = {
  args: {
    title: 'Warning',
    status: 'warning',
    children: 'Please review the details.',
  },
};

Error

export const Error: Story = {
  args: {
    title: 'Error',
    status: 'error',
    children: 'Something went wrong.',
  },
};

With Dismiss

Info:
Dismissible
Click the X to dismiss.
export const WithDismiss: Story = {
  args: {
    title: 'Dismissible',
    children: 'Click the X to dismiss.',
    onDismiss: fn(),
  },
  render: (args) => <DismissibleToast {...args} />,
};

Toaster Example

export const ToasterExample: Story = {
  args: {
    title: 'Saved',
    status: 'success',
    children: 'Your changes were saved.',
  },
  render: (args) => (
    <Toaster>
      <ToasterDemo {...args} />
    </Toaster>
  ),
};

Toaster Top Start

export const ToasterTopStart: Story = {
  args: {
    title: 'Heads up',
    status: 'warning',
    children: 'Toasts appear at the top start corner.',
  },
  render: (args) => (
    <Toaster position="top-start">
      <ToasterDemo {...args} />
    </Toaster>
  ),
};

Limit

export const Limit: Story = {
  args: {
    title: 'File uploaded',
    status: 'success',
    children: 'The file is ready to share.',
  },
  render: (args) => (
    <Toaster limit={3}>
      <BurstDemo {...args} />
    </Toaster>
  ),
};

Dismiss All

export const DismissAll: Story = {
  args: {
    title: 'Sync conflict',
    status: 'warning',
    children: 'Review the changed files.',
  },
  render: (args) => (
    <Toaster>
      <DismissAllDemo {...args} />
    </Toaster>
  ),
};

Motion

export const Motion: Story = {
  args: {
    title: 'Comment added',
    status: 'info',
    children: 'Kat replied to your comment.',
  },
  render: function MotionToaster(args) {
    const cases = motionCases(fadeAndCollapse);
    const [label, setLabel] = React.useState(cases[0].label);
    const { motion } = cases.find((option) => option.label === label) ?? cases[0];
    return (
      <div className="flex flex-col gap-4">
        <RadioGroup
          aria-label="Toast motion"
          orientation="horizontal"
          value={label}
          onValueChange={setLabel}
        >
          {cases.map((option) => (
            <RadioItem key={option.label} value={option.label} label={option.label} />
          ))}
        </RadioGroup>
        <Toaster motion={motion}>
          <DismissAllDemo {...args} />
        </Toaster>
      </div>
    );
  },
};

Toaster Beside Drawer

export const ToasterBesideDrawer: Story = {
  args: {
    title: 'Filters saved',
    status: 'success',
    children: 'Dismiss this toast with its button.',
  },
  render: (args) => (
    <Toaster>
      <DrawerWithToasts {...args} />
    </Toaster>
  ),
};

Parts

export const Parts: Story = {
  args: {
    status: 'success',
    title: 'Backup complete',
    children: 'All 128 files were copied to the archive.',
  },
  render: (args) => (
    <Toaster>
      <PartsDemo {...args} />
    </Toaster>
  ),
};

Title Action

Info:
Message deleted
export const TitleAction: Story = {
  args: { status: 'info', title: 'Message deleted', onDismiss: fn() },
  render: ({ title, ...args }) => (
    <DismissibleToast {...args}>
      <Toast.Title
        action={
          <Toast.Close>
            <Button size="small" appearance="subtle">
              Undo
            </Button>
          </Toast.Close>
        }
      >
        {title}
      </Toast.Title>
    </DismissibleToast>
  ),
};

Custom Icon

Info:
Reminder
Stand-up starts in 5 minutes.
export const CustomIcon: Story = {
  args: { status: 'info', title: 'Reminder', children: 'Stand-up starts in 5 minutes.' },
  render: (args) => <Toast {...args} icon={<BellIcon />} />,
};

Standalone

Warning:
Storage almost full
You have used 95% of your storage.
export const Standalone: Story = {
  args: {
    status: 'warning',
    title: 'Storage almost full',
    children: 'You have used 95% of your storage.',
    onDismiss: fn(),
  },
  render: ({ title, children, ...args }) => (
    <DismissibleToast {...args}>
      <Toast.Title>{title}</Toast.Title>
      <Toast.Body>{children}</Toast.Body>
      <Toast.Footer>
        <Button size="small">Manage storage</Button>
      </Toast.Footer>
    </DismissibleToast>
  ),
};

Rich Content

Undone 0 times.

export const RichContent: Story = {
  args: { status: 'success', title: 'Email sent', children: 'Your message was delivered.' },
  render: (args) => (
    <Toaster>
      <RichContentDemo {...args} />
    </Toaster>
  ),
};

Custom Content

export const CustomContent: Story = {
  args: { status: 'warning', children: 'Your session expires in 5 minutes.' },
  render: (args) => (
    <Toaster>
      <CustomContentDemo {...args} />
    </Toaster>
  ),
};

Progress Toast

export const ProgressToast: Story = {
  args: { title: 'Uploading report.pdf', children: '3 of 10 MB' },
  render: (args) => (
    <Toaster>
      <ProgressToastDemo {...args} />
    </Toaster>
  ),
};

Keyboard Shortcut

Show a toast, then press Alt+Shift+N to move focus to it.

export const KeyboardShortcut: Story = {
  args: { status: 'info', title: 'New comment', children: 'Ada replied to your review.' },
  render: (args) => (
    <Toaster shortcuts={{ focus: altShiftN }}>
      <div className="flex flex-col items-start gap-2">
        <p className="text-wave-body-1 text-wave-foreground">
          Show a toast, then press Alt+Shift+N to move focus to it.
        </p>
        <ToasterDemo {...args} />
      </div>
    </Toaster>
  ),
};

From Outside React

export const FromOutsideReact: Story = {
  args: {
    status: 'success',
    title: 'Export ready',
    children: 'report.csv was saved to your downloads.',
  },
  render: (args) => (
    <Toaster toaster={storyToaster}>
      <Button appearance="primary" onClick={() => notifyExportReady(args)}>
        Export
      </Button>
    </Toaster>
  ),
};

Inverted

Success:
Link copied
Share it anywhere.
export const Inverted: Story = {
  args: {
    title: 'Link copied',
    status: 'success',
    appearance: 'inverted',
    children: 'Share it anywhere.',
  },
  render: (args) => <DismissibleToast {...args} />,
};

Centered And Offset

export const CenteredAndOffset: Story = {
  render: () => (
    <Toaster position="top" offset={{ vertical: 48 }}>
      <OptionsDemo
        label="Show a centered toast"
        options={{ title: 'Centered', body: '48px from the top.' }}
      />
    </Toaster>
  ),
};

Per Toast Position

export const PerToastPosition: Story = {
  render: () => (
    <Toaster>
      <PerToastPositionDemo />
    </Toaster>
  ),
};

Politeness

export const Politeness: Story = {
  render: () => (
    <Toaster>
      <OptionsDemo
        label="Show a calm error"
        options={{
          title: 'Sync failed',
          status: 'error',
          politeness: 'polite',
          body: 'It will retry.',
        }}
      />
    </Toaster>
  ),
};

Priority

export const Priority: Story = {
  render: () => (
    <Toaster limit={1}>
      <PriorityDemo />
    </Toaster>
  ),
};

Lifecycle

Lifecycle: none yet

export const Lifecycle: Story = {
  render: () => (
    <Toaster>
      <LifecycleDemo />
    </Toaster>
  ),
};

Without Dismiss Button

export const WithoutDismissButton: Story = {
  render: () => (
    <Toaster>
      <OptionsDemo
        label="Show a toast without a button"
        options={{
          title: 'Syncing',
          body: 'Keep this window open.',
          showDismissButton: false,
          pauseOnHover: false,
        }}
      />
    </Toaster>
  ),
};

Custom Announcer

Announced: nothing yet

export const CustomAnnouncer: Story = {
  render: () => <CustomAnnouncerDemo />,
};

Inline

export const Inline: Story = {
  render: () => (
    <Toaster inline>
      <OptionsDemo label="Show an inline toast" options={{ title: 'Inline', body: 'No portal.' }} />
    </Toaster>
  ),
};

Props

NameTypeRequiredDefaultDescription
status'success' | 'warning' | 'error' | 'info'No'info'

Status level controlling the toast color, icon and status text.

appearance'default' | 'inverted'No'default'

inverted draws the toast on the inverted surface, as a Tooltip is: its background, border, text and icon take the inverted colors (the status shows in the start border), and so do the text of Toast.Title, Toast.Body and its subtitle. Buttons of your own in the footer keep their appearance (an inverted Spinner, a transparent Button suit it). The toast carries it as data-appearance. Fluent's Toast appearance.

showDismissButtonbooleanNotrue in a Toaster, else whether `onDismiss` is given

Whether the Dismiss button shows. Inside a Toaster it shows by default, a Toast outside one shows it with onDismiss. false hides it (Delete, Backspace, Escape, dismissToast and the timeout still dismiss the toast), for a toast that reports a running task; a Toast.Close of yours is not affected. Fluent has no such prop: its Dismiss button is a ToastTrigger you add.

titlestringNo

Title text (the 0.5 form; renders as a Toast.Title). A Toast.Title among the children wins over it (development warning).

statusLabelstringNo

Visually hidden status text read before the toast ('Info:', 'Success:', 'Warning:', 'Error:' by default). Pass a translation for other languages, or '' to omit it.

iconSlot<'span'>No

Replaces the status icon (decorative, aria-hidden). Only undefined keeps the default; null, or anything that renders nothing, shows no icon (the status-icon slot rule, as MessageBar.icon). Fluent's ToastTitle media.

onDismiss() => voidNo

Called when the Dismiss button or a Toast.Close is activated; passing it renders the button. Inside the Toaster every Toast shows the button and it dismisses the toast (your onDismiss runs first). A timeout, Escape, Delete and dismissToast do not call it.

dismissLabelstringNo'Dismiss'

Accessible name of the dismiss button. Pass a translation for other languages.

refReact.Ref<HTMLDivElement>No

Ref to the root <div>.

slotProps{ content?: SlotPart<'div'>; dismissButton?: SlotPart<'button'> }No

Props for the elements the Toast draws around your content, by part, merged into the part's own: your classes after the part's (yours win a conflict), your styles over its styles, your attributes and handlers added, your ref beside its ref. Every attribute the Toast sets on a part is locked and keeps the Toast's value; you add the attributes it does not set. A part takes no children.

Any other prop is passed to the element it renders (HTMLDivElement).

Parts

  • content
  • dismissButton
  • Toast.Title
  • Toast.Body
  • Toast.Footer
  • Toast.Close

Stable class names

PartClass
rootwave-toast
iconwave-toast__icon
contentwave-toast__content
dismissButtonwave-toast__dismiss-button