Skip to content

Toast

Stacked toast notifications. Unlike the other components this is imperative and group-managed, so it does not extend ZagController. Put the controller on the toast region and provide a <template> for one toast; stimulus-zag renders one per toast in the store.

Create toasts by calling the controller (via a Stimulus outlet) or by dispatching a zag-toast:create CustomEvent on the region element:

js
const region = document.querySelector('[data-controller~="zag-toast"]')
region.dispatchEvent(new CustomEvent("zag-toast:create", { detail: { title: "Saved!" } }))

Parts

root, title, description, close-trigger, action-trigger (rendered per toast from the template).

Target: toastTemplate.

Values

AttributeTypeDefaultDescription
data-zag-toast-placement-valueString"bottom-end"Where toasts appear.
data-zag-toast-duration-valueNumber5000Default auto-dismiss (ms).
data-zag-toast-max-valueNumber24Max visible toasts.
data-zag-toast-gap-valueNumber16Gap between toasts (px).
data-zag-toast-overlap-valueBooleanfalseOverlap stacked toasts.

Imperative API: create(options), success(options), error(options), info(options), warning(options) (each returns the toast id), dismiss(id?), and count. Options: { title, description, type, duration, id }.