# Tree View
> An expandable tree with a selectable item.
Source: https://shellui.dev/docs/v0.4/components/data-display/tree-view
`TreeView` is **new in v0.4**. Nest `TreeViewItem`s 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.
```razor
```
### 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.
```razor
Selected: @(selected ?? "none")
@code {
private string? selected = "documents/contract.docx";
}
```
### With icons
When an item has both an `Icon` and children, put the children in ``.
```razor
```
## API Reference
### TreeView
| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `SelectedValue` | `string?` | `null` | The selected item's value; use `@bind-SelectedValue` |
| `SelectedValueChanged` | `EventCallback` | - | Fires when the selection changes |
| `ChildContent` | `RenderFragment?` | `null` | The top-level `TreeViewItem`s |
| `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 `TreeViewItem`s |
| `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