# Alert Dialog
> Confirmation dialog requiring explicit user action
Source: https://shellui.dev/docs/v0.3/components/advanced/alert-dialog
The AlertDialog component presents a modal dialog that interrupts the user to confirm a destructive or important action. Unlike a standard Dialog, it requires an explicit confirm or cancel — clicking outside does not dismiss it.
## Installation
```bash
shellui add alert-dialog
```
## Basic Usage
```razor
@code {
private bool isOpen = false;
private void HandleConfirm()
{
// Perform destructive action
isOpen = false;
}
private void HandleCancel()
{
isOpen = false;
}
}
```
## Custom Button Text
Customize the confirm and cancel button labels:
```razor
@code {
private bool isOpen = false;
private void HandleDiscard() => isOpen = false;
}
```
## Destructive Confirm Variant
Style the confirm button as destructive:
```razor
@code {
private bool isOpen = false;
private void HandleDelete() => isOpen = false;
}
```
## Non-Destructive Confirmation
Use for important but non-destructive actions:
```razor
@code {
private bool isOpen = false;
private void HandlePublish() => isOpen = false;
}
```
## Async Confirm
Handle async operations on confirm:
```razor
@code {
private bool isOpen = false;
private string memberName = "John Doe";
private async Task HandleRemoveAsync()
{
await Task.Delay(500); // e.g. await TeamService.RemoveMemberAsync(memberName);
isOpen = false;
}
}
```
## API Reference
| Property | Type | Default | Description |
|----------|------|---------|-------------|
| `IsOpen` | `bool` | `false` | Controls dialog visibility |
| `IsOpenChanged` | `EventCallback` | — | Callback when open state changes |
| `Title` | `string` | — | Dialog title (required) |
| `Description` | `string` | — | Dialog description (required) |
| `ConfirmText` | `string` | `"Continue"` | Confirm button label |
| `CancelText` | `string?` | `"Cancel"` | Cancel button label |
| `ConfirmVariant` | `ButtonVariant` | `ButtonVariant.Default` | Confirm button style variant |
| `OnConfirm` | `EventCallback` | — | Callback when user confirms |
| `OnCancel` | `EventCallback` | — | Callback when user cancels |
## Accessibility
The AlertDialog component includes:
- `role="alertdialog"` with `aria-modal="true"`
- Focus trap — Tab cycles within the dialog
- Escape key triggers cancel (not dismiss)
- Focus moves to cancel button on open (safer default)
- Focus returns to trigger on close
- Screen reader announces title and description