navius

Menu

Displays a menu to the user, such as a set of actions or functions, triggered by a button.

Features

  • Can be controlled (@bind-Open) or uncontrolled (DefaultOpen).
  • Supports submenus with their own independent open state.
  • Supports items, group labels, separators, checkbox items and radio groups.
  • Full keyboard navigation with roving focus and typeahead.
  • Focus is fully managed: opening focuses the first item, closing returns focus to the trigger.
  • Dismisses on Escape, outside pointer-down, and selecting an item (cancelable via OnSelect).
  • The engine self-portals the Popup to document.body to escape clipping and stacking ancestors.
  • Direction-aware: flips submenu open/close arrow keys in RTL.

Installation

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

Anatomy

Import the parts and assemble them. The Positioner and Popup replace the former Content; the Popup self-portals.

API Reference

Contains all the parts of a menu. Owns the open state and renders no DOM of its own.

Prop Type Default
Open bool false
OpenChanged EventCallback<bool> -
DefaultOpen bool false
Modal bool true
Dir string? -
ChildContent RenderFragment? -

The button that toggles the menu. By default it has aria-haspopup, aria-expanded and aria-controls wired to the popup. Renders a button.

Prop Type Default
Disabled bool false
ChildContent RenderFragment? -
Data attribute Values
[data-popup-open] Present while the menu is open.
[data-disabled] Present when disabled.

Owns placement (side / align / offsets / collision). A flag-setter that publishes the placement options; the Popup renders the positioning element the engine anchors to the trigger and writes data-side / data-align + --anchor-* onto.

Prop Type Default
Side string "bottom"
Align string "center"
SideOffset double 0
AlignOffset double 0
Flip bool true
AvoidCollisions bool true
CollisionPadding double? -
ArrowPadding double 0
ChildContent RenderFragment? -

The menu surface, self-portaled and anchored to the trigger. Mounted while open (kept mounted through its exit transition). Renders a div with role=menu.

Prop Type Default
Loop bool false
KeepMounted bool false
OnEscapeKeyDown EventCallback<NaviusEscapeKeyDownEventArgs> -
OnPointerDownOutside EventCallback<NaviusPointerDownOutsideEventArgs> -
ChildContent RenderFragment? -
Data attribute Values
[data-open] Present while the menu is open.
[data-closed] Present while closing (through the exit transition).
[data-starting-style] Present on the first committed open frame.
[data-ending-style] Present while animating out.
[data-side] "top" | "right" | "bottom" | "left"
[data-align] "start" | "center" | "end"

An optional arrow that the positioner keeps pointed at the trigger. Renders an svg.

Prop Type Default
Width double 10
Height double 5
ChildContent RenderFragment? -

A selectable menu item. Activates on click or Enter/Space, then closes the menu unless OnSelect prevents it. Renders a div with role=menuitem.

Prop Type Default
OnSelect EventCallback<NaviusSelectEventArgs> -
Disabled bool false
TextValue string? -
ChildContent RenderFragment? -
Data attribute Values
[data-highlighted] Present when the item is the roving-focus target.
[data-disabled] Present when disabled.

A wrapper that groups related items and is labelled by a GroupLabel child. Renders a div with role=group.

Prop Type Default
ChildContent RenderFragment? -

A non-interactive heading. When nested in a Group it labels that group via aria-labelledby. Renders a div.

Prop Type Default
ChildContent RenderFragment? -

An item that can be checked, unchecked or indeterminate. Cascades a state context the ItemIndicator reads. Renders a div with role=menuitemcheckbox.

Prop Type Default
Checked bool? -
CheckedChanged EventCallback<bool?> -
DefaultChecked bool? -
OnSelect EventCallback<NaviusSelectEventArgs> -
Disabled bool false
TextValue string? -
ChildContent RenderFragment? -
Data attribute Values
[data-checked] Present when checked.
[data-unchecked] Present when unchecked.
[data-indeterminate] Present when indeterminate.
[data-highlighted] Present when the item is the roving-focus target.
[data-disabled] Present when disabled.

Groups RadioItems and cascades the selected value. Renders a div with role=group.

Prop Type Default
Value string? -
ValueChanged EventCallback<string?> -
DefaultValue string? -
ChildContent RenderFragment? -

An item inside a RadioGroup; checked when the group's value equals its Value. Cascades a state context the ItemIndicator reads. Renders a div with role=menuitemradio.

Prop Type Default
Value string -
OnSelect EventCallback<NaviusSelectEventArgs> -
Disabled bool false
TextValue string? -
ChildContent RenderFragment? -
Data attribute Values
[data-checked] Present when checked.
[data-unchecked] Present when unchecked.
[data-highlighted] Present when the item is the roving-focus target.
[data-disabled] Present when disabled.

Renders the check or dot glyph for a CheckboxItem or RadioItem. Present only when the parent is checked (or indeterminate). Renders a span.

Prop Type Default
ForceMount bool false
ChildContent RenderFragment? -

A visual divider between items or groups. Renders a div with role=separator.

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

Contains the parts of a submenu. Owns its own nested open state and renders no DOM of its own.

Prop Type Default
Open bool false
OpenChanged EventCallback<bool> -
DefaultOpen bool false
ChildContent RenderFragment? -

An item inside the parent menu that opens a submenu on hover, ArrowRight (ArrowLeft in RTL) and Enter/Space. Anchors the submenu. Renders a div with role=menuitem.

Prop Type Default
Disabled bool false
TextValue string? -
ChildContent RenderFragment? -
Data attribute Values
[data-popup-open] Present while the submenu is open.
[data-highlighted] Present when the item is the roving-focus target.
[data-disabled] Present when disabled.

The floating submenu surface, self-portaled and positioned to the side of the SubTrigger. ArrowLeft (ArrowRight in RTL) and Escape close only this submenu. Renders a div with role=menu.

Prop Type Default
SideOffset double 0
AlignOffset double 0
Loop bool false
ForceMount bool false
ChildContent RenderFragment? -
Data attribute Values
[data-open] Present while the submenu is open.
[data-closed] Present while closing (through the exit transition).

Accessibility

Adheres to the menu button WAI-ARIA design pattern.

Key Description
Space When focus is on the trigger, opens the menu and focuses the first item. When on an item, activates it.
Enter When focus is on the trigger, opens the menu and focuses the first item. When on an item, activates it. On a SubTrigger, opens the submenu and focuses its first item.
ArrowDown When focus is on the trigger, opens the menu. When inside, moves focus to the next item.
ArrowUp When focus is on the trigger, opens the menu. When inside, moves focus to the previous item.
ArrowRight On a SubTrigger, opens its submenu and focuses the first item (ArrowLeft in RTL).
ArrowLeft Inside a submenu, closes it and returns focus to the SubTrigger (ArrowRight in RTL).
Esc Closes the menu (or the current submenu) and returns focus to the trigger.
Tab Items are not in the tab sequence; focus is managed with a roving tabindex.