The React Toast is a super lightweight and small pop-up component that is used for displaying a message content, notifying end-users about the status of a changed record. You can easily position and show React toast notifications at the bottom or at any other specified area of the screen. Or you can also dismiss them in a simple and easy way.
The React Toast component is primarily used for system messaging, push notifications, warning messages, and information. It cannot be dismissed by the user. This control has different features like animation effects, display time property to configure how long the toast component is visible, styling, and others.
React Toast Example
Take a look at the simple Ignite UI for React Toast example below. The animated notification message pops up after clicking on the button.
For a complete introduction to the Ignite UI for React, read the Getting Started topic.
The simplest way to display the toast component is to use its show method and call it on a button click.
<IgrButtonvariant="contained"clicked={this.onShowButtonClicked}><span>Show Toast</span></IgrButton><IgrToastref={this.onToastRef}><span>Toast Message</span></IgrToast>public onToastRef(toast: IgrToast) {
if (!toast) { return; }
this.toastRef = toast;
}
public onShowButtonClicked() {
if (this.toastRef) {
this.toastRef.show();
}
}
tsx
Examples
Properties
Use the displayTime property to configure how long the toast component is visible. By default, it's set to 4000 milliseconds.
By default, the toast component is hidden automatically after a period specified by the displayTime. You can use keepOpen property to change this behavior. In this way, the toast will remain visible.
<div><IgrButtonvariant="contained"clicked={this.onToggleButtonClicked}><span>Toggle Toast</span></IgrButton><IgrButtonvariant="contained"clicked={this.onKeepOpenButtonClicked}><span>Toggle keepOpen Property</span></IgrButton><IgrButtonvariant="contained"clicked={this.onDisplayTimeButtonClicked}><span>Set DisplayTime to 8000</span></IgrButton></div><IgrToastref={this.onToastRef}><span>Toast Message</span></IgrToast>public onToastRef(toast: IgrToast) {
if (!toast) { return; }
this.toastRef = toast;
}
public onToggleButtonClicked() {
if (this.toastRef) {
this.toastRef.toggle();
}
}
public onKeepOpenButtonClicked() {
if (this.toastRef) {
this.toastRef.keepOpen = !this.toastRef.keepOpen;
}
}
public onDisplayTimeButtonClicked() {
if (this.toastRef) {
this.toastRef.displayTime = 8000;
}
}
tsx