navius

Tree

A full WAI-APG TreeView: single or multi selection, controlled expansion, roving or activedescendant focus, and a data-driven or hand-composed shape.

Selected: index.ts

Features

  • Generic over the node value type; a non-generic context is cascaded so the parts stay simple. Every treeitem auto-wires aria-level / aria-setsize / aria-posinset from the composition.
  • Selection is none / single / multiple, controlled via @bind-SelectedValue(s) or uncontrolled; expansion via @bind-ExpandedValues.
  • FocusMode is roving (default) or activedescendant (for virtualized trees); a single keyboard handler on the tree serves both.
  • Two composition modes: author the parts as children, or pass Items (a hierarchy of TreeNode<TValue>) + an ItemTemplate and let the tree walk it.

Installation

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

Anatomy

A treeitem's row is a Content holding an Indicator + a Trigger; a child Group makes the node a parent and holds its subtree.

API Reference

NaviusTree<TValue>. Owns selection, expansion, focus and the keyboard model. Renders a div with role=tree. SelectedValue(s) and ExpandedValues are two-way bindable.

Prop Type Default
SelectionMode string "single"
FocusMode string "roving"
SelectedValue TValue? -
SelectedValueChanged EventCallback<TValue?> -
DefaultSelectedValue TValue? -
SelectedValues IReadOnlyList<TValue>? -
SelectedValuesChanged EventCallback<IReadOnlyList<TValue>> -
DefaultSelectedValues IReadOnlyList<TValue>? -
ExpandedValues IReadOnlyCollection<TValue>? -
ExpandedValuesChanged EventCallback<IReadOnlyCollection<TValue>> -
DefaultExpandedValues IReadOnlyCollection<TValue>? -
Disabled bool false
Orientation string "vertical"
Dir string? -
Label string? -
LabelledBy string? -
Items IReadOnlyList<TreeNode<TValue>>? -
ItemTemplate RenderFragment<TreeNode<TValue>>? -
OnSelectionChange EventCallback<IReadOnlyList<TValue>> -
OnExpandedChange EventCallback<IReadOnlyList<TValue>> -
ChildContent RenderFragment? -
…attributes IDictionary<string, object>? -
Data attribute Values
[data-navius-tree] Present on the tree
[data-orientation] "vertical" | "horizontal"
[data-disabled] Present when disabled

NaviusTreeItem. The focusable node (role=treeitem); emits aria-level / setsize / posinset, aria-expanded (parents only) and aria-selected. Renders a div.

Prop Type Default
Value object required
Disabled bool false
TextValue string? rendered value
ChildContent RenderFragment? -
…attributes IDictionary<string, object>? -
Data attribute Values
[data-navius-tree-item] Present on every treeitem
[data-expanded] Present on an expanded parent
[data-selected] Present when selected (and selection is enabled)
[data-disabled] Present when disabled
[data-focused] Present on the active node
[data-level] The 1-based depth
[data-leaf] Present on leaf nodes

NaviusTreeItemContent. The presentational label-row wrapper (indicator + trigger + adornments). Renders a div.

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

NaviusTreeItemTrigger. The expand/collapse + select click target; a presentational span (no second tab stop). Renders a span.

Prop Type Default
ChildContent RenderFragment? -
…attributes IDictionary<string, object>? -
Data attribute Values
[data-navius-tree-item-trigger] Present on the trigger
[data-expanded] / [data-selected] / [data-disabled] Mirror the node state

NaviusTreeItemIndicator. The expand/collapse chevron (aria-hidden). Renders a span carrying data-state so a chevron can rotate.

Prop Type Default
ChildContent RenderFragment? -
…attributes IDictionary<string, object>? -
Data attribute Values
[data-navius-tree-item-indicator] Present on the chevron
[data-state] "expanded" | "collapsed"
[data-leaf] Present on leaf nodes (nothing to expand)

NaviusTreeGroup. The child container (role=group); its presence marks the parent expandable. Lazy-mount or KeepMounted. Renders a div.

Prop Type Default
KeepMounted bool false
ChildContent RenderFragment? -
…attributes IDictionary<string, object>? -
Data attribute Values
[data-navius-tree-group] Present on the child container (role=group)
[data-expanded] Present while the group is open
[data-level] The child depth

Data-driven mode: Items is an IReadOnlyList<TreeNode<TValue>> where TreeNode has Value, Label, Children and Disabled; the ItemTemplate renders each node's row and the tree wires the group + recursion.

Accessibility

Adheres to the tree view pattern: role="tree" with a labelled name, treeitems with level / setsize / posinset, aria-expanded on parents only (never leaves), and aria-multiselectable in multiple mode. Give the tree a Label or LabelledBy.

Key Description
Arrow Down / Arrow Up Moves through the visible rows in document order.
Arrow Right Expands a collapsed parent, or moves to its first child (mirrored under rtl).
Arrow Left Collapses an expanded parent, or moves to its parent (mirrored under rtl).
Home / End Moves to the first / last visible node.
Enter / Space Selects the focused node (and toggles a parent's expansion).
Type a character Type-ahead: moves to the next node whose label starts with it.