Toast
toast is an imperative API for showing transient notifications. You call it from anywhere in your app, and the Toaster component — mounted once at the root — renders the result. To show a simple toast, call the toast function.
toast({ title: 'Toast title', description: 'Toast description', options: { /** * If duration is not provided, * the toast will be closed after 10 seconds by default. */ duration: 5000, dismissible: true, action: { label: 'Undo', onClick: () => { console.log('Undo') } } } })Toast types
toast can show different types of toasts:
- Default toast —
toast - Success toast —
toast.success - Danger toast —
toast.danger - Info toast —
toast.info - Loading toast —
toast.loading - Promise toast —
toast.promise
Variations
Success toast
Danger toast
Info toast
Info toast supports optional secondaryAction, ctaPosition ("top" | "bottom"), and severity ("Critical" | "High" | "Medium" | "Low"). These options are info-only. Omitting them preserves the default info toast layout and styling.
Loading toast
Promise toast
Promise toast accepts a promise as its first argument and an options object as its second argument.
Installation
import { Toaster, toast } from "@harnessio/ui/components";
// Mount the Toaster once, at the root of your app<Toaster />;
// Then call toast from anywheretoast({ title: "Saved", description: "Your changes have been saved.",});Behavior
- At most 3 toasts are visible at a time; additional toasts queue behind them.
- If
durationis not provided, a toast closes automatically after 10 seconds. - A toast shows a close button unless
dismissibleis set tofalseinoptions. By defaultdismissibleistrue. - Add an action button by providing
actioninoptions. Clicking it runs theactioncallback but does not close the toast — calltoast.dismissinside the callback if you want it to. - Loading toasts cannot be dismissed by the user; close them with
toast.dismiss(id). - Promise toasts close automatically 7 seconds after the promise settles.
- Loading and promise toasts cannot display a
description.
Best practices
Do
- Use the type that matches the message:
success/dangerfor outcomes,infofor neutral notices,loading/promisefor in-progress work. - Keep
titleshort and put detail indescription. - Provide an
action(e.g. “Undo”, “View details”) when there’s a meaningful next step.
Don’t
- Don’t use a toast for critical information a user must not miss — it’s transient and auto-dismisses.
- Don’t stack many toasts at once; only 3 show, and the rest queue.
Accessibility
Labeling & semantics
- Toasts are announced by the
Toaster’s live region, so screen-reader users hear new notifications without moving focus. - Because toasts disappear on a timer, don’t rely on them alone to convey information a user needs to act on — pair important states with persistent UI.
Properties
Toast params
Parameters passed to the toast function.
Prop | Required | Default | Type |
|---|---|---|---|
| title | true | string | |
| description | false | ReactNode | |
| options | false | ToastOptions | InfoToastOptions | |
| loadingMessage | false | string | |
| successMessage | false | string | |
| errorMessage | false | string |
Toast options
The configuration object passed to the toast’s options parameter.
Prop | Required | Default | Type |
|---|---|---|---|
| duration | false | 10000 | number |
| action | false | Action | |
| dismissible | false | true | boolean |
| onClose | false | () => void | |
| onAutoClose | false | () => void |
Info toast options
Info toasts (toast.info) accept everything above plus the following.
Prop | Required | Default | Type |
|---|---|---|---|
| secondaryAction | false | Action | |
| ctaPosition | false | "top" | "bottom" | |
| severity | false | "Critical" | "High" | "Medium" | "Low" |