navius

Alert Dialog

A modal dialog that interrupts the user with important content and expects a response.

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 Cancel control, 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.body to escape ancestor overflow, transform, and z-index stacking contexts.
  • role="alertdialog" wired to its title and description via aria-labelledby / aria-describedby.

Installation

Install the brain, or copy just this primitive in with the CLI.

Anatomy

Import the parts and assemble them.

API Reference

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? -

The button that opens the dialog. Renders a button.

Prop Type Default
ChildContent RenderFragment? -
Attributes IDictionary<string, object>? -
Data attribute Values
[data-popup-open] Present while the dialog is open.

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? -

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 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.

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 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.

An accessible name for the dialog (aria-labelledby points here). Renders an h2.

Prop Type Default
ChildContent RenderFragment? -
Attributes IDictionary<string, object>? -

An accessible description for the dialog (aria-describedby points here). Renders a p.

Prop Type Default
ChildContent RenderFragment? -
Attributes IDictionary<string, object>? -

The cancelling action. Closes the dialog and receives initial focus. Renders a button.

Prop Type Default
ChildContent RenderFragment? -
Attributes IDictionary<string, object>? -

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.

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.