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:
<NaviusTree TValue="string" @bind-SelectedValue="_selected"
DefaultExpandedValues="_expanded" Label="Project files">
<NaviusTreeItem Value="@("src")">
<NaviusTreeItemContent class="flex items-center gap-1 rounded px-2 py-1
data-[selected]:bg-primary data-[selected]:text-primary-foreground">
<NaviusTreeItemIndicator class="data-[state=expanded]:rotate-90 data-[leaf]:opacity-0"><ChevronIcon /></NaviusTreeItemIndicator>
<NaviusTreeItemTrigger class="flex-1">src</NaviusTreeItemTrigger>
</NaviusTreeItemContent>
<NaviusTreeGroup class="pl-4">
<NaviusTreeItem Value="@("index.ts")">
<NaviusTreeItemContent> ... index.ts ... </NaviusTreeItemContent>
</NaviusTreeItem>
</NaviusTreeGroup>
</NaviusTreeItem>
</NaviusTree>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-posinsetfrom the composition. - Selection is
none/single/multiple, controlled via@bind-SelectedValue(s)or uncontrolled; expansion via@bind-ExpandedValues. -
FocusModeisroving(default) oractivedescendant(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 ofTreeNode<TValue>) + anItemTemplateand let the tree walk it.
Installation
Install the brain, or copy just this primitive in with the CLI.
navius add treeAnatomy
A treeitem's row is a Content holding an Indicator + a Trigger; a child Group makes the node a parent and holds its subtree.
@using Navius.Primitives.Components.Tree
<NaviusTree TValue="string" Label="Files">
<NaviusTreeItem Value="@("node")">
<NaviusTreeItemContent>
<NaviusTreeItemIndicator />
<NaviusTreeItemTrigger>node</NaviusTreeItemTrigger>
</NaviusTreeItemContent>
<NaviusTreeGroup>
@* nested NaviusTreeItem children *@
</NaviusTreeGroup>
</NaviusTreeItem>
</NaviusTree>API Reference
Root
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 attributes
| Data attribute | Values |
|---|---|
| [data-navius-tree] | Present on the tree |
| [data-orientation] | "vertical" | "horizontal" |
| [data-disabled] | Present when disabled |
Item
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 attributes
| 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 |
ItemContent
NaviusTreeItemContent. The presentational label-row wrapper (indicator + trigger + adornments). Renders a div.
| Prop | Type | Default |
|---|---|---|
| ChildContent | RenderFragment? | - |
| …attributes | IDictionary<string, object>? | - |
ItemTrigger
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 attributes
| Data attribute | Values |
|---|---|
| [data-navius-tree-item-trigger] | Present on the trigger |
| [data-expanded] / [data-selected] / [data-disabled] | Mirror the node state |
ItemIndicator
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 attributes
| 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) |
Group
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 attributes
| 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.
Keyboard interactions
| 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. |