Table of Contents

Class TwRadioGroup<T>

Namespace
TwBlazor.Components
Assembly
TwBlazor.dll

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

public class TwRadioGroup<T> : TwBlazorComponentBase, IComponent, IHandleEvent, IHandleAfterRender, ITwComponent, IAsyncDisposable

Type Parameters

T

The type of value in the radio group.

Inheritance
TwRadioGroup<T>
Implements
Inherited Members

Remarks

TwRadioGroup provides two ways to use radio groups:

  1. Manual: Add TwRadioButton components as children (ChildContent)
  2. Automatic: Provide Items and bind to Value for automatic radio button generation Radio buttons within the group should share the same Name parameter to form a mutually exclusive group. The group can be oriented horizontally or vertically, and supports customizable spacing. The component supports cascading the Name to child radio buttons.

Constructors

TwRadioGroup()

public TwRadioGroup()

Properties

ChildContent

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

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

Property Value

RenderFragment

Disabled

Gets or sets whether the entire radio group is disabled.

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

Property Value

bool

ErrorMessage

Gets or sets the error message for the group. It is shown under the options when Invalid is set, announced when it appears, and read as the group's description.

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

Property Value

string

Horizontal

Gets or sets the orientation of the radio group.

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

Property Value

bool

Remarks

Default is vertical. Set to true for horizontal orientation.

Invalid

Gets or sets whether the group as a whole is in an error state.

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

Property Value

bool

ItemColor

Gets or sets the color for automatically generated radio buttons.

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

Property Value

Color?

Items

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

[Parameter]
public IEnumerable<RadioGroupItem<T>>? Items { get; set; }

Property Value

IEnumerable<RadioGroupItem<T>>

Remarks

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

Legend

Gets or sets the legend text for the radio 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 radio buttons in the group.

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

Property Value

string

Remarks

This value is cascaded to child radio buttons to form a mutually exclusive group.

Required

Gets or sets whether one of the options must be chosen. Announced by assistive technology.

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

Property Value

bool

Value

Gets or sets the selected value.

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

Property Value

T

ValueChanged

Gets or sets the callback invoked when the selected value changes.

[Parameter]
public EventCallback<T> ValueChanged { get; set; }

Property Value

EventCallback<T>

ValueExpression

Gets or sets the expression that identifies the bound value. Set automatically by @bind-Value, it lets an enclosing EditForm or TwForm validate the property the group edits.

[Parameter]
public Expression<Func<T>>? ValueExpression { get; set; }

Property Value

Expression<Func<T>>

Methods

BuildRenderTree(RenderTreeBuilder)

Renders the component to the supplied RenderTreeBuilder.

protected override void BuildRenderTree(RenderTreeBuilder __builder)

Parameters

__builder RenderTreeBuilder

DisposeAsync()

Releases the group's connection to its form.

public ValueTask DisposeAsync()

Returns

ValueTask

A task that completes once the group is released.

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.

ValidateAsync()

Reports whether the group is valid. Called by an enclosing TwForm when it is submitted.

public Task<bool> ValidateAsync()

Returns

Task<bool>

true when the group is valid.