Alert
<wa-alert>
Alerts are used to display important messages inline.
Unlike <wa-callout>, alerts are stateful and can be shown/hidden, optionally dismissed, and auto-hidden after a duration. Use alerts when the message lifecycle matters. Use callouts for static, always-visible messaging.
Alerts are only visible when the open attribute is present.
Examples
Variants
Set the variant attribute to change the alert's variant.
You can tell by how pretty the alert is.
You can safely exit the app now.
Settings will take effect on next login.
Please login again to continue.
We're very sorry to see you go!
Here's some additional information you might find useful.
Closable
Add the closable attribute to show a close button that will hide the alert.
Without Icons
Icons are optional. Simply omit the icon slot if you don't want them.
Duration
Set the duration attribute to automatically hide an alert after a period of time. This is useful for alerts that don't require acknowledgement. The timer pauses while the alert is hovered.
Importing
If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick a component manually, use one of the following snippets.
Import this component directly from the CDN:
import 'https://ka-f.webawesome.com/webawesome@0.17.0/components/alert/alert.js';
After installing Web Awesome via npm, import this component:
import '@awesome.me/webawesome/dist/components/alert/alert.js';
If you're self-hosting Web Awesome, import this component from your server:
import './webawesome/dist/components/alert/alert.js';
To import this component for React 18 or below, use the following code:
import WaAlert from '@awesome.me/webawesome/dist/react/alert/index.js';
Slots
Learn more about using slots.
| Name | Description |
|---|---|
| (default) | The alert's main content. |
close-icon
|
An optional close icon to use instead of the default. |
icon
|
An optional icon to show in the alert. Works best with <wa-icon>. |
Attributes & Properties
Learn more about attributes and properties.
| Name | Description | Reflects |
|---|---|---|
appearanceappearance |
The callout's visual appearance.
Type
'accent' | 'filled' | 'outlined' | 'plain' | 'filled-outlined'
|
|
closableclosable |
Makes the alert closable and shows the close button.
Type
boolean
Default
false
|
|
durationduration |
The amount of time, in milliseconds, to wait before closing the alert. Set to
Infinity to disable.Default
Infinity
|
|
openopen |
Indicates whether or not the alert is open. You can toggle this attribute to show and hide the alert.
Type
boolean
Default
false
|
|
sizesize |
The callout's size.
Type
'xs' | 's' | 'm' | 'l' | 'xl' | 'small' | 'medium' | 'large'
Default
'm'
|
|
variantvariant |
The callout's theme variant. Defaults to
brand if not within another element with a variant.
Type
'brand' | 'neutral' | 'success' | 'warning' | 'danger' | 'info'
Default
'brand'
|
|
Methods
Learn more about methods.
| Name | Description | Arguments |
|---|---|---|
hide() |
Hides the alert. | |
show() |
Shows the alert. |
Events
Learn more about events.
| Name | Description |
|---|---|
wa-after-hide |
Emitted after the alert closes and all animations are complete. |
wa-after-show |
Emitted after the alert opens and all animations are complete. |
wa-hide |
Emitted when the alert closes. |
wa-show |
Emitted when the alert opens. |
CSS Custom Properties
Learn more about CSS custom properties.
| Name | Description |
|---|---|
--hide-duration |
The hide duration to use when applying built-in animation classes.
Default
150ms
|
--show-duration |
The show duration to use when applying built-in animation classes.
Default
150ms
|
CSS Parts
Learn more about CSS parts.
| Name | Description | CSS selector |
|---|---|---|
close-button |
The alert's close button, a <wa-button>. |
::part(close-button)
|
close-button__base |
The close button's exported base part. |
::part(close-button__base)
|
icon |
The container that wraps the optional icon. |
::part(icon)
|
message |
The container that wraps the alert's main content. |
::part(message)
|
Dependencies
This component automatically imports the following elements. Sub-dependencies, if any exist, will also be included in this list.