Blazor Snackbar
The Ignite UI for Blazor Snackbar component is used to provide feedback about an operation by showing a brief message at the bottom of the screen.
Ignite UI for Blazor Snackbar Example
This sample demonstrates how to create IgbSnackbar component.
Usage
Register the Ignite UI for Blazor services:
// in Program.cs file
builder.Services.AddIgniteUIBlazor();
Registering IgbSnackbarModule, the client resource module of the IgbSnackbar, is optional: the component loads its resources when it first renders. Listing it in builder.Services.AddIgniteUIBlazor(typeof(IgbSnackbarModule)) can be used to preload resources or to support elements created only on the client (see Component Modules).
You will also need to link an additional CSS file to apply the styling to the IgbSnackbar component. The following needs to be placed in the app’s host page (wwwroot/index.html in a standalone Blazor WebAssembly or Blazor Hybrid app, Pages/_Host.cshtml in a Blazor Server app, Components/App.razor in a Blazor Web App):
<link href="_content/IgniteUI.Blazor/themes/light/bootstrap.css" rel="stylesheet" />
For a complete introduction to the Ignite UI for Blazor, read the Getting Started topic.
The simplest way to display the snackbar component is to use its Show method and call it on a button click.
<div class="container vertical">
<IgbButton onclick="snackbar.show()">Show Snackbar</IgbButton>
<IgbSnackbar id="snackbar"> Snackbar Message </IgbSnackbar>
</div>
Examples
Display Time
Use the DisplayTime property to configure how long the snackbar component is visible. By default, it’s set to 4000 milliseconds.
Action Text
By default, the snackbar component is hidden automatically after a period specified by the DisplayTime. You can use KeepOpen property to change this behavior. In this way, the snackbar will remain visible. Using the snackbar ActionText you can display an action button inside the component.
Styling
The IgbSnackbar component exposes several CSS parts to give you full control over its styling:
| Name | Description |
|---|---|
base |
The base wrapper of the snackbar component. |
message |
The snackbar message. |
action |
The default snackbar action button. |
action-container |
The area holding the actions. |
igc-snackbar::part(base) {
background: var(--ig-primary-500);
border-color: var(--ig-primary-800);
color: white;
}