Skip to content
GitHub11 stars

Provides shared state to a series of radio buttons.

Best apple
<RadioGroupRoot aria-labelledby="@_id" Value="fuji-apple" class="radio-group">
    <div class="radio-group-caption" id="@_id">
        Best apple

Usage guidelines

Anatomy

Import the primitives and assemble the parts:

@using Blazix.Primitives

<RadioGroupRoot>
    <RadioRoot>
        <RadioIndicator />
    </RadioRoot>
</RadioGroupRoot>

Examples

Labeling a radio group

Label the group with aria-labelledby and a sibling label element:

Using aria-labelledby to label a radio group
<div id="storage-type-label">Storage type</div>
<RadioGroupRoot aria-labelledby="storage-type-label">...</RadioGroupRoot>

An enclosing <label> is the simplest labeling pattern for each radio:

Using an enclosing label to label a radio button
<label>
    <RadioRoot Value="ssd" />
    SSD
</label>

RadioRoot renders a <span> with a hidden native <input> beside it. To label a radio with a sibling <label>, point the label's for at the hidden input's id, set with InputId:

Sibling label
<div id="storage-type">Storage type</div>
<RadioGroupRoot Value="ssd" aria-labelledby="storage-type">
    <div>
        <label for="storage-type-ssd">SSD</label>
        <RadioRoot Value="ssd" InputId="storage-type-ssd">
            <RadioIndicator />
        </RadioRoot>
    </div>
</RadioGroupRoot>

API Reference

RadioGroupRoot

Renders a <div> element.

ParameterTypeDefault
Value string? -
ValueChanged

Called with the new value when Value changes, for @bind-Value.

EventCallback<string?> -
OnValueChange

Runs before the value changes, with the reason; call Cancel() to keep it.

EventCallback<ValueChangeEventArgs<string?>> -
Disabled

Whether the component should ignore user interaction.

bool false
ReadOnly

Whether the user should be unable to change the value. It stays focusable.

bool false
Required

Whether the user must enter a value before submitting a form.

bool false
Name string? -
Render RenderFragment<RadioGroupRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-disabled

Present when the radio group is disabled.

-

RadioRoot

Renders a <span> element.

ParameterTypeDefault
Valuerequired string -
Disabled

Whether the component should ignore user interaction.

bool false
ReadOnly

Whether the user should be unable to change the value. It stays focusable.

bool false
Required

Whether the user must enter a value before submitting a form.

bool false
Name string? -
InputId string? -
Render RenderFragment<RadioRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-checked

Present when the radio is checked.

-
data-unchecked

Present when the radio is not checked.

-
data-disabled

Present when the radio is disabled.

-
data-readonly

Present when the radio is readonly.

-
data-required

Present when the radio is required.

-
data-valid

Present when the radio is in a valid state (when wrapped in FieldRoot).

-
data-invalid

Present when the radio is in an invalid state (when wrapped in FieldRoot).

-
data-dirty

Present when the radio's value has changed (when wrapped in FieldRoot).

-
data-touched

Present when the radio has been touched (when wrapped in FieldRoot).

-
data-filled

Present when the radio is checked (when wrapped in FieldRoot).

-
data-focused

Present when the radio is focused (when wrapped in FieldRoot).

-

RadioIndicator

Renders a <span> element.

ParameterTypeDefault
KeepMounted bool false
Render RenderFragment<RadioRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-checked

Present when the radio is checked.

-
data-unchecked

Present when the radio is not checked.

-
data-disabled

Present when the radio is disabled.

-
data-readonly

Present when the radio is readonly.

-
data-required

Present when the radio is required.

-
data-valid

Present when the radio is in a valid state (when wrapped in FieldRoot).

-
data-invalid

Present when the radio is in an invalid state (when wrapped in FieldRoot).

-
data-dirty

Present when the radio's value has changed (when wrapped in FieldRoot).

-
data-touched

Present when the radio has been touched (when wrapped in FieldRoot).

-
data-filled

Present when the radio is checked (when wrapped in FieldRoot).

-
data-focused

Present when the radio is focused (when wrapped in FieldRoot).

-
data-starting-style

Present when the radio indicator begins animating in.

-
data-ending-style

Present when the radio indicator is animating out.

-