navius

Dialog

A window overlaid on either the primary window or another dialog window, rendering the content underneath inert.

Features

  • Can be controlled (@bind-Open) or uncontrolled (DefaultOpen).
  • Backdrop and popup portal to document.body, escaping ancestor clipping and stacking contexts.
  • When modal, focus is trapped inside the content and page scroll is locked.
  • Dismiss on Escape and on pointer-down outside, each through a cancelable callback.
  • Focus is moved into the dialog on open and restored to the trigger on close.
  • aria-labelledby / aria-describedby are wired only when a Title / Description is mounted.

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 a dialog. Owns the open state and cascades context to the parts; renders no DOM of its own.

Prop Type Default
Open bool false
OpenChanged EventCallback<bool> -
DefaultOpen bool false
Modal bool true
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 document.body (or a Container). Renders no DOM of its own.

Prop Type Default
Container string? -
ForceMount bool false
ChildContent RenderFragment? -

The dimmed backdrop behind the popup. Portaled to document.body; renders a div.

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 panel that contains the dialog content. Self-portaled to document.body; renders a div with role=dialog.

Prop Type Default
KeepMounted bool false
OnOpenAutoFocus EventCallback<NaviusOpenAutoFocusEventArgs> -
OnCloseAutoFocus EventCallback<NaviusCloseAutoFocusEventArgs> -
OnEscapeKeyDown EventCallback<NaviusEscapeKeyDownEventArgs> -
OnPointerDownOutside EventCallback<NaviusPointerDownOutsideEventArgs> -
OnInteractOutside EventCallback<NaviusInteractOutsideEventArgs> -
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 title announced when the dialog opens. aria-labelledby points here. Renders an h2.

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

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

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

A button that closes the dialog. Lives inside the content. Renders a button.

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

Accessibility

Adheres to the Dialog (Modal) WAI-ARIA design pattern.

A dialog requires an accessible name. Always render a NaviusDialogTitle; if you do not want it shown, wrap it in NaviusVisuallyHidden.

Key Description
Space Opens or closes the dialog when focus is on the trigger.
Enter Opens or closes the dialog when focus is on the trigger.
Tab Moves focus to the next focusable element inside the content. Focus is trapped when modal.
Shift + Tab Moves focus to the previous focusable element inside the content.
Escape Closes the dialog and returns focus to the trigger.