Skip to content
Fleetline

Toast

Usage

Use a toast to confirm something that happened in the background or off-screen ("Work order WO-1042 closed", "Odometer readings synced") without interrupting work. Toasts disappear on their own, so they must never be the only place important information lives.

Anatomy

  1. Region — .toast-region, top layer, bottom inline-end, labelled "Notifications", with one polite role="status"
  2. Toast — .toast.toast--{tone}, overlay surface with a tone bar
  3. Icon — .toast__icon, per tone, aria-hidden
  4. Title and message — .toast__title, .toast__message
  5. Action (optional) — .toast__action
  6. Close — .toast__close, "Dismiss notification"

Examples

Toasts are shown statically in each card; the button in each card sends a real one through toast().

Toast

Odometer readings synced

42 vehicles updated from telematics.

Work order WO-1042 closed

Invoice sent to Northside Depot.

KX-24 assigned while overdue

Brake inspection is 1,200 km overdue.

Telematics sync failed

We'll retry in 5 minutes.

Work order WO-1042 deleted

  1. Mechanic Lee Park assigned

  2. Odometer readings synced

  3. Work order WO-1042 closed

Newest at the bottom, nearest the screen edge; at most 3. Click the info, success and warning buttons quickly to see the real stack.

<script type="module">
  import { toast } from "../js/toast.js";
  toast({ tone: "success", title: "Work order WO-1042 closed", message: "Invoice sent to Northside Depot." });
  toast({ tone: "info", title: "Work order WO-1042 deleted",
          action: { label: "Undo", onAction: () => restoreWorkOrder("WO-1042") } });
</script>

<!-- Rendered markup (the region is created once, on first use) -->
<section class="toast-region" popover="manual" aria-label="Notifications">
  <ol class="toast-region__list">
    <li class="toast toast--success">
      <svg class="toast__icon" aria-hidden="true">…</svg>
      <div class="toast__content"><p class="toast__title">…</p><p class="toast__message">…</p></div>
      <button type="button" class="btn btn--ghost btn--sm toast__close" aria-label="Dismiss notification">…</button>
    </li>
  </ol>
  <div class="sr-only" role="status" aria-live="polite"></div>
</section>

API

HookValuesPurpose
toast({ tone, title, message, action, duration })JSShows a toast; returns { dismiss }. Tone: info (default), success, warning, danger. action = { label, onAction }
init(root)JSWires [data-toast] buttons (data-toast-tone | -title | -message | -action); safe to call twice
.toast--info | --success | --warning | --dangermodifierTone of the bar and icon
.toast__icon | __content | __title | __message | __action | __closepartsSee anatomy
[data-state="closing"]attribute (set by JS)Exit transition
Timing6s · 10s with actionPaused while the pointer or focus is in the region

Do and don't

Work order WO-1042 closed

Do confirm a completed action with the object's name.

Payment card declined

Update billing details to keep dispatching.

Don't use a disappearing toast for a blocking problem. Use an alert that stays.

Accessibility

Keyboard interaction
KeyBehavior
TabToasts are at the end of the document; their action and close buttons are reachable. While focus is inside, timers pause
Enter / SpaceActivates Undo or Dismiss; focus returns to where it was before entering the region

Tokens

Custom propertyPurpose
--color-elevation-surface-overlay, --elevation-overlaySurface and shadow
--color-feedback-{tone}-iconTone bar and icon
--z-toastStacking when the top layer isn't available
--motion-duration-base | -fast, --motion-easing-enter | -exitSlide in and out
--space-2 | -4Gap between toasts, distance from the screen edge