Skip to main content
  1. Docs
  2. Components
  3. Overlays

Toast

A brief word that something happened, at the bottom end. One action at most, such as Undo.

Import
@qeetrix/react
Status
StableSince 0.0.2
Renders
<div role="region">Server-rendered
Tested
WCAG 2.2 AAaxe on every pull request

01

Import

toast.tsx
// From the package: a build keeps only what it uses.
import { ToastProvider, useToast } from "@qeetrix/react";

// Or from its own path.
import { ToastProvider, useToast } from "@qeetrix/react/toast";

02

Props

And every native attribute of the element it renders.

PropTypeDefaultWhat it does
ToastProvider: limitnumber3The most shown at once; older ones wait.
ToastProvider: timeoutnumber5000Milliseconds before one closes, unless it sets its own.
useToast().add(options) => string—Shows a toast; returns its id.
useToast().update · close(id, options) · (id?)—Changes one that's showing; closes one, or all.
useToast().promise(promise, { loading, success, error })—A spinner while pending, then success or error; returns the promise.
options: title · descriptionReactNode—What happened; one more line.
options: tone"info" | "success" | "warning" | "danger""info"danger stays until dismissed and is announced at once.
options: action{ label, onClick }—At most one: Undo.
options: timeout · id · onClose…5000 · —Its own time; your own id; called however it closes.

03

Parts

Each part carries a data-slot, for tests and placement.

data-slotElementWhat it is
toast-viewport<div role="region">The region: a landmark named "Notifications", at the bottom end, reached with F6.
toast<div role="dialog">One toast: data-tone; data-loading while a promise is pending. A danger one is role="alertdialog".
toast-icon<svg>Its icon, or a spinner.
toast-content<div>toast-title and toast-description.

04

Once, at the root

ToastProvider wraps the app once; useToast works anywhere inside it.

app.tsx
<QeetrixProvider locale="en-IN">
  <ToastProvider>
    <App />
  </ToastProvider>
</QeetrixProvider>
Next — ToastAccessibility