Tree

Description

A component that displays a hierarchical list

A tree displays hierarchical data. Nodes can be expanded or collapsed to reveal nested data.

Supports synchronous and asynchronous loading of child nodes.

Samples

Basic Synchronous Tree

Asynchronous Tree

Selectable Tree

File-System Tree with Selection Events

This sample models a realistic project layout. OnSelected on the Tree fires every time the user clicks an item, so we mirror the path of the selected node in a panel beside the tree.

API reference

class

Tree

public sealed class Tree : ComponentBase<Tree, HTMLUListElement>, IContainer<Tree.Item, Tree.Item>, IObservableComponent<Tree.Item>

A vertically-stacked tree view with expand / collapse, keyboard navigation, selection and arbitrary item rendering.

Namespace
Tesserae
Inheritance
ComponentBase<Tree, HTMLUListElement> → Tree
Implements
IContainer<Tree.Item, Tree.Item>, IObservableComponent<Tree.Item>

Constructors

NameDescription
TreeInitializes a new instance of this class.
Constructor
Tree
public Tree()

Initializes a new instance of this class.

Properties

NameDescription
SelectedItemGets the currently selected item.
Property
Tree.SelectedItem
public Item SelectedItem { get; private set; }

Gets the currently selected item.

Methods

NameDescription
RenderRenders the component's root HTML element.
OnSelectedRegisters a callback invoked when the selected event fires.
SelectionEnabledEnables or disables item selection on the tree.
AddAdds the given item to the component.
ClearClears the component's current state.
ReplaceReplaces an existing item with a new one.
AsObservableReturns an observable that tracks the currently-selected tree item.
ItemsAdds the given items to the component.
Method
Tree.Render
public override HTMLElement Render()

Renders the component's root HTML element.

Method
Tree.OnSelected
public Tree OnSelected(ComponentEventHandler<Tree, Item> onSelected)

Registers a callback invoked when the selected event fires.

Method
Tree.SelectionEnabled
public Tree SelectionEnabled(bool enabled = true)

Enables or disables item selection on the tree.

Method
Tree.Add
public void Add(Item component)

Adds the given item to the component.

Method
Tree.Clear
public void Clear()

Clears the component's current state.

Method
Tree.Replace
public void Replace(Item newComponent, Item oldComponent)

Replaces an existing item with a new one.

Method
Tree.AsObservable
public IObservable<Item> AsObservable()

Returns an observable that tracks the currently-selected tree item.

Method
Tree.Items
public Tree Items(params Item[] children)

Adds the given items to the component.

Events

NameDescription
SelectedItemChangedRaised when selected item changed occurs.
Event
Tree.SelectedItemChanged
public event ComponentEventHandler<Tree, Item> SelectedItemChanged

Raised when selected item changed occurs.

TreeCommand

A command inside a tree item, drawn as a small action button on the row.

class

TreeCommand

public class TreeCommand : IComponent

A Command component for use within a Tree item, typically appearing as a small action button.

Namespace
Tesserae
Implements
IComponent

Constructors

NameDescription
TreeCommandInitializes a new instance of this class.
Constructor
TreeCommand
Overload
TreeCommand(UIcons, UIconsWeight)Initializes a new instance of this class.
TreeCommand(string, UIcons, UIconsWeight)Initializes a new instance of this class.
TreeCommand(Emoji)Initializes a new instance of this class.
TreeCommand(string, Emoji)Initializes a new instance of this class.
TreeCommand(ISidebarIcon)Initializes a new instance of this class.
TreeCommand(string, ISidebarIcon)Initializes a new instance of this class.
TreeCommand(UIcons, UIconsWeight)
public TreeCommand(UIcons icon, UIconsWeight weight = UIconsWeight.Regular) : this(null, Button().SetIcon(icon, weight: weight))

Initializes a new instance of this class.

Parameters

icon UIcons
weight UIconsWeight
TreeCommand(string, UIcons, UIconsWeight)
public TreeCommand(string href, UIcons icon, UIconsWeight weight = UIconsWeight.Regular) : this(href, Button().SetIcon(icon, weight: weight))

Initializes a new instance of this class.

Parameters

href string
icon UIcons
weight UIconsWeight
TreeCommand(Emoji)
public TreeCommand(Emoji icon) : this(null, Button().SetIcon(icon))

Initializes a new instance of this class.

Parameters

icon Emoji
TreeCommand(string, Emoji)
public TreeCommand(string href, Emoji icon) : this(href, Button().SetIcon(icon))

Initializes a new instance of this class.

Parameters

href string
icon Emoji
TreeCommand(ISidebarIcon)
public TreeCommand(ISidebarIcon image) : this(null, image)

Initializes a new instance of this class.

Parameters

image ISidebarIcon
TreeCommand(string, ISidebarIcon)
public TreeCommand(string href, ISidebarIcon image)

Initializes a new instance of this class.

Parameters

