RzToastProvider
RzToastProvider is the SSR-only root provider for toast notifications. It owns the toast viewport, renders the position stacks, and publishes the server-generated class map consumed by the Rizzy.toast JavaScript runtime.
Developers do not manually render toast items. Add one provider, then create toasts by calling Rizzy.toast or dispatching rz:toast events from client code, HTMX fragments, or other SSR-safe flows.
Important setup
Place one RzToastProvider near the root layout, typically after @Body. This documentation page renders a live provider directly on the page so the examples below can trigger real toast notifications.
Installation / Root Layout Placement
In an application, place one provider near the root layout, typically after @Body. The provider renders all supported stacks up front; Position only controls the default stack for requests that do not provide a position.
@inherits LayoutComponentBase
<div class="min-h-screen">
@Body
</div>
<RzToastProvider /><RzToastProvider Id="docs-toast-provider"
Position="ToastPosition.TopRight"
MaxVisible="5"
ShowProgress="true" />Server-triggered toasts with Rizzy
AddRizzyUI() registers the scoped IRzToastService and the internal ordered command queue. Add UseRzToast() to the request pipeline so commands queued during an HTMX request are emitted as one rz:toast:batch HX-Trigger event. The root layout must still render one RzToastProvider; the service only transports commands to the existing browser runtime.
builder.Services.AddRizzy();
builder.Services.AddRizzyUI();
var app = builder.Build();
app.UseRizzy();
app.UseRzToast();
app.MapControllers();
app.MapRazorComponents<App>();The C# API mirrors the server-compatible Rizzy.toast methods: Show, Custom, Success, Error, Warning, Info, Loading, Update, Dismiss, and Clear. Commands keep their insertion order in the batch, so a show followed by an update for the same stable id is processed in that order by the browser.
public IActionResult Save([FromServices] IRzToastService toastService)
{
toastService.Success("Project settings saved.", "Saved");
return View();
}Rizzy.toast.success("Project settings saved.", "Saved");toastService.Show(new RzToastMessage
{
Status = ToastStatus.Warning,
Title = "Session expiring",
Text = "Your session expires in two minutes.",
Position = ToastPosition.BottomRight,
Duration = 7000,
DedupeKey = "session-expiration"
});
var handle = toastService.Loading("Uploading file...", "Uploading", new RzToastOptions
{
Id = "profile-photo-upload"
});
handle.Update(new RzToastUpdate
{
Status = ToastStatus.Success,
Title = "Uploaded",
Text = "Your profile photo was updated.",
AutoClose = true,
Duration = 3000,
Progress = true
});toastService.Update("profile-photo-upload", new RzToastUpdate
{
Status = ToastStatus.Success,
Title = "Uploaded",
Text = "Your profile photo was updated."
});
toastService.Dismiss("obsolete-toast");
toastService.Dismiss();
toastService.Clear();
toastService.Success("Message archived.", "Archived", new RzToastOptions
{
Action = new RzToastAction
{
Label = "Undo",
EventName = "rz:message:restore",
Detail = new { MessageId = 42 }
}
});HTMX request-scope limitation
UseRzToast() emits commands only for HTMX responses. Commands queued during normal non-HTMX requests, redirects, or later requests are not persisted by this middleware. Use application-defined stable string ids for cross-request updates, and do not store RzToastHandle beyond the current request scope. Redirect persistence requires a separate TempData, session, distributed cache, or application-specific store.
Live Examples
These examples use delegated documentation event listeners and stable data-rz-toast-demo attributes. The buttons call the real Rizzy.toast facade in the same DOM context as the provider above.
Default toast
Use a default toast for neutral feedback that confirms an operation completed or provides lightweight status information.
Rizzy.toast.show({
title: "Notification",
description: "The background check completed."
});Title and description
Use a title when the toast needs a scannable heading and a short supporting message.
Rizzy.toast.info("The report is being generated. You can continue working.", "Report started");Success toast
Use a success toast after a save, publish, upload, or completed background operation.
Rizzy.toast.success("Project settings saved.", "Saved");Info toast
Use an info toast for non-critical status updates, background task starts, or contextual notices.
Rizzy.toast.info("Build started. You can continue working while it runs.", "Build started");Warning toast
Use a warning toast for non-blocking conditions the user may need to notice soon.
Rizzy.toast.warning("Your session expires in 2 minutes.", "Session expiring");Error toast
Use an error toast when an operation fails but the user can continue working. For blocking failures, use an alert, dialog, or form validation message instead.
Rizzy.toast.error("Unable to upload image. Check the file type and try again.", "Upload failed");Action toast
Use an action toast when the user can immediately recover from the event, such as undoing a delete or retrying a failed operation.
Rizzy.toast.success("Message archived.", "Archived", {
action: {
label: "Undo",
dismissOnClick: true,
onClick: toast => {
Rizzy.toast.info("The message was restored.", "Undo complete");
toast.dismiss();
}
}
});Persistent toast
Use a persistent toast for progress or status that should remain visible until the user dismisses it or code updates it.
Rizzy.toast.info("Waiting for the background worker to respond.", "Still working", {
autoclose: false,
progress: false
});Custom duration
Use a custom duration when the message needs slightly more or less reading time than the provider default.
Rizzy.toast.success("Export completed and is ready to download.", "Export ready", {
duration: 7000
});Loading and update flow
Use a loading toast for long-running work, then update the same id when the operation completes.
Rizzy.toast.loading("Uploading changes...", "Syncing", {
id: "docs-loading-demo"
});
setTimeout(() => {
Rizzy.toast.update("docs-loading-demo", {
status: "success",
title: "Synced",
text: "All changes are online.",
autoclose: true,
duration: 3000,
progress: true
});
}, 1500);Positioning
RzToastProvider renders separate stacks for every supported position, so different toast requests can appear in different regions at the same time.
Rizzy.toast.info("This toast appears in the top-right stack.", "Top right", {
position: "top-right"
});
Rizzy.toast.info("This toast uses the Simple Notify alias bottom left.", "Bottom left", {
position: "bottom left"
});
Rizzy.toast.info("This toast appears in the center stack.", "Center", {
position: "center"
});
Rizzy.toast.info("This toast uses the Simple Notify alias right y-center.", "Right center", {
position: "right y-center"
});Programmatic dismiss and clear
Use a stable id when you need to dismiss or update a specific toast later. Use clear when a context change makes existing notifications irrelevant.
Rizzy.toast.info("This toast can be dismissed by id.", "Tracked toast", {
id: "docs-dismiss-demo",
autoclose: false,
progress: false
});
Rizzy.toast.dismiss("docs-dismiss-demo");
Rizzy.toast.clear();Event dispatch
Use rz:toast events when a server-rendered fragment, HTMX response, or other client code needs to publish a toast without directly calling the facade.
window.dispatchEvent(new CustomEvent("rz:toast", {
detail: {
id: "docs-event-demo",
status: "success",
title: "Saved",
description: "The event API created this toast."
}
}));window.dispatchEvent(new CustomEvent("rz:toast:update", {
detail: {
id: "docs-event-demo",
text: "The event API updated this toast."
}
}));
window.dispatchEvent(new CustomEvent("rz:toast:dismiss", {
detail: { id: "docs-event-demo" }
}));
window.dispatchEvent(new CustomEvent("rz:toast:clear"));Dedupe behavior
Use dedupeKey for one logical notification that may update repeatedly instead of stacking duplicates.
Press repeatedly to update/coalesce the same logical warning.
Rizzy.toast.show({
dedupeKey: "docs-storage-warning",
status: "warning",
title: "Storage warning",
text: "Storage is still almost full.",
incrementCount: true
});Stacking and overflow
MaxVisible limits the number of visible toasts per position stack. The default overflow strategy dismisses the oldest toast in the affected stack.
for (let index = 1; index <= 7; index += 1) {
Rizzy.toast.info(`Stacked notification ${index}`, "Stack demo", {
position: "bottom-right",
duration: 8000
});
}Usage Guidelines
Use toast notifications for
- Save confirmations
- Background task completion
- Non-blocking errors
- Short status messages
- Undo or retry actions
Avoid toast notifications for
- Required decisions
- Field-level validation
- Blocking errors
- Long explanations
- Multi-step workflows
Use RzAlert for persistent inline feedback, a dialog for required decisions, and form validation messages near the related field.
API Reference
Provider Parameters
| Property | Description | Type | Default |
|---|---|---|---|
Position | Default stack for new toasts; all stacks are still rendered. | ToastPosition | ToastPosition.TopRight |
DefaultStatus | Default semantic status for new toasts. | ToastStatus | ToastStatus.Info |
Tone | Default visual tone. | ToastTone | ToastTone.Subtle |
Animation | Default animation preset. | ToastAnimation | ToastAnimation.Fade |
OverflowStrategy | Behavior when a stack reaches MaxVisible. | ToastOverflowStrategy | DismissOldest |
Duration | Default auto-dismiss duration in milliseconds. | int | 4000 |
Speed | Leaving transition speed in milliseconds. | int | 300 |
MaxVisible | Maximum visible toast count per position stack. | int | 5 |
NewestOnTop | Whether new toasts insert before older toasts. | bool | true |
Dismissible | Whether close buttons render by default. | bool | true |
ShowIcon | Whether status icons render by default. | bool | true |
ShowProgress | Whether progress indicators render by default. | bool | true |
PauseOnHover | Whether timers pause during pointer hover. | bool | true |
PauseOnFocus | Whether timers pause while focus is inside a toast. | bool | true |
PauseOnWindowBlur | Whether timers pause while the window is blurred. | bool | false |
CloseOnEscape | Whether Escape dismisses a focused toast. | bool | true |
PreventDuplicates | Whether duplicate requests update instead of stacking. | bool | false |
CloseButtonAriaLabel | Accessible label for close buttons. | string? | localized |
RegionAriaLabel | Accessible label for the provider region. | string? | localized |
Toast Request Options
| Option | Description | Type | Default |
|---|---|---|---|
id | Stable id for update or dismiss. | string | generated |
status | Canonical toast status. | string | provider default |
variant | Alias for status. | string | none |
title | Scannable heading text. | string | empty |
text | Primary description text. | string | empty |
message | Alias for text. | string | none |
description | Alias for text. | string | none |
position | Canonical position or supported alias. | string | provider default |
duration | Auto-dismiss time in milliseconds. | number | provider default |
autotimeout | Alias for duration. | number | none |
autoclose | Whether the toast closes automatically. | boolean | duration > 0 |
tone | Visual tone. | string | provider default |
type | Alias for tone; filled maps to solid. | string | none |
animation | Animation preset. | string | provider default |
effect | Alias for animation. | string | none |
dismissible | Whether the close button is shown. | boolean | provider default |
showCloseButton | Alias for dismissible. | boolean | none |
action | Action button label and JavaScript callback. | object | none |
dedupeKey | Logical key used to update instead of stack. | string | none |
incrementCount | Increment coalesced toast count. | boolean | false |
data | Serializable data forwarded to lifecycle events. | any | none |
customClass | Alias for root toast class. | string | none |
className | Alias for root toast class. | string | none |
classNames | Slot-specific class overrides. | object | {} |
Statuses
| Status | Use | ARIA | Default tone |
|---|---|---|---|
default | Neutral feedback. | status / polite | subtle |
info | Non-critical status updates. | status / polite | subtle |
success | Completed operations. | status / polite | subtle |
warning | Non-blocking concerns. | status / polite | subtle |
error | Recoverable failures. | alert / assertive | subtle |
loading | Long-running work. | status / polite | subtle |
Positions
| Canonical value | Simple Notify-compatible aliases | Region | Notes |
|---|---|---|---|
top-left | left top, top left | Top left | Canonical corner stack. |
top-center | top center, center top, x-center top, top x-center | Top center | Centered along top edge. |
top-right | right top, top right | Top right | Default provider position. |
bottom-left | left bottom, bottom left | Bottom left | Simple Notify alias supported. |
bottom-center | bottom center, center bottom, x-center bottom, bottom x-center | Bottom center | Centered along bottom edge. |
bottom-right | right bottom, bottom right | Bottom right | Useful for stack demos. |
center | center | Center | Centered viewport stack. |
left-center | left center, left y-center, y-center left | Left center | Vertical center alias supported. |
right-center | right center, right y-center, y-center right | Right center | Vertical center alias supported. |
Overflow Strategies
| Enum | Request value | Behavior | Use when |
|---|---|---|---|
DismissOldest | dismiss-oldest | Dismisses the oldest toast in the affected stack. | New information should still appear. |
IgnoreNewest | ignore-newest | Drops the newest request when the stack is full. | Existing notifications are more important. |
Accessibility
Toasts do not steal focus. The provider root exposes a named region, while each JavaScript-rendered toast announces through live-region semantics instead of moving the user away from their current task.
Default, info, success, warning, and loading toasts use role="status" with aria-live="polite". Error toasts use role="alert" with aria-live="assertive". Every toast uses aria-atomic="true" so assistive technology announces the complete message.
Close controls are native buttons with accessible labels, action buttons are keyboard reachable, and Escape can dismiss a focused toast when CloseOnEscape is enabled. Auto-dismiss timers pause on hover and focus when configured, helping users read or act on content before it disappears.
Give users enough time for toast content, avoid long or critical messages, and never make a toast the only way critical information is communicated. Reduced-motion preferences are respected through the generated class map, and functional timing does not depend on animation.
Theming
Provider and toast item classes come from Theme.RzToastProvider. JavaScript reads the class map rendered by the provider and applies slot, status, tone, animation, state, and position classes without constructing Tailwind class strings at runtime.
Override the descriptor in your theme to adjust the provider root, viewport stacks, toast item slots, status variants, tones, animations, and reduced-motion-safe states.
CSP Notes
The toast runtime is loaded through the normal RizzyUI JavaScript entries, including the CSP-safe entry. It avoids eval, new Function, inline event handlers, dynamic script injection, and runtime Tailwind construction.
This documentation page uses a CSP-safe delegated listener in /js/site.js. Toast text is assigned as text content by the runtime; HTML content must be supplied as a trusted HTMLElement.
Migration Notes
The public Rizzy.toast facade preserves compatibility helpers such as success, error, warning, info, custom, and Simple Notify option aliases including variant, message, description, autotimeout, effect, type, customClass, and compatible position strings.
Simple Notify CSS class names are not preserved. Style toast output through Theme.RzToastProvider and the provider-generated class map.
Troubleshooting
No toast appears
Ensure RzToastProvider is rendered on the current page or root layout and that the RizzyUI JavaScript runtime is loaded before calling Rizzy.toast.
Toast does not work inside RzBrowser
RzBrowser renders its inner content in an iframe. Place the provider directly on the page or in the application layout, not inside browser preview components.
Toast appears in the wrong position
Use canonical positions such as top-right or bottom-left, or one of the supported Simple Notify aliases such as bottom left or right y-center.
Toast disappears too quickly
Increase Duration or request-level duration, set autoclose to false for persistent toasts, and keep PauseOnHover or PauseOnFocus enabled when users may need more time.
Action button does not run
Action callbacks must be real JavaScript functions. Runtime callback errors are caught and logged to the console.
Styles look wrong or missing
Classes come from the provider’s server-generated class map and Theme.RzToastProvider. Make sure the provider renders and the Tailwind build includes RizzyUI descriptor classes.