Alert Dialog
A modal dialog that interrupts the user with important content and expects a response.
<NaviusAlertDialog @bind-Open="_open">
<NaviusAlertDialogTrigger class="...">Delete account</NaviusAlertDialogTrigger>
<NaviusAlertDialogBackdrop class="fixed inset-0 z-50 bg-black/80" />
<NaviusAlertDialogPopup
class="fixed left-1/2 top-1/2 z-50 -translate-x-1/2 -translate-y-1/2 ...">
<NaviusAlertDialogTitle class="text-lg font-semibold">
Are you absolutely sure?
</NaviusAlertDialogTitle>
<NaviusAlertDialogDescription class="text-sm text-muted-foreground">
This action cannot be undone. This will permanently delete your account.
</NaviusAlertDialogDescription>
<div class="flex justify-end gap-2">
<NaviusAlertDialogCancel class="...">Cancel</NaviusAlertDialogCancel>
<NaviusAlertDialogAction class="... bg-destructive">Continue</NaviusAlertDialogAction>
</div>
</NaviusAlertDialogPopup>
</NaviusAlertDialog>
@code { private bool _open; }Features
- Can be controlled (
@bind-Open) or uncontrolled (DefaultOpen). - Focus is trapped within the content while open and restored to the trigger on close.
- Initial focus lands on the
Cancelcontrol, so the destructive default is never the active target. - An interruption: outside-pointer clicks never dismiss it; only Escape, Cancel, or Action close it.
- Page scroll is locked while open.
- Self-portals to
document.bodyto escape ancestor overflow, transform, and z-index stacking contexts. -
role="alertdialog"wired to its title and description viaaria-labelledby/aria-describedby.
Installation
Install the brain, or copy just this primitive in with the CLI.
navius add alert-dialogAnatomy
Import the parts and assemble them.
@using Navius.Primitives.Components.AlertDialog
<NaviusAlertDialog>
<NaviusAlertDialogTrigger />
<NaviusAlertDialogBackdrop />
<NaviusAlertDialogPopup>
<NaviusAlertDialogTitle />
<NaviusAlertDialogDescription />
<NaviusAlertDialogCancel />
<NaviusAlertDialogAction />
</NaviusAlertDialogPopup>
</NaviusAlertDialog>API Reference
Root
Contains all the parts of an alert dialog. Owns the open state and renders no DOM of its own.
| Prop | Type | Default |
|---|---|---|
| Open | bool | false |
| OpenChanged | EventCallback<bool> | - |
| DefaultOpen | bool | false |
| ChildContent | RenderFragment? | - |
Trigger
The button that opens the dialog. Renders a button.
| Prop | Type | Default |
|---|---|---|
| ChildContent | RenderFragment? | - |
| Attributes | IDictionary<string, object>? | - |
Data attributes
| Data attribute | Values |
|---|---|
| [data-popup-open] | Present while the dialog is open. |
Portal
Optional wrapper that hoists the Backdrop and Popup to the portal target. Renders no DOM of its own.
| Prop | Type | Default |
|---|---|---|
| Container | string? | - |
| ForceMount | bool | false |
| ChildContent | RenderFragment? | - |
Backdrop
The backdrop layer. Purely visual: clicking it never closes the dialog. Renders a div, portaled to the body.
| Prop | Type | Default |
|---|---|---|
| KeepMounted | bool | false |
| Attributes | IDictionary<string, object>? | - |
Data attributes
| Data attribute | Values |
|---|---|
| [data-open] | Present while open. |
| [data-closed] | Present while closing (through the exit transition). |
| [data-starting-style] | Present at the start of the open transition. |
| [data-ending-style] | Present at the start of the close transition. |
Popup
The focus-trapped panel. Renders a div with role="alertdialog", self-portaled to the body.
| Prop | Type | Default |
|---|---|---|
| KeepMounted | bool | false |
| OnOpenAutoFocus | EventCallback<NaviusOpenAutoFocusEventArgs> | - |
| OnCloseAutoFocus | EventCallback<NaviusCloseAutoFocusEventArgs> | - |
| OnEscapeKeyDown | EventCallback<NaviusEscapeKeyDownEventArgs> | - |
| ChildContent | RenderFragment? | - |
| Attributes | IDictionary<string, object>? | - |
Data attributes
| Data attribute | Values |
|---|---|
| [data-open] | Present while open. |
| [data-closed] | Present while closing (through the exit transition). |
| [data-starting-style] | Present at the start of the open transition. |
| [data-ending-style] | Present at the start of the close transition. |
Title
An accessible name for the dialog (aria-labelledby points here). Renders an h2.
| Prop | Type | Default |
|---|---|---|
| ChildContent | RenderFragment? | - |
| Attributes | IDictionary<string, object>? | - |
Description
An accessible description for the dialog (aria-describedby points here). Renders a p.
| Prop | Type | Default |
|---|---|---|
| ChildContent | RenderFragment? | - |
| Attributes | IDictionary<string, object>? | - |
Cancel
The cancelling action. Closes the dialog and receives initial focus. Renders a button.
| Prop | Type | Default |
|---|---|---|
| ChildContent | RenderFragment? | - |
| Attributes | IDictionary<string, object>? | - |
Action
The confirming action. Closes the dialog. Renders a button.
| Prop | Type | Default |
|---|---|---|
| ChildContent | RenderFragment? | - |
| Attributes | IDictionary<string, object>? | - |
Accessibility
Adheres to the alert dialog WAI-ARIA design pattern. Unlike a plain dialog, focus opens on the least destructive control and a click outside never dismisses it.
Keyboard interactions
| Key | Description |
|---|---|
| Space | When focus is on the trigger, opens the dialog. When on Cancel or Action, activates it. |
| Enter | When focus is on the trigger, opens the dialog. When on Cancel or Action, activates it. |
| Tab | Moves focus to the next focusable element; focus is trapped within the content. |
| Shift + Tab | Moves focus to the previous focusable element; focus is trapped within the content. |
| Escape | Closes the dialog and returns focus to the trigger. |