Tree View

An expandable tree with a selectable item.

TreeView is new in v0.4. Nest TreeViewItems to build the tree; items with children expand and collapse, and @bind-SelectedValue tracks the selected one.

Installation

bash
shellui add tree-view

This also installs TreeViewItem.

Usage

Basic

Set DefaultExpanded on the branches that should start open.

<TreeView>
    <TreeViewItem Label="src" DefaultExpanded="true">
        <TreeViewItem Label="Components" DefaultExpanded="true">
            <TreeViewItem Label="Button.razor" />
            <TreeViewItem Label="Chat.razor" />
        </TreeViewItem>
        <TreeViewItem Label="Program.cs" />
    </TreeViewItem>
    <TreeViewItem Label="README.md" />
</TreeView>

Selection

Bind SelectedValue to a string?. Each item reports its Value, or its Label when no Value is set, so give items a Value when labels repeat.

Selected: documents/contract.docx

<div class="w-full max-w-xs">
    <TreeView @bind-SelectedValue="selected">
        <TreeViewItem Label="Documents" Value="documents" DefaultExpanded="true">
            <TreeViewItem Label="Invoices" Value="documents/invoices">
                <TreeViewItem Label="2026-09.pdf" Value="documents/invoices/2026-09.pdf" />
                <TreeViewItem Label="2026-10.pdf" Value="documents/invoices/2026-10.pdf" />
            </TreeViewItem>
            <TreeViewItem Label="Contract.docx" Value="documents/contract.docx" />
        </TreeViewItem>
        <TreeViewItem Label="Archive" Value="archive" Disabled="true" />
    </TreeView>

    <p class="mt-3 text-sm text-muted-foreground">Selected: @(selected ?? "none")</p>
</div>

@code {
    private string? selected = "documents/contract.docx";
}

With icons

When an item has both an Icon and children, put the children in <ChildContent>.

<TreeView>
    <TreeViewItem Label="wwwroot" DefaultExpanded="true">
        <Icon>
            <svg class="h-4 w-4" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                <path stroke-linecap="round" stroke-linejoin="round" d="M4 20h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.93a2 2 0 0 1-1.66-.9l-.82-1.2A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z" />
            </svg>
        </Icon>
        <ChildContent>
            <TreeViewItem Label="app.css">
                <Icon>
                    <svg class="h-4 w-4" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8ZM14 2v6h6" />
                    </svg>
                </Icon>
            </TreeViewItem>
            <TreeViewItem Label="favicon.png">
                <Icon>
                    <svg class="h-4 w-4" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8ZM14 2v6h6" />
                    </svg>
                </Icon>
            </TreeViewItem>
        </ChildContent>
    </TreeViewItem>
</TreeView>

API Reference

TreeView

Parameter Type Default Description
SelectedValue string? null The selected item's value; use @bind-SelectedValue
SelectedValueChanged EventCallback<string?> - Fires when the selection changes
ChildContent RenderFragment? null The top-level TreeViewItems
Class string? null Additional CSS classes

TreeViewItem

Parameter Type Default Description
Label string "" Text shown for the item
Value string? null Value reported on selection; defaults to Label
DefaultExpanded bool false Start with the children visible
Disabled bool false Prevents selecting or expanding
Icon RenderFragment? null Icon before the label
ChildContent RenderFragment? null Nested TreeViewItems
Class string? null Additional CSS classes

Accessibility

  • role="tree", role="treeitem" and role="group" describe the structure
  • aria-expanded and aria-selected reflect each item's state
  • Every item is a native button: Tab moves between items, Enter or Space selects and toggles

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.