Table of Contents

Class TwSidebarItem

Namespace
TwBlazor.Components
Assembly
TwBlazor.dll

Represents a navigation item in a sidebar that can be either a parent item with collapsible children or a link item.

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

Remarks

The TwSidebarItem component renders differently based on the IsParent property:

  • When IsParent is true, it renders as a button with a chevron icon that can toggle child items.
  • When IsParent is false, it renders as a navigation link.

The component can be initialized using either the Href and Label parameters directly, or by providing a NavigationItem object which will populate these values automatically.

Constructors

TwSidebarItem()

public TwSidebarItem()

Properties

ChildContent

Gets or sets the child content to render within the sidebar item.

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

Property Value

RenderFragment

Remarks

This is typically used to render nested TwSidebarItem components when IsParent is true.

ChildrenId

Gets or sets the id of the collapsible child-item container that this item's toggle button controls.

[Parameter]
public string? ChildrenId { get; set; }

Property Value

string

Remarks

Only relevant when IsParent is true. Rendered as the toggle button's aria-controls value so assistive technology can associate the button with the child list it expands/collapses.

Depth

Gets or sets how many levels deep this item is nested (0 for a top-level item, 1 for its children, 2 for its grandchildren, and so on).

[Parameter]
public int Depth { get; set; }

Property Value

int

Href

Gets or sets the URL that the sidebar item navigates to.

[Parameter]
public required string Href { get; set; }

Property Value

string

Remarks

This property is required unless a NavigationItem is provided that contains a Href value. When IsParent is false, this value is used in the anchor tag's href attribute.

IsChild

Gets or sets whether this sidebar item is a child within a parent group.

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

Property Value

bool

Remarks

When true, no rounding is applied unless this is also the last child.

IsCollapsed

Gets or sets whether the parent item's children are collapsed.

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

Property Value

bool

Remarks

This property only affects the visual state when IsParent is true. It controls the rotation of the chevron icon to indicate the collapsed/expanded state.

IsLastChild

Gets or sets whether this sidebar item is the last child in a parent's child list.

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

Property Value

bool

Remarks

When true, bottom rounded corners are applied to visually close the parent group.

IsParent

Gets or sets whether this sidebar item is a parent item that can have collapsible children.

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

Property Value

bool

Remarks

When true, the item is rendered as a button with a chevron icon. When false, it is rendered as a link.

Label

Gets or sets the display text for the sidebar item.

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

Property Value

string

Remarks

This property is required unless a NavigationItem is provided that contains a Label value.

NavigationItem

Gets or sets the navigation item model that provides the sidebar item's properties.

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

Property Value

NavigationItem

Remarks

When provided, the Href and Label properties are automatically populated from the navigation item during initialization. This allows for easier integration with navigation data models.

OnClick

Gets or sets the callback that is invoked when the sidebar item is clicked.

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

Property Value

EventCallback

Remarks

This callback is typically used with parent items to toggle the visibility of child navigation items.

Methods

BuildRenderTree(RenderTreeBuilder)

Renders the component to the supplied RenderTreeBuilder.

protected override void BuildRenderTree(RenderTreeBuilder __builder)

Parameters

__builder RenderTreeBuilder

OnParametersSet()

Initializes the component and populates properties from the NavigationItem if provided.

protected override void OnParametersSet()

Remarks

If NavigationItem is not null, the Href and Label properties are set from the navigation item's corresponding properties, defaulting to empty strings if the values are null.