Close
Angular React Web Components Blazor React
Open Source

React Snackbar

The Ignite UI for React Snackbar component is used to provide feedback about an operation by showing a brief message at the bottom of the screen.

Ignite UI for React Snackbar Example

This sample demonstrates how to create IgrSnackbar component.

Usage

First, you need to the install the corresponding Ignite UI for React npm package by running the following command:

npm install igniteui-react

You will then need to import the IgrSnackbar and its necessary CSS, like so:

import { IgrSnackbar } from 'igniteui-react';
import 'igniteui-webcomponents/themes/light/bootstrap.css';

Before using the IgrSnackbar, you need to register it as follows:

For a complete introduction to the Ignite UI for React, 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.

<IgrButton variant="contained" onClick={onShowButtonClicked}>
    <span>Show Snackbar</span>
</IgrButton>
<IgrSnackbar ref={snackbarRef}>
    <span>Snackbar Message</span>
</IgrSnackbar>

const snackbarRef = useRef<IgrSnackbar>(null);

const onShowButtonClicked = () => {
      if (snackbarRef) {
          snackbarRef.current.show();
      }
  }

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 IgrSnackbar component exposes several CSS parts to give you full control over its styling:

NameDescription
baseThe base wrapper of the snackbar component.
messageThe snackbar message.
actionThe default snackbar action button.
action-containerThe area holding the actions.
igc-snackbar::part(base) {
  background: var(--ig-primary-500);
  border-color: var(--ig-primary-800);
  color: white;
}

API References

Additional Resources