DeepWorks Studios Blazor Component Library

Demo user Administrator ยท Blazor Server Library 20261206222504-6e8ff32.dirty

DwsRadioButton

Examples for the DwsRadioButtonGroup<T> and DwsRadioButton<T> components.

API Reference — DwsRadioButtonGroup API Reference — DwsRadioButton

Default selection

DefaultValue is selected once, when a group starts without a selection.

Size (DefaultValue = Medium)
Show Code
RadioButton.razor

<DwsRadioButtonGroup T='string' Name='RadioButtonDemo_Default' Label='Size (DefaultValue = Medium)' DefaultValue='@("Medium")'>
    <DwsRadioButton Name='RadioButtonDemo_Default_Small' Value='@("Small")' Label='Small' />
    <DwsRadioButton Name='RadioButtonDemo_Default_Medium' Value='@("Medium")' Label='Medium' />
    <DwsRadioButton Name='RadioButtonDemo_Default_Large' Value='@("Large")' Label='Large' />
</DwsRadioButtonGroup>

Appearance: segmented

Appearance=Segmented draws the same native inputs as a segmented control: segments of one track that wrap on a narrow screen. Arrow keys, Tab and what a screen reader hears are those of the default appearance. The selected option has an outline in the group's colour and heavier text; keyboard focus shows on the segment. Disabled options work as before.

View
Show Code
RadioButton.razor

<DwsRadioButtonGroup Name='RadioButtonDemo_Segmented' Label='View' Appearance='DwsRadioButtonGroupAppearance.Segmented' @bind-Value='@_appearanceView'>
    <DwsRadioButton Name='RadioButtonDemo_Segmented_Day' Value='@("Day")' Label='Day' />
    <DwsRadioButton Name='RadioButtonDemo_Segmented_Week' Value='@("Week")' Label='Week' />
    <DwsRadioButton Name='RadioButtonDemo_Segmented_Month' Value='@("Month")' Label='Month' />
    <DwsRadioButton Name='RadioButtonDemo_Segmented_Year' Value='@("Year")' Label='Year' Disabled='true' />
</DwsRadioButtonGroup>
<span>View: @_appearanceView</span>
RadioButton.razor.cs

private string? _appearanceView = "Week";

Appearance: segmented with multiple selection

The segmented appearance also works with SelectionMode=Multiple: every segment is a checkbox that can be toggled on its own.

Toppings (multiple selection)
Show Code
RadioButton.razor

<DwsRadioButtonGroup Name='RadioButtonDemo_SegmentedMultiple' Label='Toppings (multiple selection)' Appearance='DwsRadioButtonGroupAppearance.Segmented'
                     SelectionMode='DwsSelectionMode.Multiple' @bind-Values='@_appearanceToppings'>
    @foreach (string topping in _segmentedToppings)
    {
        <DwsRadioButton Name='@($"RadioButtonDemo_SegmentedMultiple_{topping}")' Value='topping' Label='@topping' />
    }
</DwsRadioButtonGroup>
RadioButton.razor.cs

private static readonly string[] _segmentedToppings = ["Cheese", "Mushrooms", "Olives", "Onions", "Peppers", "Pineapple"];
private IReadOnlyList<string> _appearanceToppings = ["Cheese"];

Appearance: cards

Appearance=Card draws every option as a card that can be pressed anywhere, arranged by Layout - here a grid of three, one column on a phone. Keyboard and screen reader behaviour stay those of the default appearance, and the Required error works as before.

Plan
Show Code
RadioButton.razor

<DwsRadioButtonGroup @ref='_planGroup' Name='RadioButtonDemo_Card' Label='Plan' Appearance='DwsRadioButtonGroupAppearance.Card'
                     Layout='DwsRadioButtonGroupLayout.Grid' Columns='3' Required='true' @bind-Value='@_appearancePlan'>
    <DwsRadioButton Name='RadioButtonDemo_Card_Free' Value='@("Free")' Label='Free - one project' />
    <DwsRadioButton Name='RadioButtonDemo_Card_Team' Value='@("Team")' Label='Team - ten projects, shared boards' />
    <DwsRadioButton Name='RadioButtonDemo_Card_Enterprise' Value='@("Enterprise")' Label='Enterprise - unlimited' />
