Skip to main content
twblazor
Home
  • Get started
  • Tailwind with Blazor
  • Why twblazor?
  • Theme
  • Class Merge
    • Configuring localization
    • RTL Provider
  • Breadcrumb
  • Card
  • Carousel
  • Collapse
  • Context Menu
  • Drawer
  • Footer
  • Menu
  • Navbar
  • On This Page
  • Separator
  • Sidebar
  • Stepper
  • Tabs
  • Tree List
  • Container
  • Flex
  • Grid
  • Text
  • Link
  • Button
  • Form
    • AutocompleteNew
    • Checkbox
    • Color Picker
    • Date Picker
    • Date Range Picker
    • Datetime Picker
    • Datetime Range Picker
    • File Upload
    • Input GroupNew
    • NumericNew
    • Masked InputNew
    • Radio Button
    • Range SliderNew
    • RatingNew
    • Select
    • Slider
    • Switch
    • Tag InputNew
    • Text EditorNew
    • Textfield
    • Time Picker
    • Time Range Picker
  • Toggle
  • Toggle Group
  • Alert
  • Avatar
  • Badge
  • Chip
  • Empty
  • Icon
  • Popover
  • Progress
  • Skeleton
  • Spinner
  • Tooltip
  • Data Table
  • SpreadsheetNew
  • Column Filter Editor
  • Pagination
  • Pick List
  • Barcode
  • QR Code
  • Calendar
  • Table
  • Attachment
  • Overview
    • Bar
    • Bullet
    • Column
    • Dot Plot
    • Dumbbell
    • Icon
    • Lollipop
    • Radial Bar
    • Range
    • Word Cloud
    • Area
    • Bump
    • Bump Area
    • Candlestick
    • Gantt
    • Horizon
    • Line
    • Slope
    • Small Multiples
    • Stream Graph
    • Funnel
    • Gauge
    • Marimekko
    • Nightingale
    • Pie
    • Treemap
    • Waffle
    • Waterfall
    • Circular Treemap
    • Convex Treemap
    • Dendrogram
    • Sunburst
    • Barcode
    • Beeswarm
    • Box Plot
    • Density Plot
    • Histogram
    • Radial Histogram
    • Ridgeline
    • Strip Plot
    • Violin Plot
    • Categorical Scatter
    • Contour
    • Hexagonal Binning
    • Quadrant
    • Scatter
    • Heatmap
    • Matrix
    • Parallel Coordinates
    • Radar
    • Arc Diagram
    • Chord Diagram
    • Flowchart
    • Network Diagram
    • Sankey
    • Euler Diagram
    • Venn Diagram
  • Bubble
  • Marker
  • Message
  • Dialog Service
  • Toast Service
API DocumentationAI Agents & Skills
Home Get Started

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 18 October 2026

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

RAZOR
<TwTreeList AriaLabel="Select a file">
    <TwTreeListItem Label="Reports">
        <TwTreeListItem Label="Q1.xlsx" OnClick="@(() => OnFileSelected("Q1.xlsx"))" />
        <TwTreeListItem Label="Q2.xlsx" OnClick="@(() => OnFileSelected("Q2.xlsx"))" />
    </TwTreeListItem>
    <TwTreeListItem Label="summary.pdf" OnClick="@(() => OnFileSelected("summary.pdf"))" />
</TwTreeList>
<p class="mt-4 text-sm text-gray-600 dark:text-white">Selected: <strong>@(selectedFile ?? "none")</strong></p>
CSHARP
@code {
    private string? selectedFile;
    
    private void OnFileSelected(string label) => selectedFile = label;
}

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
RAZOR
<TwTreeList AriaLabel="Departments">
    @foreach (var department in _departments)
    {
        @if (department.Teams.Count > 0)
        {
            <TwTreeListItem Label="@department.Name" Collapsed="false">
                @foreach (var team in department.Teams)
                {
                    <TwTreeListItem Label="@team" OnClick="@(() => ShowTeamMembers(team))" />
                }
            </TwTreeListItem>
        }
        else
        {
            <TwTreeListItem Label="@department.Name" />
        }
    }
</TwTreeList>
CSHARP
@code {
    private sealed class Department
    {
        public string Name { get; set; } = string.Empty;
        public List<string> Teams { get; set; } = [];
    }
    
    private readonly List<Department> _departments =
    [
        new() { Name = "Engineering", Teams = ["Platform", "Mobile"] },
        new() { Name = "Marketing", Teams = ["Content", "Growth"] },
    ];
    
    private static readonly string[] _namePool =
    [
        "Alice Johnson", "Bob Smith", "Carol Lee", "David Kim", "Priya Patel",
        "Wei Zhang", "Fatima Al-Sayed", "Liam O'Brien", "Sofia Rossi", "Noah Muller"
    ];
    
    private Task ShowTeamMembers(string team)
    {
        var members = _namePool.OrderBy(_ => Random.Shared.Next()).Take(3);
    
        return DialogService.ShowAsync<ConfirmDialog>(team,
            new TwDialogParameters { ["Message"] = $"Team members: {string.Join(", ", members)}" });
    }
}

Keyboard navigation

The tree is a single Tab stop. Collapsed branches are skipped, and disabled nodes cannot be focused. In a right to left layout Arrow Left and Arrow Right swap roles.
Key What it does
Tab Moves focus into the tree, onto the node last visited.
Arrow Up or Arrow Down Moves to the previous or next visible node.
Arrow Right On a collapsed node: expands it. On an expanded node: moves to its first child.
Arrow Left On an expanded node: collapses it. On any other node: moves to its parent.
Home or End Moves to the first or last visible node.
Enter Activates the node: expands or collapses it and raises OnClick.
Space With checkboxes: checks or unchecks the node and everything under it. Without: activates the node.

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.

On this page

  • Basic usage
  • Default expanded
  • Selecting a node
  • Checkboxes
  • Disabled nodes
  • Custom icons
  • Hiding icons
  • Building from your own data
  • Keyboard navigation
  • Theme configuration
twblazor

The Tailwind CSS component library for Blazor. Accessible, themeable and MIT licensed.

Discord (opens in a new tab) GitHub(opens in a new tab)

Get started

  • Install guide
  • Theming
  • Class merging
  • Localization

Guides

  • Tailwind CSS with Blazor
  • Why twblazor?
  • Right to left
  • AI agents and skills

Resources

  • API documentation (opens in a new tab)
  • llms.txt (opens in a new tab)
  • MIT License (opens in a new tab)

Community

  • Contributing (opens in a new tab)
  • Code of conduct (opens in a new tab)
  • Report an issue (opens in a new tab)

twblazor is and always will be free and open source.

An unhandled error has occurred. Reload