Layout
TwTreeList
TwTreeList is a Blazor tree view for nested, expandable data. Set Label, Icon and Disabled per node, show checkboxes, and bind Checked and Collapsed.
Last updated
Basic Usage
Build a tree by nesting
TwTreeListItem tags inside a TwTreeList - and inside each other, for children. A node with nested items can be expanded or collapsed by clicking it.- Documents
- resume.pdf
- cover-letter.docx
- Pictures
- holiday.jpg
- profile.png
- readme.md
Razor
<TwTreeList AriaLabel="File explorer">
<TwTreeListItem Label="Documents">
<TwTreeListItem Label="resume.pdf" />
<TwTreeListItem Label="cover-letter.docx" />
</TwTreeListItem>
<TwTreeListItem Label="Pictures">
<TwTreeListItem Label="holiday.jpg" />
<TwTreeListItem Label="profile.png" />
</TwTreeListItem>
<TwTreeListItem Label="readme.md" />
</TwTreeList>Default Expanded
Set
Collapsed="false" on a node so its children are already visible on first render.- src
- Components
- TwTreeList.razor
- TwTreeListItem.razor
- TwBlazorComponentBase.cs
- TwBlazor.csproj
Razor
<TwTreeList AriaLabel="Project structure">
<TwTreeListItem Label="src" Collapsed="false">
<TwTreeListItem Label="Components" Collapsed="false">
<TwTreeListItem Label="TwTreeList.razor" />
<TwTreeListItem Label="TwTreeListItem.razor" />
</TwTreeListItem>
<TwTreeListItem Label="TwBlazorComponentBase.cs" />
</TwTreeListItem>
<TwTreeListItem Label="TwBlazor.csproj" />
</TwTreeList>Selecting a Node
Assign
OnClick on a node to react when it's activated by click or keyboard (Enter/Space).- Reports
- Q1.xlsx
- Q2.xlsx
- summary.pdf
Selected: none
Checkboxes
Set
ShowCheckboxes on the tree to render a checkbox next to each node. Checking or unchecking a node cascades to all of its descendants, and a parent whose children disagree renders indeterminate (a dash) rather than a plain check.- src
- Program.cs
- Startup.cs
- tests
- UnitTests.csproj
- IntegrationTests.csproj
Razor
<TwTreeList ShowCheckboxes AriaLabel="Select project files">
<TwTreeListItem Label="src" Collapsed="false">
<TwTreeListItem Label="Program.cs" Checked="true" />
<TwTreeListItem Label="Startup.cs" />
</TwTreeListItem>
<TwTreeListItem Label="tests" Collapsed="false">
<TwTreeListItem Label="UnitTests.csproj" Checked="true" />
<TwTreeListItem Label="IntegrationTests.csproj" Checked="true" />
</TwTreeListItem>
</TwTreeList>Disabled Nodes
Set
Disabled on a node to prevent it from expanding or raising OnClick.- Shared
- team-notes.txt
- Locked
- secret.txt
Razor
<TwTreeList AriaLabel="File explorer with a locked folder">
<TwTreeListItem Label="Shared" Collapsed="false">
<TwTreeListItem Label="team-notes.txt" />
</TwTreeListItem>
<TwTreeListItem Label="Locked" Disabled="true" Collapsed="false">
<TwTreeListItem Label="secret.txt" />
</TwTreeListItem>
</TwTreeList>Custom Icons
Every node shows a folder or file icon by default. Set
Icon on a node to override it.- Photos
- Videos
- Favorites
Razor
<TwTreeList AriaLabel="Mixed content types">
<TwTreeListItem Label="Photos" Icon="Icon.Image" />
<TwTreeListItem Label="Videos" Icon="Icon.Camera_Video" />
<TwTreeListItem Label="Favorites" Icon="Icon.Star_Fill" />
</TwTreeList>Hiding Icons
Set
HideIcons on the tree for a plainer look with just labels and the expand/collapse chevron.- Documents
- resume.pdf
- readme.md
Razor
<TwTreeList HideIcons AriaLabel="File explorer without icons">
<TwTreeListItem Label="Documents">
<TwTreeListItem Label="resume.pdf" />
</TwTreeListItem>
<TwTreeListItem Label="readme.md" />
</TwTreeList>Building From Your Own Data
A node is just a component, so a tree built from your own data is a normal
@foreach - no separate model type to learn. OnClick works the same regardless of how a node was created, so clicking a team here calls into ITwDialogService to show its members.- Engineering
- Platform
- Mobile
- Marketing
- Content
- Growth
Theme Configuration
Styling is controlled by
TwBlazorTheme.Components (a TwTreeListTheme), configured via the
AddTwBlazor() options callback described on the Get Started page.
Every property is a set of Tailwind classes, so changes are picked up by your own Tailwind build.
| Property | Type | Controls |
|---|---|---|
Container |
string | |
Group |
string | |
Row |
string | |
RowDisabled |
string | |
ToggleSlot |
string | |
ToggleIcon |
string | |
ToggleIconOpen |
string | |
Label |
string | |
ItemIcon |
string | |
CheckboxWrapper |
string | |
ItemOutline |
string |
Full reference: TwTreeListTheme on the API docs.