</DwsRadioButtonGroup>

<DwsButton Name='RadioButtonDemo_Card_Validate' OnClick='ValidatePlan'>Validate (Required)</DwsButton>
<span>Plan: @(_appearancePlan ?? "none")</span>
RadioButton.razor.cs

private string? _appearancePlan;
private DwsRadioButtonGroup<string> _planGroup = default!;

private void ValidatePlan() => _planGroup.Validate();

Colors

Color sets the selected color through the theme's CSS variables; a button's own Color overrides the group's.

Per-button colors
Show Code
RadioButton.razor

<DwsRadioButtonGroup Name='RadioButtonDemo_Severity' Label='Per-button colors' @bind-Value='@_severity'>
    <DwsRadioButton Name='RadioButtonDemo_Severity_Low' Value='@("Low")' Label='Low' Color='DwsColor.Success' />
    <DwsRadioButton Name='RadioButtonDemo_Severity_Medium' Value='@("Medium")' Label='Medium' Color='DwsColor.Warning' />
    <DwsRadioButton Name='RadioButtonDemo_Severity_High' Value='@("High")' Label='High' Color='DwsColor.Error' />
</DwsRadioButtonGroup>
RadioButton.razor.cs

private string? _severity = "Medium";

Disabled

Disabled on the group disables every button; on a button it disables only that one. Disabled buttons keep their state and are skipped by the arrow keys.

Disabled group
One disabled button
Show Code
RadioButton.razor

<DwsRadioButtonGroup T='string' Name='RadioButtonDemo_Disabled_Group' Label='Disabled group' Disabled='true' DefaultValue='@("Yes")'>
    <DwsRadioButton Name='RadioButtonDemo_Disabled_Group_Yes' Value='@("Yes")' Label='Yes' />
    <DwsRadioButton Name='RadioButtonDemo_Disabled_Group_No' Value='@("No")' Label='No' />
</DwsRadioButtonGroup>

<DwsRadioButtonGroup T='string' Name='RadioButtonDemo_Disabled_Button' Label='One disabled button'>
    <DwsRadioButton Name='RadioButtonDemo_Disabled_Button_Available' Value='@("Available")' Label='Available' />
    <DwsRadioButton Name='RadioButtonDemo_Disabled_Button_SoldOut' Value='@("SoldOut")' Label='Sold out' Disabled='true' />
    <DwsRadioButton Name='RadioButtonDemo_Disabled_Button_Preorder' Value='@("Preorder")' Label='Pre-order' />
</DwsRadioButtonGroup>

Interface-Description

