Blazorise Alert component
Provide contextual feedback messages for typical user actions with the handful of available and flexible alert messages.
The <Alert> component is used to convey important information to the user through the use of contextual types, icons, and colors.
Overview
<Alert>the main container.<AlertMessage>the main content of the Alert.<AlertDescription>an optional description of the Alert.<CloseButton>an optional close button, which will hide the Alert.
When to use
- When you need to show alert messages to users.
- When you need a persistent static container which is closable by user actions.
Examples
Basic
<Alert Color="Color.Success" Visible> <AlertMessage>Well done!</AlertMessage> <AlertDescription>You successfully read this important alert message.</AlertDescription> </Alert>
Close button
You can also add aCloseButton.
<Alert Color="Color.Success" @bind-Visible=""> <AlertDescription> Lorem ipsum dolor sit amet, consectetur adipisicing elit. </AlertDescription> <AlertMessage> Alert Link. </AlertMessage> <CloseButton /> </Alert>
@code { bool visible = true; }
Extra content
<Alert> can also contain additional HTML elements like headings and paragraphs, which will be styled with the appropriate color matching the variant.
Big one!
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Cras mattis consectetur purus sit amet fermentum.
<Alert Color="Color.Info" @bind-Visible=""> <Heading Size="HeadingSize.Is4" TextColor="TextColor.Success"> Big one! <CloseButton /> </Heading> <Paragraph> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Cras mattis consectetur purus sit amet fermentum. </Paragraph> <Paragraph> <Button Color="Color.Info">Wanna do this</Button> <Button Color="Color.Light">Or do this</Button> </Paragraph> </Alert>
@code { bool visible = true; }
Usages
Two-way binding
To show alert just setVisible attribute to true.
<Alert Color="Color.Success" @bind-Visible=""> <AlertMessage> Alert test. </AlertMessage> </Alert> <Button Clicked="" Color="Color.Primary">Toggle alert</Button>
@code { bool visible = true; Task OnButtonClick() { visible = !visible; return Task.CompletedTask; } }
Programmatically
<Alert @ref="myAlert" Color="Color.Success"> <AlertMessage> Alert test. </AlertMessage> </Alert> <Button Clicked="" Color="Color.Primary">Show alert</Button>
@code{ Alert myAlert; Task OnButtonClick() { return myAlert.Show(); } }
Best Practices
Make Messages Actionable
Write a concise message that explains what happened and, when applicable, what the user should do next. Match the color to the message severity, but include meaningful text or an appropriate icon so color is not the only indication of status.
Feedback Pattern
Alerts are appropriate for information that belongs in the current page and may need to remain visible. Make an alert dismissible only when it can be safely ignored, and keep blocking errors visible until the problem is resolved. For brief feedback about a completed action, use a Toast instead.
API
See the API reference for the parameters, events, methods, and related types available to the components covered on this page.