General
Alert
Usage#
import { WdsAlertComponent } from '@wds/angular/alert';Examples#
Default#
import { Component } from '@angular/core';
import { WdsAlertComponent } from '@wds/angular/alert';
import '@wds/core/icons/lucide/check-circle-2';
import '@wds/core/icons/lucide/info';
@Component({
selector: 'app-alert-default-demo',
imports: [WdsAlertComponent],
template: `
<div class="flex w-full max-w-md flex-col gap-4">
<wds-alert heading="Payment successful" description="Your payment of $29.99 has been processed. A receipt has been sent to your email address." icon="lucide-check-circle-2"></wds-alert>
<wds-alert heading="New feature available" description="We've added dark mode support. You can enable it in your account settings." icon="lucide-info"></wds-alert>
</div>
`,
})
export class AlertDefaultDemo {}Destructive#
variant="destructive" uses the error color and adds a default icon; icon sets another one.
import { Component } from '@angular/core';
import { WdsAlertComponent } from '@wds/angular/alert';
@Component({
selector: 'app-alert-destructive-demo',
imports: [WdsAlertComponent],
template: `
<div class="flex w-full max-w-md flex-col">
<wds-alert variant="destructive" heading="Payment failed" description="Your payment could not be processed. Please check your payment method and try again."></wds-alert>
</div>
`,
})
export class AlertDestructiveDemo {}Action#
action slot places a control on the right, vertically centered. With an action the alert gets role="status".
import { Component } from '@angular/core';
import { WdsAlertComponent } from '@wds/angular/alert';
import { WdsButtonComponent } from '@wds/angular/button';
@Component({
selector: 'app-alert-action-demo',
imports: [WdsAlertComponent, WdsButtonComponent],
template: `
<div class="flex w-full max-w-md flex-col">
<wds-alert heading="Dark mode is now available" description="Enable it under your profile settings to get started.">
<wds-button slot="action" size="xs">Enable</wds-button>
</wds-alert>
</div>
`,
})
export class AlertActionDemo {}Custom colors#
base part: set its color with ::part(base) or with --wds-alert-border-color.
import { Component } from '@angular/core';
import { WdsAlertComponent } from '@wds/angular/alert';
import '@wds/core/icons/lucide/triangle-alert';
@Component({
selector: 'app-alert-custom-colors-demo',
imports: [WdsAlertComponent],
template: `
<div class="flex w-full max-w-md flex-col">
<wds-alert
class="bg-amber-50 text-amber-900 dark:bg-amber-950 dark:text-amber-50 [&::part(base)]:border-amber-200 dark:[&::part(base)]:border-amber-900"
heading="Your subscription will expire in 3 days"
description="Renew now to avoid service interruption or upgrade to a paid plan to continue using the service."
icon="lucide-triangle-alert"
></wds-alert>
</div>
`,
})
export class AlertCustomColorsDemo {}API References#
wds-alert#
status with an action, alert otherwise.
A role attribute set on the element takes precedence.
Background and text color are on the host, so a class or a style on the element changes them;
the border color is --wds-alert-border-color.
Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
| variant | WdsAlertVariant | 'default' | destructive uses the error color and adds an icon. |
| icon | string | undefined | destructive variant has a default icon. The name of a registered icon, e.g. lucide-info (after import '@wds/core/icons/lucide/info'). | |
| heading | string | '' | title slot takes precedence. |
| description | string | '' |
Slots
| Slot | Description |
|---|---|
| (default) | description), e.g. with links or paragraphs. |
| icon | icon (SVG, 16px). |
| title | heading). |
| action | wds-button size="xs"). |
CSS parts (::part)
| Part | Description |
|---|---|
| base | |
| icon | |
| title | |
| description | |
| action |
CSS custom properties
| Property | Description |
|---|---|
| --wds-alert-border-color | --wds-border). |
| --wds-alert-description-color | --wds-muted-foreground, the error color in destructive). |
Accessibility#
Screen reader#
wds-alert sets its own role: alert by default, so screen readers announce it when it appears, and status when the action slot is filled. A role you set on the element takes precedence.
destructive variant is hidden from screen readers; give your own icon in the icon slot aria-hidden="true".
Keyboard support#
action slot and links in the description follow the page tab sequence.