TreeView
Since 0.1.0-alpha.21Items nested in items, from data: folders, categories, a company's teams. Items are the top level, and ItemChildren gives each item's own.
Each item with children opens and closes, with no script. A branch starts open when it holds the current item (ItemCurrent), a selected one, or ItemExpanded says so, so a page arrives with its own place in the tree showing. With script, the branches a person opened stay open as they move between pages; on an interactive page @bind-ExpandedItems follows them.
With no template, ItemText, ItemDescription and ItemIcon draw an icon, the text and a muted second line; ChildContent draws each item instead. ItemHref makes items links. In a tree of links each item's arrow sits at its end, as in NavGroup, and an item that is a link and has children gets its own button to open them; other trees put the arrow first.
SelectionMode makes a tree to choose from, as ListView's selection: Multiple gives each item a checkbox, Single selects one item. In a form the keys post under SelectionName; on an interactive page bind them with @bind-Selection:
A tree of links
Set Items to the top level and ItemChildren to each item's own, with ItemKey and ItemText. To make each item a link, set ItemHref; to mark the item the page is showing, set ItemCurrent, and its branch arrives open. A link with children gets its own button at its end that opens them.
Static
Code
@* Each folder links to this page with ?folder=, and the one in the address is current: its branch
arrives open, in every mode, with no script. *@
NavigationManager Navigation
<TreeView Items="_folders" ItemChildren="f => f.Folders" ItemKey="f => f.Id" ItemText="f => f.Name"
ItemIcon="_ => Lucide.Folder" ItemHref="(f => Navigation.GetUriWithQueryParameter("folder", f.Id))"
ItemCurrent="(f => f.Id == (Folder ?? "invoices"))" Label="Folders" MaxWidth="18.Rem" Grow />
{
[SupplyParameterFromQuery] private string? Folder { get; set; }
private readonly Item[] _folders =
[
new("documents", "Documents",
[
new("contracts", "Contracts", []),
new("finance", "Finance", [new("invoices", "Invoices", []), new("receipts", "Receipts", [])]),
]),
new("photos", "Photos", [new("2025", "2025", []), new("2026", "2026", [])]),
new("shared", "Shared", []),
];
}Add this example to a page with the izzy CLI:
izzy add component TreeView --at <file>:<line>Topics
- Selection: Checkboxes or a single choice. The keys post with a form or bind to C#.
- Large trees: Children that load when a branch first opens, and a search box that narrows the tree.
Text and descriptions
Set ItemChildren to each item's children. With no template, ItemText, ItemDescription and ItemIcon draw each item; to start branches open, set ItemExpanded.
Static
Preview
EngineeringAda Lovelace
PlatformAlan Turing
- StorageBarbara Liskov
- NetworkingRadia Perlman
- AppsGrace Hopper
DesignSusan Kare
- ResearchDon Norman
- OperationsKatherine Johnson
Code
@* A tree to read, not to navigate: each team with a muted line under it, the top level open. *@
<TreeView Items="_teams" ItemChildren="t => t.Teams" ItemText="t => t.Name" ItemDescription="t => t.Lead"
ItemIcon="_ => Lucide.Users" ItemExpanded="t => t.Teams.Length > 0 && _teams.Contains(t)" MaxWidth="20.Rem" Grow />
{
private readonly Team[] _teams =
[
new("Engineering", "Ada Lovelace",
[
new("Platform", "Alan Turing", [new("Storage", "Barbara Liskov", []), new("Networking", "Radia Perlman", [])]),
new("Apps", "Grace Hopper", []),
]),
new("Design", "Susan Kare", [new("Research", "Don Norman", [])]),
new("Operations", "Katherine Johnson", []),
];
}Details
Checking a parent checks its branch, and a parent with some of its branch checked shows a mixed box (Cascade="false" makes each box its own). The selection holds every checked key, parents included.
For a large tree, ItemHasChildren and ChildrenProvider load a branch's children the first time it opens: on a static page the script fetches the page with the branch's key, so there's no endpoint to write (two such trees on a page need ids). Searchable adds a box that narrows the tree to matches and the branches that hold them.
Mode support
| Feature | Static | Interactive |
|---|---|---|
| Links, the current item, and branches that open | Yes | Yes |
| Branches opened by hand stay open across pages | Yes | Yes |
| Selection that posts with a form or binds in C# | Yes | Yes |
| Checking a parent checks its branch; mixed parents | Yes | Yes |
| One Tab stop, arrow keys and typeahead in a tree to choose from | Yes | Yes |
| Children that load when a branch first opens | Yes | Yes |
| A search box that narrows the tree | Yes | Yes |
| The open branches bound to C# | No | Yes |
Static: static server-side rendering, with no circuit and no WebAssembly. Interactive: Server, WebAssembly or Auto.
Without JavaScript
Every page starts as plain HTML: before IzzyBlazor's script loads on a static page, while an interactive page prerenders, and with JavaScript off. With JavaScript off, a tree you select from is a list of checkboxes or radio buttons in branches that open: no arrow keys, and checking a parent doesn't check its children. Children that load and the search box need it.
Accessibility
- It's nested lists (
ulwithrole="list"), so screen readers say how many items each level has and how deep an item is. Put a tree of links for moving around the site in anav, or name it withLabel. - An item with children opens and closes with a
detailselement: its summary is a button that says whether it's open. A link with children has a separate button after it, named by the item, so Tab reaches the link, then its button. - The current item (
ItemCurrent) is markedaria-current("page" on a link). - A disabled item (
ItemDisabled) has no link, or its box is disabled, and it's dimmed; its children still open. - In a tree of links, Tab goes through the links and buttons in order. Arrow keys don't move through it: a list of links is read and reached as one.
- With
SelectionModeand script, it's an ARIAtree(give it anLabel): one Tab stop, the arrow keys between items, and each item atreeitemthat says whether it's open and whether it's checked (aria-checked, "mixed" for a part-checked parent) or selected. With JavaScript off it's a list of checkboxes or radio buttons in branches.
Keyboard navigation
| Press this key | To do this |
|---|---|
| Up or Down | Move to the item above or below |
| Right | Open an item's branch, or move to its first child (Left on right-to-left pages) |
| Left | Close an item's branch, or move to its parent (Right on right-to-left pages) |
| Home or End | Move to the first or last item |
| * | Open every branch beside the focused item |
| Space | Check or uncheck the item, or select it; one that can't be, open or close its branch |
| Enter | Select the item; with checkboxes, check or uncheck it; one that can't be, open or close its branch |
| A letter | Move to the next item starting with it |
Parameters
| Prop | Type | Default |
|---|---|---|
ItemsThe items at the top of the tree. | IEnumerable<TItem>? | |
ItemChildrenAn item's children, or null or empty when it has none. | Func<TItem, IEnumerable<TItem>?>? | |
ItemKeyA key that tells items apart, such as an id. | Func<TItem, string>? | |
ChildContentAn item's content. | RenderFragment<TItem>? | |
ItemTextAn item's text, with no template. | Func<TItem, string?>? | computed |
ItemDescriptionA muted second line under an item's text, with no template. | Func<TItem, string?>? | |
ItemIconAn icon before an item's text, with no template. | Func<TItem, IconData?>? | |
ItemLabelNames an item for screen readers: the button that opens its children, and in a tree to choose from the item itself. | Func<TItem, string>? | computed |
ItemHrefMakes an item a link to this address; null leaves it plain. | Func<TItem, string?>? | |
ItemCurrentMarks the item the page is showing. | Func<TItem, bool>? | |
ItemHasChildrenSays an item has children to load with ChildrenProvider when its branch first opens, for items whose ItemChildren is empty. | Func<TItem, bool>? | |
ChildrenProviderLoads an item's children, given its key, the first time its branch opens: in the component on an interactive page, and on a static page by the script fetching the page with the key. | Func<string, CancellationToken, ValueTask<IEnumerable<TItem>>>? | |
SearchableA search box above the tree that narrows it as you type: matches and their parents stay, their branches open. | bool | false |
SearchLabelThe search box's name and placeholder. | string? | computed |
ItemExpandedStarts an item's children open. | Func<TItem, bool>? | |
ItemDisabledDims an item and takes away its link, or disables its box. | Func<TItem, bool>? | |
@bind-ExpandedItemsThe keys of the items whose children are open, on an interactive page; bind it with @bind-ExpandedItems. | IReadOnlyCollection<string>? | |
SelectionModeSelectionMode.Multiple gives each item a checkbox; SelectionMode.Single selects one item. | SelectionMode | SelectionMode.None |
@bind-SelectionThe selected items' keys. | Selection? | |
SelectionNameThe form name the selected keys post under, as {name}.Keys; read them with [SupplyParameterFromForm(Name = "...")] Selection. | string? | selected |
ItemSelectableWhether an item can be selected; one that can't keeps its place, with its box disabled, and with script a click on it opens or closes its branch. | Func<TItem, bool>? | |
CascadeWith checkboxes, checking a parent checks its branch, and a parent shows how much of its branch is checked. | bool | true |
LabelNames the tree for screen readers, when nothing around it does. | string? | |
EmptyTextShown when there are no items. | string? | computed |
EmptyContentContent shown when there are no items, in place of EmptyText. | RenderFragment? |
Plus 27 surface props, 17 item props and 4 common props.
Full APISee also
- NavGroup: a collapsible group of nav items, built on
<details>, so it opens and closes with no JavaScript. - ListView: displays a list of items users can open, select, page through and reorder.