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
TThe type of value in the radio group.
- Inheritance
-
TwRadioGroup<T>
- Implements
- Inherited Members
Remarks
TwRadioGroup provides two ways to use radio groups:
- Manual: Add TwRadioButton components as children (ChildContent)
- 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
Disabled
Gets or sets whether the entire radio group is disabled.
[Parameter]
public bool Disabled { get; set; }
Property Value
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
Horizontal
Gets or sets the orientation of the radio group.
[Parameter]
public bool Horizontal { get; set; }
Property Value
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
ItemColor
Gets or sets the color for automatically generated radio buttons.
[Parameter]
public Color? ItemColor { get; set; }
Property Value
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
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
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 radio buttons in the group.
[Parameter]
public string? Name { get; set; }
Property Value
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
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
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
__builderRenderTreeBuilder
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()