Large trees
Since 0.1.0-alpha.21Children that load when a branch first opens, and a search box that narrows the tree.
Children that load
For a tree too large to send at once, set ItemHasChildren and ChildrenProvider. The first time a branch opens, the provider gets the item's key and returns its children.
Static
Preview
Projects
Turn on JavaScript to see these items. Couldn't load the items.Archive
Turn on JavaScript to see these items. Couldn't load the items.- notes.txt
Code
@* Each folder's contents load the first time it opens. On a static page the script asks the page
for them with the folder's key; on an interactive page the component calls ChildrenProvider. *@
<TreeView Items="Roots" ItemKey="f => f.Path" ItemText="f => f.Name" ItemIcon="(f => f.Folder ? Lucide.Folder : Lucide.File)"
ItemHasChildren="f => f.Folder" ChildrenProvider="LoadAsync" MaxWidth="20.Rem" Grow />
{
private static readonly Entry[] Roots = [new("projects", "Projects", true), new("archive", "Archive", true), new("notes.txt", "notes.txt", false)];
private static async ValueTask<IEnumerable<Entry>> LoadAsync(string path, CancellationToken cancellationToken)
{
await Task.Delay(400, cancellationToken); // A slow store, for the demo.
var depth = path.Count(c => c == '/');
Entry[] folders = depth < 2 ? [new($"{path}/2025", "2025", true), new($"{path}/2026", "2026", true)] : [];
return [.. folders, new($"{path}/readme.md", "readme.md", false), new($"{path}/plan.txt", "plan.txt", false)];
}
}On static pages, IzzyBlazor's script asks the page for the children, so there's no endpoint to write. Give each tree on the page that loads children an id.
With JavaScript off, those branches say to turn it on.
Search
To add a search box, set Searchable. Typing narrows the tree to the matches and the branches that hold them, and marks the matched text. It searches the items in the page, so children still to load aren't found.
Static
Preview
Europe
France
- Paris
- Lyon
- Marseille
Germany
- Berlin
- Hamburg
- Munich
Portugal
- Lisbon
- Porto
Americas
Canada
- Toronto
- Montréal
- Vancouver
Brazil
- São Paulo
- Rio de Janeiro
Asia
Japan
- Tokyo
- Osaka
India
- Mumbai
- Delhi
Code
@* Typing narrows the tree to matches and the branches that hold them, with the matched text
marked. Clearing the box puts the branches back as they were. *@
<TreeView Items="_regions" ItemChildren="r => r.Places" ItemKey="r => r.Name" ItemText="r => r.Name"
Searchable SearchLabel="Search places" MaxWidth="20.Rem" Grow />
{
private readonly Place[] _regions =
[
new("Europe",
[
new("France", [new("Paris", []), new("Lyon", []), new("Marseille", [])]),
new("Germany", [new("Berlin", []), new("Hamburg", []), new("Munich", [])]),
new("Portugal", [new("Lisbon", []), new("Porto", [])]),
]),
new("Americas",
[
new("Canada", [new("Toronto", []), new("Montréal", []), new("Vancouver", [])]),
new("Brazil", [new("São Paulo", []), new("Rio de Janeiro", [])]),
]),
new("Asia", [new("Japan", [new("Tokyo", []), new("Osaka", [])]), new("India", [new("Mumbai", []), new("Delhi", [])])]),
];
}