Tree
A WAI-ARIA tree view with arrow-key navigation and optional selection.
Examples
Tree
Up, Down, Left, Right, Home, End, Enter and Space; type a letter to jump.
- src
- components
- Button.razor
- Tabs.razor
- index.js
- tests
- ButtonTests.cs
- README.md
Selected: none
Razor
<div class="w-full max-w-xs">
<KlyTree Items="Items" @bind-Value="_selected" AriaLabel="Project files" />
<p class="mt-3 text-sm text-(--klyroo-text-muted)" data-testid="tree-state">Selected: @(_selected ?? "none")</p>
</div>
@code {
private string? _selected;
private static readonly KlyTreeItem[] Items =
[
new("src")
{
Expanded = true,
Children =
[
new("components")
{
Children = [new("Button.razor"), new("Tabs.razor")],
},
new("index.js"),
],
},
new("tests") { Children = [new("ButtonTests.cs")] },
new("README.md"),
];
}Links
Items with an Href follow the link on Enter; a parent also toggles once.
Razor
<div class="w-full max-w-xs">
<KlyTree Items="Items" AriaLabel="Sections" />
</div>
@code {
private static readonly KlyTreeItem[] Items =
[
new("Guide") { Href = "/docs", Children = [new("Install") { Href = "/docs/installation" }, new("Render modes") { Href = "/docs/render-modes" }] },
new("Theming") { Href = "/docs/theming" },
];
}API
KlyTree
Tree view with expandable nodes, selection and arrow key navigation.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
AriaLabel |
string |
Accessible name of the tree. | |
Class |
string |
Classes added to the root element, merged last so they win over the theme. | |
Color |
KlyColor |
"primary" |
Semantic color of the tree: a built-in KlyColor or the name of a color you defined. When not set, Color applies, else the default of the component. Values: primary, secondary, success, info, warning, error, neutral. |
Items (required) |
IReadOnlyList |
The nodes of the tree, as KlyTreeItem . | |
Ui |
TreeUi |
Per-instance class overrides of the slots of the tree, see TreeUi . They are merged after the theme and the Class parameter wins on the root slot. | |
Value (@bind-Value) |
string |
Value of the selected item. Selection also works unbound: the browser keeps it. |
Ui slots
Ui takes a TreeUi with one class string per slot, merged after the theme.
| Slot | Styles |
|---|---|
Root |
Classes merged into the root slot of KlyTree , after the theme and the app configuration. |
List |
Classes merged into the list slot of KlyTree , after the theme and the app configuration. |
Item |
Classes merged into the item slot of KlyTree , after the theme and the app configuration. |
Row |
Classes merged into the row slot of KlyTree , after the theme and the app configuration. |
Chevron |
Classes merged into the chevron slot of KlyTree , after the theme and the app configuration. |
Spacer |
Classes merged into the spacer slot of KlyTree , after the theme and the app configuration. |
Icon |
Classes merged into the icon slot of KlyTree , after the theme and the app configuration. |
Label |
Classes merged into the label slot of KlyTree , after the theme and the app configuration. |
Group |
Classes merged into the group slot of KlyTree , after the theme and the app configuration. |