React Toast - Show and Hide the Toast

API

NOTE
In this article, the Button UI component is used to demonstrate how to show and hide the Toast. This choice is made for purely demonstrational purposes, and you can do the same operations using another UI component following the same guidelines.

To show or hide the Toast programmatically, bind the visible property of the Toast to a component property. After that, change the latter property, and the Toast will appear or disappear.

HTML
TypeScript
  • <dx-toast
  • [(visible)]="isVisible"
  • type="error"
  • message="Connection problem">
  • </dx-toast>
  • <dx-button
  • text="Show the Toast"
  • (onClick)="isVisible = true">
  • </dx-button>
  • import { DxToastModule, DxButtonModule } from "devextreme-angular";
  • // ...
  • export class AppComponent {
  • isVisible: boolean = false;
  • }
  • @NgModule({
  • imports: [
  • DxButtonModule,
  • DxToastModule,
  • // ...
  • ],
  • // ...
  • })

User Interaction

Because the Toast is supposed to notify a user when something happens, it cannot be invoked from the UI. However, it may be hidden from the UI in many different ways. To decide which of them are available to the user, specify the following properties.

Property Description
closeOnClick Hides the Toast when a user clicks/presses it.
hideOnOutsideClick Hides the Toast when a user clicks/presses outside of it.
closeOnSwipe Hides the Toast when a user swipes it out of the screen.

Events

To execute certain commands before or after the Toast was shown/hidden, handle the showing, shown, hiding or hidden event. If the event handling function is not going to be changed during the lifetime of the UI component, assign it to the corresponding onEventName property:

HTML
TypeScript
  • <dx-toast ...
  • (onShowing)="onShowing($event)"
  • (onShown)="onShown($event)"
  • (onHiding)="onHiding($event)"
  • (onHidden)="onHidden($event)">
  • </dx-toast>
  • import { DxToastModule, DxButtonModule } from "devextreme-angular";
  • // ...
  • export class AppComponent {
  • onShowing (e) {
  • // Handler of the "showing" event
  • },
  • onShown (e) {
  • // Handler of the "shown" event
  • },
  • onHiding (e) {
  • // Handler of the "hiding" event
  • },
  • onHidden (e) {
  • // Handler of the "hidden" event
  • }
  • }
  • @NgModule({
  • imports: [
  • DxButtonModule,
  • DxToastModule,
  • // ...
  • ],
  • // ...
  • })
See Also