Name Typ Default Description
InputName string - The name every input of the group renders: GroupName, or the generated one.
Name Typ Parameters Description
Validate bool Checks Required now and shows the result, as a form submit would. Returns true when the group has no validation message.
ResetValidation void Hides the Required message again until the next change or validation.
FocusAsync ValueTask bool containedInScrollableList Focuses the selected button, or the first enabled one when nothing is selected.
Name Typ Default Description
Value T? default The selected value in Single mode. Supports two-way binding via @bind-Value; T is inferred from it. Setting it from code never raises ValueChanged. With ValueChanged bound the group shows the value the parent passes back, so a handler that keeps its value refuses the selection.
ValueExpression Expression<Func<T?>>? null Identifies the bound field for EditContext validation. Set automatically by @bind-Value.
Values IReadOnlyList<T>? null The selected values in Multiple mode, in selection order. Supports two-way binding via @bind-Values. Every change is reported as a new list; the given list is never modified.
ValuesExpression Expression<Func<IReadOnlyList<T>?>>? null Identifies the bound field for EditContext validation. Set automatically by @bind-Values.
SelectionMode DwsSelectionMode DwsSelectionMode.Single Single renders radio buttons bound to Value; Multiple renders checkboxes bound to Values. For a new multiple-selection list prefer DwsCheckBoxGroup: in Multiple mode each option is its own Tab stop and the arrow keys do not move between options, and DwsCheckBoxGroup adds select-all, MinSelected / MaxSelected and ReadOnly. Multiple stays supported for groups that switch mode at run time.
DefaultValue T? - Selected once, as soon as the group has buttons, when Value is not given or matches none of them. A bound parent is told through ValueChanged. A value that matches no button is logged and ignored. Takes precedence over SelectFirstWhenEmpty.
DefaultValues IReadOnlyList<T>? null Multiple-mode counterpart of DefaultValue: its values that match a button are selected once when the group starts without a selection.
SelectFirstWhenEmpty bool false Fallback for a group that starts without a valid selection and has no default: selects its first enabled button once and reports it. A Value that matches no button is logged.
GroupName string? null The native name shared by the group's inputs, which makes the browser treat them as one group (arrow keys, one tab stop). Generated when empty. A name another group on the page already uses is replaced by a generated one and logged.
Label string string.Empty Caption rendered above the buttons; also names the group for assistive technology (aria-labelledby).
Layout DwsRadioButtonGroupLayout DwsRadioButtonGroupLayout.Vertical Vertical (one button per row), Horizontal (side by side, wrapping) or Grid.
Appearance DwsRadioButtonGroupAppearance DwsRadioButtonGroupAppearance.Default How the buttons are drawn: Default (circle and label), Segmented (segments of one track, side by side and wrapping; Layout Vertical is not applied, Grid is) or Card (bordered cards arranged by Layout). A styling of the same native inputs: keyboard, form behaviour and semantics are unchanged.
Columns int 2 Number of equal-width columns for the Grid layout. Values below 1 are treated as 1.
Gap int? null Space between buttons in pixels. Uses the layout's default spacing when unset.
Color DwsColor DwsColor.Primary Color of the selected state, resolved through the theme's CSS variables. A button's own Color overrides it.
CheckedIcon string? null Icon for a selected button, replacing the native control (the input stays underneath for keyboard and screen readers). Setting either icon switches to icons; the other falls back to a matching default.
UncheckedIcon string? null Icon for an unselected button. See CheckedIcon.
Required bool false Requires a selection. The message appears after a change, after Validate(), or when an enclosing EditForm validates - where it also blocks OnValidSubmit.
RequiredErrorText string? null Message shown when Required is not met. Defaults to a localised "Please select an option." ("Please select at least one option." in Multiple mode).
ChildContent RenderFragment? null The group's DwsRadioButton<T> buttons, and any other content between them.
Name Typ Description
ValueChanged EventCallback<T?> Raised with the requested value when the user selects a button, and once for an applied DefaultValue / SelectFirstWhenEmpty. Used by @bind-Value.
ValuesChanged EventCallback<IReadOnlyList<T>> Multiple-mode counterpart of ValueChanged. Used by @bind-Values.
OnValueChanged EventCallback<T?> Raised after every user selection with the requested value. Stays available when @bind-Value is used. It reports the request, not the outcome: a bound parent may still refuse it.
OnValuesChanged EventCallback<IReadOnlyList<T>> Multiple-mode counterpart of OnValueChanged.
OnFocus EventCallback<FocusEventArgs> Raised when focus enters the group from outside. Moving between its buttons does not raise it. Needs dws.js.
OnBlur EventCallback<FocusEventArgs> Raised when focus leaves the group entirely. Moving between its buttons does not raise it. Needs dws.js.
Name Typ Default Description
Element ElementReference The associated web component. May be null if accessed before the component is rendered.
ComponentGuid Guid Unique identifier for the component.
TypeString string The name of the component type, obtained from reflection.
Authorized_RegisterEnabled bool false Indicates whether this component is enabled through a permission registry.
Authorized_RegisterSelected bool false Indicates whether this component is selected in permission selection mode.
GetInitializedState bool false Returns whether the component is initialized.
GetRenderModeState DwsRenderMode Returns the current render mode.
GetComponentState DwsComponentStateType Returns the current component state.
GetIsInteractiveState bool false Returns whether the component is interactive.
GetIsPrerenderingState bool false Returns whether the component is prerendering.
GetComponentLoadingState bool false Returns whether the component is loading.
IsFormBusy bool false Whether the DwsForm (or DwsFormBusyRegion) around the component is locked because its submit handler is running. The state itself is the cascaded FormBusyState (IDwsFormBusyState).
Name Typ Parameters Description
DebugInfo void Logs debug information about the component.
UpdateState void Updates the component's state and triggers StateHasChanged.
UpdateStateAsync Task Asynchronously updates the component's state and triggers StateHasChanged.
Dispose void Disposes the component and releases resources.
FocusAsync ValueTask bool containedInScrollableList Sets focus to the component's element.
Name Typ Default Description
Name string Required unique identifier for the component within its container.
Visible bool true Determines if the component is visible in the UI.
Disabled bool false Disables the form control, ensuring it doesn't participate in form submission.
ComponentNameSpace string The namespace for permission-based access control.
PermissionKey string? null A stable key that takes the place of Name in the generated permission namespace (Page.PermissionKey): the stored permission survives a rename, and components that share a key share one permission entry. Null: keyed by Name. Read once, when the component registers; an explicit ComponentNameSpace wins.
Class string Optional CSS class names.
Style string Optional in-line styles.
Tag object An optional user-defined object to store any additional data with the component.
BackReference DwsReference A reference to the enclosing component.
ID string The HTML ID attribute for the component.
AdditionalAttributes Dictionary<string, object> Additional HTML attributes for the group's container (e.g. aria-label when there is no Label). id, class, style, role and the aria-* state attributes are controlled by the group.
IgnorePermissionChecks bool false Bypasses all permission checks for this component.
IgnorePermissionSelection bool false Ignore permission selection mode for this component.
IgnoreFormBusy bool false Takes the component out of the submit lock of the DwsForm (or DwsFormBusyRegion) around it: IsFormBusy stays false for it.
Name Typ Description
OnInitializedCallbackStarted EventCallback Callback when OnInitialized starts.
OnInitializedCallback EventCallback Callback during OnInitialized.
OnInitializedCallbackCompleted EventCallback Callback when OnInitialized completes.
OnInitializedAsyncCallbackStarted EventCallback Callback when OnInitializedAsync starts.
OnInitializedAsyncCallback EventCallback Callback during OnInitializedAsync.
OnInitializedAsyncCallbackCompleted EventCallback Callback when OnInitializedAsync completes.
OnIsComponentLoadingChanged EventCallback<bool> Callback when IsComponentLoading changes.
OnCurrentRenderModeChanged EventCallback<DwsRenderMode> Callback when CurrentRenderMode changes.
OnComponentStateChanged EventCallback<DwsComponentStateType> Callback when ComponentState changes.

