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.
Choose a type to pick which function fires — toast for neutral messages, toast.success / toast.danger for outcomes, toast.info for notices, and toast.loading / toast.promise for in-progress work. title is the bold heading and description the detail line (loading and promise toasts show only a title). Through options you can set a duration, allow or block dismissal with dismissible, and attach an action button; info toasts additionally take a secondaryAction, a ctaPosition, and a severity border. Try them in the playground below.
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') } } } })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.",});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
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.
When to use a toast
Use a success toast only when the user can’t already see that the action worked.
Skip the toast when
- The result is on screen: a new row appears, a toggle flips, an edit saves in place.
- The user lands on the result, like being taken to a new item’s page after creating it.
- The action is small and easy to undo, like checking a box or changing a filter.
- It would fire over and over, like autosave.
- The action is a delete. Deletes always use a confirmation dialog, never a toast.
Use a toast when
- The result is somewhere else — for example, moving an item to another project.
- Nothing changes on screen. Copying to the clipboard is the classic case.
- The work takes time. Confirm when it starts (“Export started”) and when it finishes (“Export ready”), especially if the user may have moved on.
- Many things happened at once. Say what happened: “12 members added,” or “9 of 12 added, 3 failed,” with a link to details.
Writing them
- Be specific and use past tense — “Member added” is better than “Success!”
- Match the type to the message:
success/dangerfor outcomes,infofor neutral notices,loading/promisefor in-progress work. - Keep the
titleshort and put any detail in thedescription. - Add an
actionlike “Undo” or “View details” when there’s a meaningful next step. - Dismiss automatically after about 5 seconds.
- Keep it to one toast at a time, and combine multiple results into one message.
- Don’t use a toast for errors or anything the user needs to act on — those should stay on screen.
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" |