Skip to main content

Toast

BasicFeedback<co-toast>

Toast confirms a finished action at the bottom of the screen for about 2.8 seconds, in the "... Successfully" voice.

import { Toast } from 'health-components';

Examples​

Tones​

Storybook

With Undo​

Storybook

With Provider​

Storybook

Usage​

{toast && <Toast tone="success" message="Draft Saved Successfully" />} // hide after 2800 ms

In an app, wrap the root in ToastProvider and use the hook: toasts queue in a portal, hide after 2800 ms (5000 ms with an action; hover or focus pauses), and errors stay until dismissed.

<ToastProvider><App /></ToastProvider>

const toast = useToast();
toast.success("Draft Saved Successfully");
toast.show({ message: "Notification Deleted Successfully", tone: "success", action: "Undo", onAction: restore });
toast.error("Could not save. This browser is blocking storage; nothing was changed.");

When to use​

  • Background confirmation that needs no action.

When not to use​

  • Errors the user must fix: field error or Alert.
  • Big completions (claim submitted): SuccessDialog.

Variants and states​

VariantWhat it is
neutralDefault.
successCheck icon.
errorAlert icon, role alert, stays until dismissed.
actionOne text action, such as Undo.
inlineStatic, for previews and docs.

Accessibility​

  • role status with aria-live polite; errors role alert.
  • Do not auto-hide a toast that holds an action in under 5 seconds.

Do and don't​

  • Do: Title Case object and verb plus Successfully: "Appointment Type Added Successfully".
  • Don't: "Success!"
  • Don't: Toasts for errors that block the task.

Props​

PropTypeDefaultDescription
messagestring—Message in the "... Successfully" voice ("Draft Saved Successfully"). Falls back to `children`.
toneToastTone'neutral''neutral' | 'success' | 'error'
actionstringnoneOne text action, such as "Undo"
onAction() => voidnoneAction handler
onDismiss() => voidnoneShows a Dismiss (x) button that calls this
inlinebooleanfalseStatic, rendered in place (previews, docs, and inside ToastProvider); otherwise fixed at the bottom through a portal
childrenReactNode—Message content when `message` is not set

Also accepts native attributes, including defaultChecked, defaultValue, autoFocus, plus className and event handlers on the root element.

Angular, Vue and HTML​

Register the elements once (Angular guide), then use <co-toast>. Attributes take strings; arrays and objects are set as properties (Angular [prop], Vue :prop) or as JSON attributes. Callbacks are DOM events with the value in event.detail.

Angular template
<co-toast message="…" tone="…" [defaultValue]="defaultValue" (co-action)="onAction($event.detail)">…</co-toast>
KindNameDescription
attributemessageMessage in the "... Successfully" voice ("Draft Saved Successfully"). Falls back to `children`.
attributetone'neutral' | 'success' | 'error'; default 'neutral'
attributeactionOne text action, such as "Undo"; default none
attributeinlineStatic, rendered in place (previews, docs, and inside ToastProvider); otherwise fixed at the bottom through a portal; default false
attributedefault-checked / defaultChecked
property / JSON attributedefault-value / defaultValue
attributeauto-focus / autoFocus
eventco-actionAction handler; default none (React: onAction)
eventco-dismissShows a Dismiss (x) button that calls this; default none (React: onDismiss)
slot(default)Message content when `message` is not set