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
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
| Name | Description |
|---|---|
| Tree | Initializes a new instance of this class. |
Properties
| Name | Description |
|---|---|
| SelectedItem | Gets the currently selected item. |
Methods
| Name | Description |
|---|---|
| Render | Renders the component's root HTML element. |
| OnSelected | Registers a callback invoked when the selected event fires. |
| SelectionEnabled | Enables or disables item selection on the tree. |
| Add | Adds the given item to the component. |
| Clear | Clears the component's current state. |
| Replace | Replaces an existing item with a new one. |
| AsObservable | Returns an observable that tracks the currently-selected tree item. |
| Items | Adds the given items to the component. |
public Tree OnSelected(ComponentEventHandler<Tree, Item> onSelected)Registers a callback invoked when the selected event fires.
public Tree SelectionEnabled(bool enabled = true)Enables or disables item selection on the tree.
public void Replace(Item newComponent, Item oldComponent)Replaces an existing item with a new one.
public IObservable<Item> AsObservable()Returns an observable that tracks the currently-selected tree item.
Events
| Name | Description |
|---|---|
| SelectedItemChanged | Raised when selected item changed occurs. |
TreeCommand
A command inside a tree item, drawn as a small action button on the row.
public class TreeCommand : IComponentA Command component for use within a Tree item, typically appearing as a small action button.
- Namespace
- Tesserae
- Implements
- IComponent
Constructors
| Name | Description |
|---|---|
| TreeCommand | Initializes a new instance of this class. |
| 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
Methods
| Name | Description |
|---|---|
| Foreground | Sets the foreground color of the command button. |
| HookToParentContextMenu | Configures the command to hook into the parent tree item's context menu event. |
| Background | Sets the background color of the command button. |
| Default | Sets the command to use the default style. |
| Primary | Sets the command to use the primary style. |
| Success | Sets the command to use the success style. |
| Danger | Sets the command to use the danger style. |
| Tooltip | Sets a tooltip for the command. |
| OnClickMenu | Configures the command to show a menu when clicked. |
| ShowMenu | Shows the associated menu for the command. |
| RaiseOnClick | Programmatically raises the click event. |
| RaiseOnContextMenu | Programmatically raises the context menu event. |
| OnClick | Adds a click event handler. |
| OnContextMenu | Adds a context menu event handler. |
| SetIcon | Sets the icon for the command. |
| SetText | Sets the text label for the command. |
| Render | Renders the tree command. |
public TreeCommand Foreground(string color)Sets the foreground color of the command button.
public TreeCommand HookToParentContextMenu()Configures the command to hook into the parent tree item's context menu event.
public TreeCommand Background(string color)Sets the background color of the command button.
| 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
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.
public TreeCommand RaiseOnClick(MouseEvent mouseEvent)Programmatically raises the click event.
public TreeCommand RaiseOnContextMenu(MouseEvent mouseEvent)Programmatically raises the context menu event.
| Overload | |
|---|---|
| OnClick(Action) | Adds a click event handler. |
| OnClick(Action<Button, MouseEvent>) | Adds a click event handler with button and mouse event arguments. |
| 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. |
| Overload | |
|---|---|
| SetIcon(UIcons, string, UIconsWeight) | Sets the icon for the command. |
| SetIcon(Emoji) | Sets an emoji icon for the command. |
public TreeCommand SetText(string text)Sets the text label for the command.