Blazorise Snackbar component

Snackbars provide brief messages about app processes. The component is also known as a toast.

The snackbar extension is composed of several components:

  • <Snackbar> main snackbar component
    • <SnackbarBody> container for the snackbar content
    • <SnackbarAction> snackbar action button

To use the Snackbar component, install the Blazorise.Snackbar package first.

Snackbar has its own default styling and is not provider-native. If the application does not define theme color variables, Snackbar falls back to its bundled colors. Defining Theme.ColorOptions, including new() without explicit color assignments, enables the default Blazorise theme colors and generates Snackbar color variables.

Installation

NuGet

Install extension from NuGet.
Install-Package Blazorise.Snackbar

Imports

In your main _Imports.razor add:
@using Blazorise.Components
@using Blazorise.Snackbar

Static files

Include CSS link into your index.html or _Layout.cshtml / _Host.cshtml file, depending if you're using a Blazor WebAssembly or Blazor Server side project.
<link href="_content/Blazorise.Snackbar/blazorise.snackbar.css" rel="stylesheet" />

Basic example

A basic snackbar that aims to reproduce standard snackbar behavior.
Single line of text directly related to the operation performed
<Button Clicked="@(()=>snackbar.Show())">Snackbar</Button>

<Snackbar @ref="snackbar">
    <SnackbarBody>
        Single line of text directly related to the operation performed
    </SnackbarBody>
</Snackbar>
@code{
    Snackbar snackbar;
}

Variant snackbars

You can also define variant colors to override default snackbar style.
Single line of text directly related to the operation performed
Single line of text directly related to the operation performed
<Button Color="Color.Primary" Clicked="@(()=>snackbarPrimary.Show())">Primary</Button>
<Button Color="Color.Secondary" Clicked="@(()=>snackbarSecondary.Show())">Secondary</Button>

<Snackbar @ref="snackbarPrimary" Color="SnackbarColor.Primary">
  <SnackbarBody>
    Single line of text directly related to the operation performed
    <SnackbarAction Clicked="@(()=>snackbarPrimary.Hide())">ACTION</SnackbarAction>
  </SnackbarBody>
</Snackbar>
<Snackbar @ref="snackbarSecondary" Color="SnackbarColor.Secondary">
  <SnackbarBody>
    Single line of text directly related to the operation performed
    <SnackbarAction Clicked="@(()=>snackbarSecondary.Hide())">ACTION</SnackbarAction>
  </SnackbarBody>
</Snackbar>
@code{
    private Snackbar snackbarPrimary;
    private Snackbar snackbarSecondary;
}

Stacked snackbars

When you want to show multiple snackbars stacked on top of each other you can use a wrapper component SnackbarStack. You can specify Action<SnackbarOptions> options when calling PushAsync() in order to specify the Snackbar parameters available below.
<Button Color="Color.Primary" Clicked="@(()=>snackbarStack.PushAsync("Current time is: " + DateTime.Now, SnackbarColor.Info))">Primary</Button>

<Button Color="Color.Info" Clicked="@(()=>snackbarStack.PushAsync("Some info message! Timeout: " + intervalBeforeMsgClose, SnackbarColor.Info, options => {  options.IntervalBeforeClose = intervalBeforeMsgClose; } ))">Show Info</Button>

<SnackbarStack @ref="snackbarStack" Location="SnackbarStackLocation.BottomEnd" />
@code{
    SnackbarStack snackbarStack;
    double intervalBeforeMsgClose = 2000;
}

API

Parameters

Parameter Description TypeDefault
AnimationDuration

Specifies the base animation duration in milliseconds.

double0
ChildContent

Specifies the content to be rendered inside this Snackbar.

RenderFragmentnull
Color

Specifies the snackbar color.

Possible values:Default, Primary, Secondary, Success, Danger, Warning, Info, Light, Dark

SnackbarColorSnackbarColor.Default
DelayCloseOnClick

If clicked on snackbar, a close action will be delayed by increasing the Interval time.

boolfalse
DelayCloseOnClickInterval

Specifies the interval (in milliseconds) by which the snackbar will be delayed from closing.

double?null
Interval

Specifies the interval (in milliseconds) after which the snackbar will be automatically closed.

double0
Key

Unique key associated by this snackbar.

string
Location

Specifies the snackbar location.

Possible values:Default, Bottom, BottomStart, BottomEnd, Top, TopStart, TopEnd

SnackbarLocationSnackbarLocation.Default
Multiline

Allow snackbar to show multiple lines of text.

boolfalse
Visible

Specifies the visibility of snackbar.

boolfalse

Events

Event Description Type
Closed

Occurs after the snackbar has closed.

EventCallback<SnackbarClosedEventArgs>

Methods

Method DescriptionReturnParameters
Hide Hides the snackbar. Task
Show Shows the snackbar. Task
On this page