Skip to content

Search

Start typing to search.


Show all pages

Documentation

feedback

Toast

A short message that confirms what just happened, at the bottom of the screen, and goes away by itself.

Rich widgetNeeds a script for its behavior.

Usage

Press a button to see a toast. Buttons with data-ca-toast show one without code; apps call toast().

HTML

Examples

Variants

The markup ca-toast.js creates, in every tone. The message says what happened, so it does not rely on color.

Draft saved

Sam opened the invitation

Lesson moved to Thursday

Two lessons still need a car

Could not send the invoice

HTML

With an action

A toast can carry one action, such as Undo. It then stays until it is closed.

Lesson cancelled

HTML

Guidance and accessibility

When to use

  • Use a toast to confirm an action people just took, such as moving a lesson, when the page itself does not show the result.
  • Keep it to one short sentence that says what happened.
  • Do not use a toast for something people must read or act on. Errors in a form belong next to the field; a decision belongs in a dialog.

Show a toast from code

JavaScript
import { toast } from "@calaca/ui/behavior/toast";

toast("Lesson moved to Thursday", { tone: "success" });

const close = toast("Lesson cancelled", {
  action: { label: "Undo", onClick: () => restoreLesson() },
});

toast() returns a function that closes the toast. Options are tone, duration in milliseconds (5000 by default, Infinity to keep it) and one action. Without a bundler, import it from ca-toast.js, or dispatch new CustomEvent("ca:toast", { detail: { message, tone } }) on the document.

Accessibility

  • Every message is announced through one role="status" region that exists before the first toast, so screen readers read each one without moving focus.
  • A toast stays while the pointer is over it or focus is inside it, and a toast with an action stays until it is closed, so there is time to use the action (WCAG 2.2.1).
  • The region is in the top layer. While a modal dialog is open, the page behind it is inert, so the script moves the region into the dialog; toasts then show above it and their buttons work. It moves back when the dialog closes.
  • Every toast has a close button with an accessible name.

Classes

Generated from the component contract. Parts use __, modifiers use --.

Classes of the toast component
ClassKindUse it for
ca-toastComponentOne message with its close button.
ca-toast__regionPartThe region at the bottom end of the screen that holds the toasts; a manual popover.
ca-toast__messagePartThe text of the message.
ca-toast__closePartThe button that closes the toast.
ca-toast__statusPartThe visually hidden live region that announces each message.
ca-toast--neutralVariantGeneral feedback, such as a saved draft.
ca-toast--infoVariantNews about something else, such as someone opening an invitation.
ca-toast--successVariantAn action worked.
ca-toast--warningVariantIt worked, but something needs attention.
ca-toast--dangerVariantAn action failed.

Skins

The same markup, dressed by each skin. Structure and behavior stay the same; only the look changes.

Base skin

Neutral grayscale starting point; product skins extend it and change what differs.

Calaca skin

The Calaca UI brand: hueso paper and tinta ink, cempasúchil marigold, rosa and jade.

Proof skin

Pilot skin pushed far from base: square, heavy, offset shadows, larger targets.

Crossview skin

The CrossView proofing table: cool ground, bond-paper sheets, rule-grey hairlines, one red mark.

Framework notes

Link the prebuilt stylesheet of your skin next to your brand theme. No build step.

HTML
<link rel="stylesheet" href="theme.css" />
<link rel="stylesheet" href="ca-base.css" />