Interface-Description

Name Typ Default Description
Value T default The value this button stands for. T is taken from the enclosing DwsRadioButtonGroup<T>. Should be unique within the group - a duplicate is logged, and buttons sharing a value are selected together.
Label string string.Empty Label text rendered next to the button. Clicking it selects the button.
Tooltip string string.Empty Tooltip text shown on hover.
Haptic DwsHapticFeedback DwsHapticFeedback.Selection Tactile feedback played inside the tap when the user picks this option, while the app has haptics switched on. None turns it off for this option. Not played while the input is disabled.
Color DwsColor? null Color of this button's selected state. Falls back to the group's Color.
CheckedIcon string? null Icon shown while this button is selected. Falls back to the group's CheckedIcon.
UncheckedIcon string? null Icon shown while this button is not selected. Falls back to the group's UncheckedIcon.
Name Typ Description
OnCheckedChanged EventCallback<bool> Raised when the user's action on this button changed the selection: true when it was selected, false when a checkbox was cleared. A radio that loses its selection because another one was chosen does not raise it.
Name Typ Default Description
Element ElementReference The associated web component. May be null if accessed before the component is rendered.
ComponentGuid Guid Unique identifier for the component.
TypeString string The name of the component type, obtained from reflection.
Authorized_RegisterEnabled bool false Indicates whether this component is enabled through a permission registry.
Authorized_RegisterSelected bool false Indicates whether this component is selected in permission selection mode.
GetInitializedState bool false Returns whether the component is initialized.
GetRenderModeState DwsRenderMode Returns the current render mode.
GetComponentState DwsComponentStateType Returns the current component state.
GetIsInteractiveState bool false Returns whether the component is interactive.
GetIsPrerenderingState bool false Returns whether the component is prerendering.
GetComponentLoadingState bool false Returns whether the component is loading.
IsFormBusy bool false Whether the DwsForm (or DwsFormBusyRegion) around the component is locked because its submit handler is running. The state itself is the cascaded FormBusyState (IDwsFormBusyState).
Name Typ Parameters Description
DebugInfo void Logs debug information about the component.
UpdateState void Updates the component's state and triggers StateHasChanged.
UpdateStateAsync Task Asynchronously updates the component's state and triggers StateHasChanged.
Dispose void Disposes the component and releases resources.
FocusAsync ValueTask bool containedInScrollableList Sets focus to the component's element.
Name Typ Default Description
Name string Required unique identifier for the component within its container.
Visible bool true Determines if the component is visible in the UI.
Disabled bool false Disables the form control, ensuring it doesn't participate in form submission.
ComponentNameSpace string The namespace for permission-based access control.
PermissionKey string? null A stable key that takes the place of Name in the generated permission namespace (Page.PermissionKey): the stored permission survives a rename, and components that share a key share one permission entry. Null: keyed by Name. Read once, when the component registers; an explicit ComponentNameSpace wins.
Class string Optional CSS class names.
Style string Optional in-line styles.
Tag object An optional user-defined object to store any additional data with the component.
BackReference DwsReference A reference to the enclosing component.
ID string The HTML ID attribute for the component.
AdditionalAttributes Dictionary<string, object> Additional HTML attributes for the button's <input> element (e.g. aria-label for a button without Label, or data-testid). id, type, name, value, class, checked and disabled are controlled by the button. A button outside a DwsRadioButtonGroup of the same T is rendered disabled and logged.
IgnorePermissionChecks bool false Bypasses all permission checks for this component.
IgnorePermissionSelection bool false Ignore permission selection mode for this component.
IgnoreFormBusy bool false Takes the component out of the submit lock of the DwsForm (or DwsFormBusyRegion) around it: IsFormBusy stays false for it.
Name Typ Description
OnInitializedCallbackStarted EventCallback Callback when OnInitialized starts.
OnInitializedCallback EventCallback Callback during OnInitialized.
OnInitializedCallbackCompleted EventCallback Callback when OnInitialized completes.
OnInitializedAsyncCallbackStarted EventCallback Callback when OnInitializedAsync starts.
OnInitializedAsyncCallback EventCallback Callback during OnInitializedAsync.
OnInitializedAsyncCallbackCompleted EventCallback Callback when OnInitializedAsync completes.
OnIsComponentLoadingChanged EventCallback<bool> Callback when IsComponentLoading changes.
OnCurrentRenderModeChanged EventCallback<DwsRenderMode> Callback when CurrentRenderMode changes.
OnComponentStateChanged EventCallback<DwsComponentStateType> Callback when ComponentState changes.
An error has occurred. This app may no longer respond until reloaded.