href string
image ISidebarIcon

Methods

NameDescription
ForegroundSets the foreground color of the command button.
HookToParentContextMenuConfigures the command to hook into the parent tree item's context menu event.
BackgroundSets the background color of the command button.
DefaultSets the command to use the default style.
PrimarySets the command to use the primary style.
SuccessSets the command to use the success style.
DangerSets the command to use the danger style.
TooltipSets a tooltip for the command.
OnClickMenuConfigures the command to show a menu when clicked.
ShowMenuShows the associated menu for the command.
RaiseOnClickProgrammatically raises the click event.
RaiseOnContextMenuProgrammatically raises the context menu event.
OnClickAdds a click event handler.
OnContextMenuAdds a context menu event handler.
SetIconSets the icon for the command.
SetTextSets the text label for the command.
RenderRenders the tree command.
Method
TreeCommand.Foreground
public TreeCommand Foreground(string color)

Sets the foreground color of the command button.

Method
TreeCommand.HookToParentContextMenu
public TreeCommand HookToParentContextMenu()

Configures the command to hook into the parent tree item's context menu event.

Method
TreeCommand.Background
public TreeCommand Background(string color)

Sets the background color of the command button.

Method
TreeCommand.Default
public TreeCommand Default()

Sets the command to use the default style.

Method
TreeCommand.Primary
public TreeCommand Primary()

Sets the command to use the primary style.

Method
TreeCommand.Success
public TreeCommand Success()

Sets the command to use the success style.

Method
TreeCommand.Danger
public TreeCommand Danger()

Sets the command to use the danger style.

Method
TreeCommand.Tooltip
Overload
Tooltip(string)Sets a tooltip for the command.
Tooltip(IComponent)Sets a tooltip component for the command.
Tooltip(Func<IComponent>)Sets a tooltip generator function for the command.
Tooltip(string)
public TreeCommand Tooltip(string text)

Sets a tooltip for the command.

Parameters

text string
Tooltip(IComponent)
public TreeCommand Tooltip(IComponent tooltip)

Sets a tooltip component for the command.

Parameters

tooltip IComponent
Tooltip(Func<IComponent>)
public TreeCommand Tooltip(Func<IComponent> tooltip)

Sets a tooltip generator function for the command.

Parameters

tooltip Func<IComponent>
Method
TreeCommand.OnClickMenu
public TreeCommand OnClickMenu(Func<TreeCommand[]> generator)

Configures the command to show a menu when clicked.

Parameters

generator
A function that generates the tree commands for the menu.
Method
TreeCommand.ShowMenu
public void ShowMenu()

Shows the associated menu for the command.

Method
TreeCommand.RaiseOnClick
public TreeCommand RaiseOnClick(MouseEvent mouseEvent)

Programmatically raises the click event.

Method
TreeCommand.RaiseOnContextMenu
public TreeCommand RaiseOnContextMenu(MouseEvent mouseEvent)

Programmatically raises the context menu event.

Method
TreeCommand.OnClick
Overload
OnClick(Action)Adds a click event handler.
OnClick(Action<Button, MouseEvent>)Adds a click event handler with button and mouse event arguments.
OnClick(Action)
public TreeCommand OnClick(Action action)

Adds a click event handler.

Parameters

action Action
OnClick(Action<Button, MouseEvent>)
public TreeCommand OnClick(Action<Button, MouseEvent> action)

Adds a click event handler with button and mouse event arguments.

Parameters

action Action<Button, MouseEvent>
Method
TreeCommand.OnContextMenu
Overload
OnContextMenu(Action)Adds a context menu event handler.
OnContextMenu(Action<Button, MouseEvent>)Adds a context menu event handler with button and mouse event arguments.
OnContextMenu(Action)
public TreeCommand OnContextMenu(Action action)

Adds a context menu event handler.

Parameters

action Action
OnContextMenu(Action<Button, MouseEvent>)
public TreeCommand OnContextMenu(Action<Button, MouseEvent> action)

Adds a context menu event handler with button and mouse event arguments.

Parameters

action Action<Button, MouseEvent>
Method
TreeCommand.SetIcon
Overload
SetIcon(UIcons, string, UIconsWeight)Sets the icon for the command.
SetIcon(Emoji)Sets an emoji icon for the command.
SetIcon(UIcons, string, UIconsWeight)
public TreeCommand SetIcon(UIcons icon, string color = "", UIconsWeight weight = UIconsWeight.Regular)

Sets the icon for the command.

Parameters

icon UIcons
color string
weight UIconsWeight
SetIcon(Emoji)
public TreeCommand SetIcon(Emoji icon)

Sets an emoji icon for the command.

Parameters

icon Emoji
Method
TreeCommand.SetText
public TreeCommand SetText(string text)

Sets the text label for the command.

Method
TreeCommand.Render
public HTMLElement Render()

Renders the tree command.

See also

© 2026 Curiosity. All rights reserved.