Toast

Brief, non-blocking notifications stacked in the corner of the screen.

StableSource

Import

tsx
import { ToastProvider, useToast } from "@merid/react";

Anatomy

Toasts are imperative. Wrap the app once in ToastProvider, then call toast() from useToast anywhere below it.

tsx
<ToastProvider>
  <App /> {/* const { toast, dismiss } = useToast(); */}
</ToastProvider>

Each toast renders a status dot, a title, an optional description, an optional action button and a dismiss button. The provider portals a labelled region with a polite live list to the bottom-right of the viewport.

Examples

Tones

The tone only changes the status dot colour.

Action, persistence and dismiss

duration: Infinity keeps a toast until it is dismissed. Choosing the action runs onClick and dismisses the toast. Reusing an id replaces the existing toast instead of stacking a new one.

API reference

ToastProvider

PropTypeDefaultDescription
childrenReactNode–App content.
durationnumber5000Default auto-dismiss delay in ms.
limitnumber3Maximum toasts visible at once; oldest are dropped.
labelstring"Notifications"Accessible name of the notification region.

useToast()

Returns ToastApi. Throws when called outside ToastProvider.

PropTypeDefaultDescription
toast(options: ToastOptions) => string–Shows a toast and returns its id.
dismiss(id?: string) => void–Removes a toast by id, or all toasts when omitted.

ToastOptions

PropTypeDefaultDescription
titleRequiredReactNode–Short headline.
descriptionReactNode–Optional supporting text.
tone"neutral" | "info" | "success" | "warning" | "danger""neutral"Status dot colour.
durationnumberprovider durationAuto-dismiss after this many ms; Infinity keeps it until closed.
action{ label: string; onClick: () => void }–Optional action button.
idstring–Reuse an id to replace an existing toast; its timer restarts with the new `duration`.

Styling

ClassElement
.mrd-toast-region, .mrd-toast-region__listRegion and live list
.mrd-toastOne toast
.mrd-toast__dotStatus dot
.mrd-toast__body, .mrd-toast__title, .mrd-toast__descriptionText
.mrd-toast__actionAction button
.mrd-toast__closeDismiss button
AttributeOnValues
data-tone.mrd-toastneutral, info, success, warning, danger

Accessibility

Toasts follow the WAI-ARIA alert pattern in its polite form: the list is an aria-live="polite" region inside a labelled <section>, so new toasts are announced without interrupting. The auto-dismiss timer pauses while the pointer is over a toast or focus is inside it.

KeyAction
TabReach the action and dismiss buttons of visible toasts.
EnterActivate the focused action or dismiss button.
SpaceActivate the focused action or dismiss button.

Guidelines

Do

Confirm an action the person just took, in a few words: “Changes saved”.

Avoid

Show a toast for something the person can already see change on screen.

Do

Offer Undo on reversible destructive actions and keep that toast until dismissed.

Avoid

Stack several toasts for one event, or use long descriptions.