Toasts

NotificationService · NotificationDisplayControl

Call the service from anywhere; toasts stack in the top-right corner and dismiss themselves.

Overview

NotificationService is a scoped, per-circuit service with four methods: Info, Success, Warning and Error. Each takes a message, an optional detail line and a duration in milliseconds; zero keeps the toast until the user closes it. NotificationDisplayControl, rendered once in the layout, shows the queue fixed to the top-right corner, newest first, twenty at most, each sliding in from the right. No JavaScript.

Examples

#Levels, detail and duration

One call per level. The second argument is the smaller detail line. Defaults: info 5 s, success 4 s, warning 8 s, error 10 s. Pass durationMs: 0 for a toast that stays.

Example
Razor
C#
No toasts showing.

Documentation

NotificationService

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()idvoidRemoves one toast.
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.
()setupbuilder.Services.AddScoped<NotificationService>() and one <NotificationDisplayControl /> in the layout. This site has both.

Notification

PropertyTypeDefaultDescription
IdGuid—Key for Dismiss.
LevelNotificationLevel—Info, Success, Warning or Error.
Messagestring—Bold first line.
Detailstring?nullSmaller second line.
TimestampDateTime—When it was added.
DurationMsint—Auto-dismiss delay; 0 means sticky.

NotificationDisplayControl has no parameters. It reads the service, re-renders on OnChange, and scales with --fx-zoom when a ZoomService is registered. Position, widths and colors are fixed in its stylesheet.

CSS classes

ClassEffect
fx-notification-containerFixed 12px from the top-right, 320–420px wide, z-index 10000, column with 8px gaps.
fx-notification · .fx-notification-info / -success / -warning / -errorOne toast; the level class sets the tinted background, text color and 4px left border.
fx-notification-icon · fx-notification-body · fx-notification-message · fx-notification-detailIcon glyph, text column, bold message, 11px detail at 80% opacity.
fx-notification-closeThe × button, 50% opacity until hovered.
fx-slide-in0.25s slide from the right on entry.

Keyboard and accessibility

  • The close button is a native <button>; its only text is ×, so screen readers announce it as "times" or "multiplication sign".
  • The container is a plain <div> with no aria-live region, so a new toast is not announced. Put important outcomes in the page as well, or use a dialog.
  • Toasts slide in over 0.25 s with no prefers-reduced-motion check.
  • The container ignores pointer events except on the toasts themselves, so it never blocks the page underneath.
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.