Skip to content
daisyBlazor

Snackbar

Toast messages raised from code with ISnackbar.Add and shown bottom-right by SnackbarProvider. Each one auto-dismisses after a delay, pausing while it is hovered or focused.
Cover · <SnackbarProvider>
Task added to the sprint
Deploy starts in 5 minutes
Invoice INV-1042 paid

Examples

Severities

The Severity argument picks the alert colour and icon.

website/Examples/Feedback/SnackbarSeveritiesExample.razor Source

Options

The configure callback sets SnackbarOptions: VisibleStateDuration (ms, default 5000), ShowCloseIcon (default true) and PreventDuplicates (default true). ISnackbar.Remove(message) drops one toast, Clear removes them all and Shown lists the visible ones.

website/Examples/Feedback/SnackbarOptionsExample.razor Source

Action

Action and OnAction add a button such as Undo; clicking it closes the toast, then runs the callback, so it runs once even on a double click. ActionTitle and ActionKeyShortcuts describe the button, FocusAction moves focus to it when the toast appears, and Icon or HideIcon replace the severity icon. Escape closes a focused toast. ShowProgress draws the time left, which pauses with the countdown on hover and focus. ReturnFocus names the element that gets focus back when the toast closes while it held focus. SnackbarProvider.VisibleStateDuration sets the house default for messages that set none, and SnackbarProvider.Position (an Origin, BottomRight by default) where the toasts stack.

Invoice INV-1042
website/Examples/Feedback/SnackbarActionExample.razor Source

API

<SnackbarProvider>

DaisyBlazor

Parameters

  • AlertClass string
    = null

    Extra CSS classes merged onto every toast's alert element. Per message, use Class.

  • CloseLabel string
    = null

    Accessible label of each toast's close button. Null uses the app-wide Strings.

  • Position Origin
    = Origin.BottomRight

    Corner or edge of the viewport the toasts stack at. Center rows are vertically centred; defaults to BottomRight.

  • Variant Variant
    = Variant.Filled

    Default alert style of every toast: Filled (default) is solid, Outlined adds alert-outline, Text adds alert-soft. A message overrides it with Variant.

  • VisibleStateDuration int
    = 5000

    House default (ms) for how long a toast stays visible, used when a message does not set VisibleStateDuration.

  • Class string
    = null

    Extra CSS classes merged onto the root toast container element.

  • Style string
    = null

    Inline CSS styles applied to the root toast container element.

ISnackbar

DaisyBlazor

MudBlazor-compatible snackbar contract. Snackbar.Add("msg", Severity.Success) stays working.

Properties

  • Shown IReadOnlyList<SnackbarMessage>

    Currently visible toasts.

Events

  • OnChange Action

    Raised whenever the visible set changes so a provider can re-render.

Methods

  • Add (string message, Severity severity = Severity.Normal, Action<SnackbarOptions> configure = null) → void

    Queue a new toast.

  • Clear () → void

    Remove all toasts.

  • Remove (SnackbarMessage message) → void

    Remove a specific toast.

SnackbarOptions

DaisyBlazor

Per-message snackbar configuration, mirroring the MudBlazor options surface used across DaisyBlazor.

Properties

  • Action string
    = null

    Label of an action button on the toast (e.g. "Undo"); no button when null.

  • ActionKeyShortcuts string
    = null

    Keyboard shortcut that also runs the action, announced through aria-keyshortcuts (e.g. "Control+Z"). The app handles the key itself.

  • ActionTitle string
    = null

    Tooltip of the Action button, e.g. "Undo (Ctrl+Z)".

  • Class string
    = null

    Extra CSS classes merged onto this toast's alert element, after AlertClass.

  • FocusAction bool
    = false

    Move keyboard focus to the Action button when the toast appears. Pair it with ReturnFocus.

  • HideIcon bool
    = false

    Show no icon on the toast.

  • Icon string
    = null

    Icon shown instead of the severity icon (an Icons.Material.* name).

  • OnAction Func<Task>
    = null

    Raised when the Action button is clicked; the toast then closes.

  • PreventDuplicates bool
    = true

    When true, an identical message will not be added again while it is still shown.

  • ReturnFocus ElementReference?
    = null

    Element that gets focus back when the toast closes while it held focus (e.g. after its action button was clicked); otherwise focus would fall to the page body.

  • ShowCloseIcon bool
    = true

    Show a manual close button on the toast.

  • ShowProgress bool
    = false

    Show a bar with the time left before the toast auto-dismisses (it pauses with the countdown).

  • Variant Variant?
    = null

    Alert style of this toast: Filled is solid, Outlined adds alert-outline, Text adds alert-soft. When null (default), the toast uses Variant.

  • VisibleStateDuration int
    = 5000

    How long (ms) the toast stays visible before it auto-dismisses. When not set, the toast uses VisibleStateDuration (5000 by default).

From MudSnackbarProvider

SnackbarProvider keeps MudSnackbarProvider's parameter names, so most markup moves over by dropping the Mud prefix. See the migration guide for the shared enums, icons and services.

Mount <SnackbarProvider /> once in your layout. Snackbar.Add(message, severity, configure) keeps MudBlazor's signature.

<MudSnackbarProvider> <SnackbarProvider>
Something went wrong while running the docs. Reload