ToastProvider
ToastProvider owns a queue of short, non-blocking confirmations. Choose it when a descendant needs to announce an outcome without threading notification state through every intermediate component; use Toast and ToastStack directly when you already own that presentation state.
Examples
On this page, notifications appear in normal flow inside their own preview so both independent providers remain readable and their controls stay reachable. This positioning is documentation-only: the copied examples and the library default still use a stack fixed to the bottom-right of the viewport.
Send a confirmation
Wrap the part of the application that needs notifications, then call success from a descendant.
The provider supplies the icon, close control and fixed stack for each queued toast.
A per-toast duration
duration sets the provider default, while the options passed to toast override it for one
notification. Pass 0 for a notification that remains until the person dismisses it.
When to use
Use ToastProvider when several descendants need one shared, imperative notification API.
Reach for something else when:
- You already manage the list of visible notifications — use the low-level Toast and ToastStack components directly.
- The message belongs next to page content — use Alert.
- Someone must decide before continuing — use Dialog.
Accessibility
- ToastProvider announces info/success through a persistent polite region and danger through a persistent assertive region, both additions-only. Composed rows have no individual role. Never use a toast as the only place for important information.
- Each queued toast receives a close button whose accessible name comes from
closeLabel, defaulting to "Close notification". Provide localized copy when needed. - The provider's ToastStack is fixed at the bottom-right of the viewport. Keep messages brief and do not let the stack become a substitute for persistent status.
Timing and dismissal
React ToastProvider and the Alpine toast store resolve duration when a notification is queued:
per-toast duration overrides explicit provider/store configuration, which overrides the implicit
tone policy. Info and success default to 8000 ms; danger, including error(), defaults to
persistent. 0 always means persistent. Explicit global 8000 also makes danger expire.
Changing configuration affects new notifications only.
Pointer hover and focus inside a row independently pause its remaining time. The countdown resumes
only after both leave; moving between descendants does not restart it. Give action-bearing React
messages an explicit { duration: 0 }; the provider does not inspect their content.
Dismissing a focused row returns focus to its enqueue-time opener if that element is still eligible. Removed, disabled, hidden or inert openers, and openers inside a toast stack, use the same persistent stack instead. This named region (a landmark) remains focusable and visibly outlined even when empty. Unfocused dismissals do not move focus, and deliberate action focus moves are preserved. The region adds no live announcement; polite and assertive regions announce additions only.
Migration: set duration={4000} on React ToastProvider or assign
Alpine.store('lyraToasts').duration = 4000 to restore the previous default delay for all tones.
Per-toast overrides still take precedence. These timing changes apply to React and Alpine; the
imported Blade API below is unchanged.
API and code
Blade: The released Blade v0.10.0 API snapshot has no component for this catalog entry.
| Name | Type | Required | Description |
|---|---|---|---|
duration | number | — | Explicit delay for new notifications, overriding tone defaults. Omitted: info/success `8000`, danger `0`. Interaction pauses remaining time; `0` persists. |
'aria-label' | string | — | Accessible name of the owned notification region. Use distinct names for coexisting providers. Default: `"Notifications"`. |
closeLabel | string | — | Accessible name passed to every composed Toast close button. Default: `"Close notification"`. |
children | ReactNode | Required |
useToast
Retained methods read the latest committed provider configuration. After real provider unmount,
notification methods return numeric ids without adding state or timers, and dismiss does nothing.
During SSR, notification methods return numeric ids without adding state or timers.
A fresh provider starts empty. StrictMode replay preserves remaining time and interaction pauses.
The owned region defaults to the accessible name "Notifications". Set aria-label to localize it
or give coexisting providers distinct names, for example <ToastProvider aria-label="Project notifications">.
The two live examples above use different region names so they remain distinguishable on the same page.
Call useToast only below a ToastProvider; outside one, the hook throws. It returns toast, success,
error and info, each of which queues a message and returns a provider-local numeric id. Call
dismiss(id) to remove one before its timer expires. The optional duration in a call overrides the
provider default for that toast, and 0 disables its auto-dismiss timer. Retained API methods called
after the provider unmounts are safe no-ops: they return an id but do not queue state or leave a timer.
ToastProvider is React state and timing, so plain HTML uses the output primitives. Own the queue, auto-dismiss timers and close behavior yourself:
<div class="lyra-toast-stack">
<div class="lyra-toast" role="status">
<span class="lyra-toast__icon lyra-toast__icon--success" aria-hidden="true">✓</span>
<span>Project published</span>
<button class="lyra-toast__close" type="button" aria-label="Close notification">×</button>
</div>
</div>