navius

Context Menu

Displays a menu located at the pointer, triggered by a right click or a long press.

Right click here

Features

  • Anchored to the pointer position, with collision-aware flipping and clamping.
  • Opens on right click, long press (touch), and the ContextMenu / Shift+F10 keys.
  • Supports submenus with configurable reading direction.
  • Supports items, labels, groups of items, checkbox items, and radio groups.
  • Full keyboard navigation with roving focus and type-ahead.
  • Dismissing and layering behavior is highly customizable.

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 context menu. Owns open state; renders no DOM.

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

The area that opens the context menu. Wrap the target and right-click within its bounds. Renders a div.

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

The menu surface that pops out when the context menu is open. Wrapped by the Positioner and self-portaled to the document body. Renders a div with role="menu". The Side / Align / SideOffset / AlignOffset / AvoidCollisions / CollisionPadding / Sticky / HideWhenDetached / ArrowPadding props are set on the enclosing Positioner.

Prop Type Default
Side string "right"
Align string "start"
SideOffset double 2
AlignOffset double 0
AvoidCollisions bool true
CollisionPadding double? -
Sticky string? -
HideWhenDetached bool false
ArrowPadding double 0
Loop bool false
Modal bool true
KeepMounted bool false
Container string? -
Dir string? -
OnEscapeKeyDown EventCallback<NaviusEscapeKeyDownEventArgs> -
OnPointerDownOutside EventCallback<NaviusPointerDownOutsideEventArgs> -
OnFocusOutside EventCallback<NaviusFocusOutsideEventArgs> -
OnInteractOutside EventCallback<NaviusInteractOutsideEventArgs> -
OnCloseAutoFocus EventCallback<NaviusCloseAutoFocusEventArgs> -
ChildContent RenderFragment? -
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.
[data-side] "left" | "right" | "top" | "bottom"
[data-align] "start" | "center" | "end"

The component that contains the context menu items. Renders a div.

Prop Type Default
Disabled bool false
TextValue string? -
OnSelect EventCallback<NaviusSelectEventArgs> -
ChildContent RenderFragment? -
Data attribute Values
[data-highlighted] Present when highlighted
[data-disabled] Present when disabled

Used to group multiple items. Renders a div with role="group".

Prop Type Default
ChildContent RenderFragment? -

Used to render a label. It won't be focusable using arrow keys. Renders a div.

Prop Type Default
ChildContent RenderFragment? -

An item that can be controlled and rendered like a checkbox. Renders a div.

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

Used to group multiple radio items. Renders a div with role="group".

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

An item that can be controlled and rendered like a radio. Renders a div.

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

Renders when the parent CheckboxItem or RadioItem is checked. You can style this element directly, or use it as a wrapper to put an icon into. Renders a span.

Prop Type Default
ForceMount bool false
ChildContent RenderFragment? -
Data attribute Values
[data-checked] Present when checked.
[data-unchecked] Present when unchecked.
[data-indeterminate] Present when in the indeterminate state.

Used to visually separate items in the context menu. Renders a div with role="separator".

Prop Type Default
- - -
Data attribute Values
[data-orientation] "horizontal"

An optional arrow element to render alongside the content. This can be used to help visually link the trigger point with the content. Renders an svg.

Prop Type Default
Width double 10
Height double 5

Contains all the parts of a submenu. Owns its own open state; renders no DOM.

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

An item that opens a submenu. Must be rendered inside a Sub. Renders a div.

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

The component that pops out when a submenu is open. Must be rendered inside a Sub. Renders a div.

Prop Type Default
Side string "right"
Align string "start"
SideOffset double 0
AlignOffset double 0
AvoidCollisions bool true
CollisionPadding double? -
Loop bool false
ForceMount bool false
Dir string? -
ChildContent RenderFragment? -
Data attribute Values
[data-open] Present while open.
[data-closed] Present while closing (through the exit transition).
[data-side] "left" | "right" | "top" | "bottom"
[data-align] "start" | "center" | "end"

Accessibility

Adheres to the menu WAI-ARIA design pattern (without typeahead support) and uses roving tabindex to manage focus movement among menu items.

Key Description
Space Activates the focused item.
Enter Activates the focused item.
ArrowDown Moves focus to the next item.
ArrowUp Moves focus to the previous item.
ArrowRight When focus is on a SubTrigger, opens the submenu and moves focus to its first item.
ArrowLeft When focus is inside a submenu, closes it and moves focus to the parent SubTrigger.
Home Moves focus to the first item.
End Moves focus to the last item.
Esc Closes the context menu and returns focus to the trigger.