Feedback
TwAlert
TwAlert is a Blazor alert component for status messages. Set Color, Dense, StartIcon and EndIcon, and make it Dismissible with a bindable Dismissed value.
Last updated
Alert
Provide contextual feedback messages for typical user actions with the handful of available and flexible alert messages.
This is an example alert with a link.
RAZOR
<TwAlert Id="example-alert" Class="mt-2" Color="Color.Accent">
<p>This is an example alert with a <a href="/alert" class="underline m-0 p-0 inline">link</a>.</p>
</TwAlert>Colors
TwAlert supports all the standard theme colors via the
Color property.Primary
Accent
Success
Danger
Warning
Info
Light
Dark
RAZOR
@foreach (Color c in ((Color[])Enum.GetValues(typeof(Color))).Take(10))
{
<TwAlert Id="@($"{c.ToString()}-alert")" Class="mt-2" Color="@c" Dense>
@c.ToString()
</TwAlert>
}Announcements
A screen reader announces an alert when it appears. An error or a warning (
Color.Danger,
Color.Warning) interrupts with role="alert"; every other color waits its turn with
role="status". Set Role to choose for yourself, or to none for an alert that
is part of the page from the start and should be read in place like any other content.
Saved. Announced when the screen reader is idle.
Payment failed. Announced at once.
Prices include tax. Read in place, never announced.
RAZOR
<TwAlert Id="status-alert" Class="mt-2" Color="Color.Success" Dense>Saved. Announced when the screen reader is idle.</TwAlert>
<TwAlert Id="urgent-alert" Class="mt-2" Color="Color.Danger" Dense>Payment failed. Announced at once.</TwAlert>
<TwAlert Id="static-alert" Class="mt-2" Color="Color.Info" Role="none" Dense>Prices include tax. Read in place, never announced.</TwAlert>Dense alerts
You can also make alerts dense and take up less space using the
Dense property.
This is a dense alert.
This is another dense alert.
RAZOR
<div class="grid grid-cols-1 md:grid-cols-2 mb-2 gap-2">
<TwAlert Id="dense-alert-1" Class="mt-2" Color="Color.Success" Dense>
This is a dense alert.
</TwAlert>
<TwAlert Id="dense-alert-2" Class="mt-2" Color="Color.Warning" Dense>
This is another dense alert.
</TwAlert>
</div>Alert icons
TwAlert also supports easy icons parameters
StartIcon and EndIcon. A small padding separates each icon from the text; override it with StartIconPadding and EndIconPadding.
This is a dense alert with a start icon.
This is another dense alert with an end icon.
This is an alert with a start icon.
This is another alert with an end icon.
RAZOR
<div class="grid grid-cols-1 md:grid-cols-2 gap-2">
<TwAlert Id="icon-alert-1" Class="mt-2" Color="Color.Primary" Dense StartIcon="Icon.Wallet">
This is a dense alert with a start icon.
</TwAlert>
<TwAlert Id="icon-alert-2" Class="mt-2" Color="Color.Danger" Dense EndIcon="Icon.Exclamation_Circle">
This is another dense alert with an end icon.
</TwAlert>
<TwAlert Id="icon-alert-3" Class="mt-2" Color="Color.Info" StartIcon="Icon.Play">
This is an alert with a start icon.
</TwAlert>
<TwAlert Id="icon-alert-4" Class="mt-2" Color="Color.Warning" EndIcon="Icon.Star">
This is another alert with an end icon.
</TwAlert>
</div>Dismissible alerts
You can also make alerts dismissible by using
OnDismiss or the Dismissible property set as true, setting Dismissible to true will show the X button and won't require an event callback.
This is a dense alert that is dismissible.
Theme configuration
Styling is controlled by
TwBlazorTheme.Components (a TwAlertTheme), configured via the
AddTwBlazor() options callback described on the Get Started page.
Every property is a set of Tailwind classes, so changes are picked up by your own Tailwind build.
| Property | Type | Controls |
|---|---|---|
TextWrapper |
string | |
Padding |
string | |
DensePadding |
string | |
StartIconPadding |
string | |
EndIconPadding |
string | |
Transition |
string | |
DismissButtonSize |
string | |
DismissButtonSpacingWithEndIcon |
string | |
DismissButtonColor |
string |
Global Theme Configuration
These reuse shared design tokens configured once on
TwBlazorTheme, rather than being unique to this component.
| Property | Type | Controls |
|---|---|---|
Colors |
TwBlazorPalette |
Full reference: TwAlertTheme on the API docs.