Table of Contents

Class TwCheckboxGroup<TValue>

Namespace
TwBlazor.Components
Assembly
TwBlazor.dll

Represents a container component for grouping multiple TwCheckbox<T> components together.

public class TwCheckboxGroup<TValue> : TwBlazorComponentBase, IComponent, IHandleEvent, IHandleAfterRender, ITwComponent

Type Parameters

TValue

The type of values in the checkbox group when using Items binding.

Inheritance
TwCheckboxGroup<TValue>
Implements
Inherited Members

Remarks

TwCheckboxGroup provides two ways to use checkbox groups:

  1. Manual: Add TwCheckbox components as children (ChildContent)
  2. Automatic: Provide Items and bind to SelectedValues for automatic checkbox generation The component supports cascading the Name property to child checkboxes.

Constructors

TwCheckboxGroup()

public TwCheckboxGroup()

Properties

ChildContent

Gets or sets the content to display within the checkbox group.

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

Property Value

RenderFragment

Disabled

Gets or sets whether the entire checkbox group is disabled.

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

Property Value

bool

Horizontal

Gets or sets the orientation of the checkbox group.

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

Property Value

bool

Remarks

Default is vertical. Set to true for horizontal orientation.

ItemColor

Gets or sets the color for automatically generated checkboxes.

[Parameter]
public Color? ItemColor { get; set; }

Property Value

Color?

Items

Gets or sets the collection of items to display as checkboxes (for automatic mode).

[Parameter]
public IEnumerable<CheckboxGroupItem<TValue>>? Items { get; set; }

Property Value

IEnumerable<CheckboxGroupItem<TValue>>

Remarks

When provided, checkboxes are automatically generated from the items. If not provided, use ChildContent to manually add checkboxes.

Legend

Gets or sets the legend text for the checkbox group.

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

Property Value

string

LegendClass

Gets or sets the CSS class for the legend element.

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

Property Value

string

Name

Gets or sets the name for all checkboxes in the group.

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

Property Value

string

Remarks

This value is cascaded to child checkboxes unless they specify their own name.

SelectedValues

Gets or sets the collection of selected values (for automatic mode with Items).

[Parameter]
public IEnumerable<TValue>? SelectedValues { get; set; }

Property Value

IEnumerable<TValue>

SelectedValuesChanged

Gets or sets the callback invoked when the selected values change (for automatic mode with Items).

[Parameter]
public EventCallback<IEnumerable<TValue>> SelectedValuesChanged { get; set; }

Property Value

EventCallback<IEnumerable<TValue>>

Methods

BuildRenderTree(RenderTreeBuilder)

Renders the component to the supplied RenderTreeBuilder.

protected override void BuildRenderTree(RenderTreeBuilder __builder)

Parameters

__builder RenderTreeBuilder

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.