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
TValueThe 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:
- Manual: Add TwCheckbox components as children (ChildContent)
- 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
Disabled
Gets or sets whether the entire checkbox group is disabled.
[Parameter]
public bool Disabled { get; set; }
Property Value
Horizontal
Gets or sets the orientation of the checkbox group.
[Parameter]
public bool Horizontal { get; set; }
Property Value
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
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
LegendClass
Gets or sets the CSS class for the legend element.
[Parameter]
public string? LegendClass { get; set; }
Property Value
Name
Gets or sets the name for all checkboxes in the group.
[Parameter]
public string? Name { get; set; }
Property Value
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
__builderRenderTreeBuilder
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.