Toast

Updated: Sep 24, 2026
Toast is an imperative singleton that presents a short, non-blocking message at the top of the display and dismisses it on its own. Reach for it to confirm something that already happened — “Settings saved”, “Photo deleted” — never to ask a question, offer an action, or report a failure the user has to recover from.
The utility owns the entire presentation: the queue, the display timing, the fade in and out, the elevated chip the message is drawn on, and the polite live region that announces it. App already renders the single ToastContainer that paints it, so there is no toast component for an application to render — you just call Toast.show.

Usage

Call Toast.show from an event handler. There is nothing to mount and no state to hold.
import { Button, Page, Toast } from '@wearables-ui-toolkit/mrbd';

export function SettingsScreen() {
  return (
    <Page>
      <Button
        title="Save"
        onActivate={() => {
          Toast.show('Settings saved');
        }}
      />
    </Page>
  );
}
Keep the returned identifier when the reason for the message can disappear before the message does, then cancel it.
import { Toast, type ToastIdentifier } from '@wearables-ui-toolkit/mrbd';

const token: ToastIdentifier = Toast.show('Uploading photo', '3 remaining', uploadIcon);

// The upload was cancelled before the toast finished.
Toast.cancel(token);
App mounts the presenter for you, so an application root needs no toast markup:
import { App } from '@wearables-ui-toolkit/mrbd';

export function Root() {
  return (
    <App>
      <SettingsScreen />
    </App>
  );
}
Use useToast when a component needs to know what is currently on screen — for example to skip an announcement it would otherwise duplicate:
import { useToast } from '@wearables-ui-toolkit/mrbd';

function SaveStatus() {
  const toast = useToast();
  const isAnnouncingSave = toast?.message === 'Settings saved';

  return isAnnouncingSave ? null : <SavedBadge />;
}

API

MethodSignatureDescription
Toast.show
show(message: string, metadata?: string, icon?: IconSource, style?: ToastStyle): ToastIdentifier
Enqueues a toast and returns the identifier used to cancel it. Presents immediately when nothing else is on screen. style defaults to ToastStyle.STANDARD.
Toast.cancel
cancel(token: ToastIdentifier): void
Removes the toast from the queue. If it is the one currently on screen, its exit fade starts right away.
Toast.cancelAll
cancelAll(): void
Empties the pending queue. A toast already on screen finishes its normal display and fade.
icon accepts any IconSource: an inline vector, an asset descriptor, or a URL string.

Hook

HookReturnsDescription
useToast
the toast being presented, or null
Subscribes to the presenter and re-renders when the presented toast changes. The value carries message, metadata, icon, style, and token.
The value stays non-null for the whole visible lifetime of a toast, including its exit fade, and drops back to null in the gap before the next one. Use it only to observe the queue — rendering the toast itself is the container’s job.

ToastContainer

ToastContainer is the component that paints the presented toast, and App renders it for you. It is exported so its props type is nameable and so tests and previews can render one in isolation; applications should not mount their own.
It takes ToastContainerProps. Both props are escape hatches for nudging the container inside a preview harness; the container still owns its layout, gradient, and the chip inside it.
PropTypeDefaultDescription
className
string
''
Extra class on the container element.
style
CSSProperties
{}
Extra inline styles on the container element. Position and stacking level are set by the container afterwards and cannot be replaced here.

Types and enums

ToastStyle

MemberDescription
STANDARD
The only style. Draws the message on an elevated Chip.

ToastIdentifier

A number handed back by Toast.show and accepted by Toast.cancel. Treat it as an opaque token.

Behavior

  • One toast is visible at a time. Further requests queue and are presented in the order they were made, separated by a 700 ms handoff gap. A request made during that gap still waits its turn.
  • Each toast fades in at the top edge, holds for 3500 ms from the moment it is presented, then fades out over 300 ms. It does not translate while animating, so the message stays at a stable position, and it remains in the DOM until the exit fade finishes.
  • Cancelling the visible toast runs the same exit fade and handoff gap as a natural dismissal, so the next queued toast is not yanked forward.
  • The message, optional metadata, and optional icon are rendered by an elevated Chip, which owns its own intrinsic sizing and material.
  • The frame spans the full width available to the application root, centers the chip, and lays a top-to-bottom gradient from --uit-color-background-window to --uit-color-background-flat behind it so the message stays legible over whatever is underneath.
  • The container renders into the floating portal root supplied by App, above route content, and falls back to the document body when there is no App root. See Floating portals.
  • With no toast to show, the container renders nothing at all.
  • The queue is document-wide, not per-component: every call reaches the same presenter regardless of which subtree made it, and every mounted container paints the same toast. Mounting a second one paints a duplicate rather than a second queue.
  • The presenter owns the timing, not the container. A toast enqueued before App is mounted still runs its display timer and expires unseen, so do not enqueue one during module evaluation and expect it to wait for the application root.
  • Where there is no DOM (server rendering) show, cancel, and cancelAll do nothing and show returns 0.

Accessibility

  • The container is a polite live region (role="status", aria-live="polite", aria-atomic="true"), so the message and metadata are announced when it appears. You supply the wording; the container supplies the role.
  • The toast is not focusable and does not take pointer events. Nothing inside it can be operated, which is why it must never carry an action.
  • Because the announcement is polite, it waits for the current utterance to finish. Do not rely on a toast to interrupt with time-critical information.
  • Do not announce the same confirmation from a live region of your own — it would be read twice.
  • Use it to confirm a completed, non-blocking action.
  • Keep the message to one short sentence and put any secondary detail in metadata.
  • Cancel a queued toast whose subject no longer exists.
  • Summarise a repeated operation with one message.
  • Pass a localized string for both message and metadata; the utility never translates them.

Avoid

  • Avoid rendering a second ToastContainer; App already renders one.
  • Avoid using a toast for a decision, a recoverable error, an action, or progress that keeps changing — use a route, a Modal surface, or a progress indicator.
  • Prefer one summary toast over a toast per item in a loop. The queue is ordered, so individual entries wait their turn.
  • Avoid restyling the container to reposition it or to change the chip inside it.
  • Avoid expecting cancel to do anything with a token whose toast has already finished; identifiers come from a monotonic counter, so a stale one simply matches nothing.