navius

Select

Displays a list of options for the user to pick from, triggered by a button.

Features

  • Can be controlled (@bind-Value / @bind-Open) or uncontrolled (DefaultValue / DefaultOpen).
  • Full keyboard navigation with type-ahead and a roving listbox focus.
  • The listbox is portaled to <body> and collision-aware via the positioner engine.
  • Supports items, groups, labels, separators, a scrollable viewport, and an optional arrow.
  • The trigger shows the selected item's label (not the raw value key).
  • Renders a hidden native mirror so the select participates in form submission.
  • role="combobox" trigger and role="listbox" content per the APG.

Installation

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

Anatomy

Import the parts and assemble them.

API Reference

Owns the value and open state and cascades the context. Renders no visible DOM (plus an optional visually-hidden form mirror).

Prop Type Default
Value string? -
ValueChanged EventCallback<string?> -
DefaultValue string? -
Open bool false
OpenChanged EventCallback<bool> -
DefaultOpen bool false
Placeholder string? -
Disabled bool false
Name string? -
Required bool false
Dir string? -
ChildContent RenderFragment? -

The button that opens the listbox. Renders a button with role=combobox.

Prop Type Default
ChildContent RenderFragment? -
Data attribute Values
[data-popup-open] Present while the listbox is open.
[data-disabled] Present when the root is disabled
[data-placeholder] Present when no value is selected

Shows the selected item's label, or the placeholder when nothing is selected. Renders a span.

Prop Type Default
Placeholder string? -
ChildContent RenderFragment? -
Data attribute Values
[data-placeholder] Present when no value is selected

A decorative affordance (chevron) inside the trigger. Renders a span.

Prop Type Default
ChildContent RenderFragment? -

The listbox surface. Wrapped by the Positioner and self-portaled to <body>. Renders a div with role=listbox while open. The Side / Align / SideOffset / AlignOffset / Flip / AvoidCollisions / CollisionPadding props are set on the enclosing Positioner.

Prop Type Default
Side string "bottom"
Align string "start"
SideOffset double 6
AlignOffset double 0
Flip bool true
AvoidCollisions bool true
CollisionPadding double? -
KeepMounted bool false
Container string? -
OnEscapeKeyDown EventCallback<NaviusEscapeKeyDownEventArgs> -
OnPointerDownOutside EventCallback<NaviusPointerDownOutsideEventArgs> -
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] "top" | "right" | "bottom" | "left" (set by the positioner)
[data-align] "start" | "center" | "end" (set by the positioner)

The scrollable container wrapping the items inside the content. Renders a div with role=presentation.

Prop Type Default
ChildContent RenderFragment? -

A selectable option. Selecting it sets the value and closes the listbox. Renders a div with role=option.

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

The label content for an item; also supplies the text the trigger shows for this value. Renders a span.

Prop Type Default
Text string? -
ChildContent RenderFragment? -

Renders its content only when its parent item is selected. Renders a span.

Prop Type Default
ChildContent RenderFragment? -

Groups related items, labelled by a child Label via aria-labelledby. Renders a div with role=group.

Prop Type Default
ChildContent RenderFragment? -

An accessible heading for a Group. Renders a div.

Prop Type Default
ChildContent RenderFragment? -

A decorative divider between item sections. Renders a div.

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

Mounts only when the viewport is scrolled down from the top. Renders a div.

Prop Type Default
ChildContent RenderFragment? -

Mounts only when there is more content below the fold. Renders a div.

Prop Type Default
ChildContent RenderFragment? -

An optional triangular pointer rendered inside the content, pointed at the trigger by the positioner. Renders a span.

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

Accessibility

Adheres to the combobox / listbox WAI-ARIA design pattern.

Key Description
Space When focus is on the trigger, opens the listbox and focuses the selected item. When focus is on an item, selects it.
Enter When focus is on the trigger, opens the listbox and focuses the selected item. When focus is on an item, selects it.
ArrowDown When focus is on the trigger, opens the listbox and focuses the first item. When focus is on an item, moves focus to the next item.
ArrowUp When focus is on the trigger, opens the listbox and focuses the last item. When focus is on an item, moves focus to the previous item.
Home When the listbox is open, moves focus to the first item.
End When the listbox is open, moves focus to the last item.
Esc Closes the listbox and returns focus to the trigger.
Type a character Type-ahead moves focus to the next item whose label starts with the typed characters.