Table of Contents

Class TwTreeListItem

Namespace
TwBlazor.Components
Assembly
TwBlazor.dll

Represents a single node in a TwTreeList: the actual row (chevron, checkbox, icon, label) plus, when it has children, its own nested <ul role="group">.

public class TwTreeListItem : TwBlazorComponentBase, IComponent, IHandleEvent, IHandleAfterRender, ITwComponent
Inheritance
TwTreeListItem
Implements
Inherited Members

Remarks

Build a tree by nesting <TwTreeListItem> tags directly - inside a TwTreeList for a root node, or inside another TwTreeListItem for a child - typically generated with your own @foreach over whatever data you already have. Collapsed/checked state is tracked internally (seeded once from the Collapsed/Checked parameters at first render, like an uncontrolled input, since a parent cascading a check down to its children can't reach through a one-way parameter) and every node keeps a list of the nested TwTreeListItems that registered with it via the cascaded parent reference, so checkbox aggregation and cascading see the whole subtree. Every node also cascades a reference to the root TwTreeList, so a checkbox change anywhere can trigger TwBlazor.Components.TwTreeList.NotifyDescendantChangedAsync - re-rendering the whole tree so every ancestor's aggregated checkbox state (computed fresh from its descendants on every render) reflects the change immediately.

Constructors

TwTreeListItem()

public TwTreeListItem()

Properties

Checked

Gets or sets whether the node is checked, when the owning TwTreeList has ShowCheckboxes enabled. Seeded once at first render, then self-managed - like an uncontrolled input - since a parent node cascading a check down to this one can't reach through a one-way parameter.

[Parameter]
public bool Checked { get; set; }

Property Value

bool

CheckedChanged

Gets or sets the callback invoked when this node's checked state changes, whether from a direct click or cascaded down from an ancestor.

[Parameter]
public EventCallback<bool> CheckedChanged { get; set; }

Property Value

EventCallback<bool>

ChildContent

Gets or sets nested TwTreeListItem tags, for building this node's children.

[Parameter]
public RenderFragment? ChildContent { get; set; }

Property Value

RenderFragment

Collapsed

Gets or sets whether this node's children start collapsed.

[Parameter]
public bool Collapsed { get; set; }

Property Value

bool

CollapsedChanged

Gets or sets the callback invoked when Collapsed changes.

[Parameter]
public EventCallback<bool> CollapsedChanged { get; set; }

Property Value

EventCallback<bool>

Disabled

Gets or sets whether the node is disabled.

[Parameter]
public bool Disabled { get; set; }

Property Value

bool

Icon

Gets or sets the node's icon override.

[Parameter]
public Icon? Icon { get; set; }

Property Value

Icon?

Label

Gets or sets the display text for the node.

[Parameter]
public string Label { get; set; }

Property Value

string

OnClick

Gets or sets the callback invoked when the node is clicked or activated via keyboard.

[Parameter]
public EventCallback OnClick { get; set; }

Property Value

EventCallback

Value

Gets or sets an arbitrary domain value for the node, for your own use (e.g. read back inside an OnClick closure) - not read or used by the component itself.

[Parameter]
public object? Value { get; set; }

Property Value

object

Methods

BuildRenderTree(RenderTreeBuilder)

Renders the component to the supplied RenderTreeBuilder.

protected override void BuildRenderTree(RenderTreeBuilder __builder)

Parameters

__builder RenderTreeBuilder

OnAfterRender(bool)

A node only exists as a component once Blazor constructs it as part of rendering its parent's own render tree - which happens after the parent's own render tree (including the aria-checked attribute computed from TwBlazor.Components.TwTreeListItem.GetEffectiveChecked) has already been built, so a node with registered children needs one extra render pass to reflect their aggregated state on first paint. Deferred to here (fired once the render batch has committed) rather than triggered re-entrantly from TwBlazor.Components.TwTreeListItem.RegisterChild(TwBlazor.Components.TwTreeListItem) during the child's own OnInitialized - calling StateHasChanged on an ancestor while still inside the render pass that's constructing that same child led Blazor to lose track of which child component instances were already registered, so a checkbox toggle's cascade silently mutated stale, no-longer-rendered instances.

protected override void OnAfterRender(bool firstRender)

Parameters

firstRender bool

OnInitialized()

Method invoked when the component is ready to start, having received its initial parameters from its parent in the render tree.

protected override void OnInitialized()

OnParametersSet()

Invoked when the component's parameters have been set. Ensures that the component has a unique identifier by generating one if none is provided.

protected override void OnParametersSet()

Remarks

If the component's identifier is not set, a unique ID is generated based on the component's type name (with a 'Tw' prefix removed if present) and a GUID. This helps ensure that each component instance can be uniquely identified, which is useful for scenarios such as associating labels with form elements or targeting elements in client-side scripts.