Blazor Toast Overview

    The Blazor 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 Blazor 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 Blazor 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.

    Blazor Toast Example

    Take a look at the simple Ignite UI for Blazor Toast example below. The animated notification message pops up after clicking on the button.

    How To Use Ignite UI for Blazor Toast Notification

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

    // in Program.cs file
    
    builder.Services.AddIgniteUIBlazor(typeof(IgbToastModule));
    

    For a complete introduction to the Ignite UI for Blazor, read the Getting Started topic.

    You will also need to link an additional CSS file to apply the styling to the IgbCalendar component. The following needs to be placed in the wwwroot/index.html file in a Blazor Web Assembly project or the Pages/_Host.cshtml file in a Blazor Server project:

    <link href="_content/IgniteUI.Blazor/themes/light/bootstrap.css" rel="stylesheet" />
    
    <IgbButton @onclick=@OnToastButtonClick Variant=@ButtonVariant.Contained>Show Toast</IgbButton>
    <IgbToast @ref="ToastRef">Toast Message</IgbToast>
    
    @code {
        public IgbToast ToastRef { get; set; }
    
        protected override void OnInitialized()
        {
        }
    
        public void OnToastButtonClick(MouseEventArgs args)
        {
            if (this.ToastRef != null)
            {
                this.ToastRef.Show();
            }
        }
    }
    

    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.

    <IgbButton @onclick=@OnToggleToastButtonClick Variant="ButtonVariant.Contained">Toggle Toast</IgbButton>
    <IgbButton @onclick=@OnToggleKeepOpenButtonClick Variant="ButtonVariant.Contained">Toggle KeepOpen Property</IgbButton>
    <IgbButton @onclick=@OnDisplayTimeButtonClick Variant="ButtonVariant.Contained">Set DisplayTime to 8000</IgbButton>
    
    <IgbToast @ref=ToastRef>Toast Message</IgbToast>
    
    @code {
        public IgbToast ToastRef{  get;  set; }
    
        protected override void OnInitialized()
        {
        }
    
        public void OnToggleToastButtonClick(MouseEventArgs args)
        {
            if (this.ToastRef != null)
            {
                this.ToastRef.Toggle();
            }
        }
    
        public void OnToggleKeepOpenButtonClick(MouseEventArgs args)
        {
            if (this.ToastRef != null)
            {
                this.ToastRef.KeepOpen = !this.ToastRef.KeepOpen;
            }
        }
    
        public void OnDisplayTimeButtonClick(MouseEventArgs args)
        {
            if (this.ToastRef != null)
            {
                this.ToastRef.DisplayTime = 8000;
            }
        }
    }
    

    Styling

    You can style the Blazor IgbToast notifications directly using its tag selector:

    igc-toast {
        background: #011627;
        color: #ECAA53;
        outline-color: #ECAA53;
    }
    

    API References

    Additional Resources