Toasts

NotificationService · NotificationDisplayControl

Tell users an action worked or failed with toasts that close themselves.

Overview

NotificationService shows Blazor toast notifications: short info, success, warning and error messages that stack in the top-right corner and close themselves. Use them to confirm a saved goods receipt or report a failed label print without interrupting work; call the service from any component, and one NotificationDisplayControl in the layout shows them all. An error stays ten seconds and a success four, and durationMs: 0 keeps a toast until it is closed or removed with Dismiss.

Examples

#Levels, detail and duration

Raise each level; the second argument is the detail line and durationMs: 0 keeps a toast until it is closed.

No toasts showing.

#Progress, then the outcome

Save the goods receipt: a sticky toast shows while the save runs, Dismiss removes it by id, and a success or an error toast takes its place. Switch on Make saves fail and every save fails until you switch it off; the error toast stays until it is closed or the next save starts.

0 saved, 0 failed

Documentation

MethodInputsReturnsDescription
Info()message
detail?
durationMs = 5000
voidBlue toast.
Success()message
detail?
durationMs = 4000
voidGreen toast.
Warning()message
detail?
durationMs = 8000
voidYellow toast.
Error()message
detail?
durationMs = 10000
voidRed toast. durationMs: 0 keeps it until dismissed.
Dismiss()Guid idvoidRemoves one toast, such as a progress message. The add methods return nothing, so read the new toast's Id from Notifications.
Clear()—voidRemoves every toast.
Notifications—IReadOnlyList<Notification>Current toasts, newest first, at most 20.
OnChange—event ActionRaised after every add, dismiss or clear. Auto-dismiss raises it from a timer thread; marshal with InvokeAsync.

Setup: builder.Services.AddScoped<NotificationService>() and one <NotificationDisplayControl /> in the layout. This site has both.

An unhandled error has occurred. Reload 🗙

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.