Feedback
Alert Dialog
Usage#
import { WdsAlertDialogComponent } from '@wds/angular/alert-dialog';Examples#
Default#
show() opens the dialog, and the buttons in the footer slot close it with close(). There is no close button and a click on the backdrop does nothing; Escape works like Cancel. The first button (Cancel) gets focus.
import { Component } from '@angular/core';
import { WdsAlertDialogComponent } from '@wds/angular/alert-dialog';
import { WdsButtonComponent } from '@wds/angular/button';
@Component({
selector: 'app-alert-dialog-default-demo',
imports: [WdsAlertDialogComponent, WdsButtonComponent],
template: `
<wds-button variant="outline" (click)="dialog.show()">Show dialog</wds-button>
<wds-alert-dialog
#dialog
heading="Are you absolutely sure?"
description="This action cannot be undone. This will permanently delete your account and remove your data from our servers."
>
<wds-button slot="footer" variant="outline" (click)="dialog.close()">Cancel</wds-button>
<wds-button slot="footer" (click)="dialog.close()">Continue</wds-button>
</wds-alert-dialog>
`,
})
export class AlertDialogDefaultDemo {}Small with media#
size="sm" makes a narrow, centered dialog with the buttons side by side. An icon in the media slot shows above the title.
import { Component } from '@angular/core';
import { WdsAlertDialogComponent } from '@wds/angular/alert-dialog';
import { WdsButtonComponent } from '@wds/angular/button';
@Component({
selector: 'app-alert-dialog-small-demo',
imports: [WdsAlertDialogComponent, WdsButtonComponent],
template: `
<wds-button variant="outline" (click)="dialog.show()">Connect accessory</wds-button>
<wds-alert-dialog
#dialog
size="sm"
heading="Allow accessory to connect?"
description="Do you want to allow the USB accessory to connect to this device?"
>
<svg slot="media" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m7 7 10 10-5 5V2l5 5L7 17" /></svg>
<wds-button slot="footer" variant="outline" (click)="dialog.close()">Don't allow</wds-button>
<wds-button slot="footer" (click)="dialog.close()">Allow</wds-button>
</wds-alert-dialog>
`,
})
export class AlertDialogSmallDemo {}Destructive#
destructive button for an action that deletes data. Cancel stays first, so a quick Enter does not delete anything.
import { Component } from '@angular/core';
import { WdsAlertDialogComponent } from '@wds/angular/alert-dialog';
import { WdsButtonComponent } from '@wds/angular/button';
@Component({
selector: 'app-alert-dialog-destructive-demo',
imports: [WdsAlertDialogComponent, WdsButtonComponent],
template: `
<wds-button variant="destructive" (click)="dialog.show()">Delete chat</wds-button>
<wds-alert-dialog
#dialog
size="sm"
heading="Delete chat?"
description="This will permanently delete this chat conversation. View Settings to delete any memories saved during this chat."
>
<svg slot="media" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 6h18" /><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6" /><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2" /><line x1="10" x2="10" y1="11" y2="17" /><line x1="14" x2="14" y1="11" y2="17" /></svg>
<wds-button slot="footer" variant="outline" (click)="dialog.close()">Cancel</wds-button>
<wds-button slot="footer" variant="destructive" (click)="dialog.close()">Delete</wds-button>
</wds-alert-dialog>
`,
})
export class AlertDialogDestructiveDemo {}Service#
WdsAlertDialogService.open() builds the dialog from the config: title, description, cancelText / okText, okDestructive and size. closed emits true after OK and undefined after Cancel or Escape; content (content, data) works as in WdsDialogService. HTML and React have no service, so their tabs show the same dialog declared in the markup.
import { Component, inject, signal } from '@angular/core';
import { WdsAlertDialogService } from '@wds/angular/alert-dialog';
import { WdsButtonComponent } from '@wds/angular/button';
@Component({
selector: 'app-alert-dialog-service-demo',
imports: [WdsButtonComponent],
template: `
<div class="flex flex-wrap items-center justify-center gap-3">
<wds-button variant="outline" (click)="confirm()">Discard draft</wds-button>
<span class="text-sm text-muted-foreground">Result: {{ result() }}</span>
</div>
`,
})
export class AlertDialogServiceDemo {
private readonly alerts = inject(WdsAlertDialogService);
protected readonly result = signal('none');
protected confirm(): void {
this.alerts
.open<unknown, boolean>({
title: 'Discard draft?',
description: 'Your changes to this message will be lost.',
cancelText: 'Keep editing',
okText: 'Discard',
okDestructive: true,
})
// OK closes with true; Cancel and Escape with undefined.
.closed.subscribe((ok) => this.result.set(ok ? 'discarded' : 'kept'));
}
}API References#
wds-alert-dialog#
role="alertdialog"). It has no close button and a click on the backdrop does not
close it: the user answers with the buttons in the footer slot. Escape works like Cancel.
Put the safe action (Cancel) first in the footer: the dialog focuses the first button when it opens.
Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
| size | WdsAlertDialogSize | 'default' | sm: a narrow, centered dialog with the buttons side by side. |
| open | boolean | false | show() and close(). |
| heading | string | '' | heading slot). |
| description | string | '' | description slot), linked as aria-describedby. |
| hide-close.hideClose | boolean | false | |
| static-backdrop.staticBackdrop | boolean | false | |
| dismissible | boolean | true | false blocks closing with Escape, the backdrop (and dragging in a drawer). |
| close-label.closeLabel | string | 'Zamknij' |
Events
| Event | Description |
|---|---|
| wds-closeCustomEvent<void> | close(), Escape), before the exit animation. |
| wds-after-closeCustomEvent<void> |
Methods
| Method | Description |
|---|---|
| show() | |
| close() |
Slots
| Slot | Description |
|---|---|
| (default) | |
| heading | heading attribute). |
| description | description attribute). |
| media | |
| footer |
CSS parts (::part)
| Part | Description |
|---|---|
| dialog | <dialog>. |
| panel | |
| header | |
| media | |
| title | |
| description | |
| body | |
| footer |
CSS custom properties
| Property | Description |
|---|---|
| --wds-dialog-width | size="sm" 20rem). |
Accessibility#
Screen reader#
role="alertdialog" named by heading and described by description (aria-labelledby, aria-describedby), so screen readers read the question when it opens.
media slot is decorative: give it aria-hidden="true" and say everything in the title and the description.
Keyboard support#
| Key | Function |
|---|---|