Skip to content
Form RadioGroup

RadioGroup

A set of native radio buttons in a fieldset.

On this page

Examples

Radio group

Plan

For side projects.

For teams shipping every week.

Contact sales.

Billing

Selected plan: pro

Razor
<div class="flex flex-col gap-6 sm:flex-row sm:gap-12">
    <KlyRadioGroup TValue="string" @bind-Value="_plan" Legend="Plan" Items="Plans" />
    <KlyRadioGroup TValue="string" Legend="Billing" Orientation="KlyOrientation.Horizontal" Color="KlyColor.Neutral"
                  Items="@([new("month", "Monthly"), new("year", "Yearly")])" Value="@("month")" />
</div>
<p class="w-full text-center text-sm text-(--klyroo-text-muted)">Selected plan: @_plan</p>

@code {
    private string? _plan = "pro";

    private static readonly KlyRadioItem<string>[] Plans =
    [
        new("free", "Free") { Description = "For side projects." },
        new("pro", "Pro") { Description = "For teams shipping every week." },
        new("enterprise", "Enterprise") { Description = "Contact sales.", Disabled = true },
    ];
}

API

KlyRadioGroup<TValue>

Group of radio buttons bound to one value.

Parameters

Name Type Default Description
Class string Classes added to the root element, merged last so they win over the theme.
Color KlyColor "primary" Semantic color of the control: a built-in KlyColor or the name of a color you defined. When not set, Color applies, else primary. Values: primary, secondary, success, info, warning, error, neutral.
Disabled bool false Disables the control: it cannot be focused or changed and is not submitted.
Id string The id of the native control. Defaults to the one of the enclosing KlyFormField , else a generated one.
Items (required) IReadOnlyList<KlyRadioItem<TValue>> The radio buttons, as KlyRadioItem`1 .
Legend string Caption of the group, rendered as the legend of its fieldset.
Name string Form field name outside an EditForm . Inside one, the name comes from the bound expression.
Orientation KlyOrientation KlyOrientation.Vertical Whether the radio buttons are stacked ( Vertical ) or side by side ( Horizontal ). Values: Horizontal, Vertical.
Required bool false Marks the control as required, for the browser and for assistive technology.
Size KlySize? Defaults to the size of the enclosing KlyFormField , or medium. Values: Xs, Sm, Md, Lg, Xl.
Ui RadioGroupUi Per-instance class overrides of the slots of the radio group, see RadioGroupUi . They are merged after the theme and the Class parameter wins on the root slot.
Value (@bind-Value) TValue The value of the control. Bind it with @bind-Value .
ValueExpression Expression<Func<TValue>> The expression of the bound field. The compiler sets it with @bind-Value , and validation uses it to find the field.

Ui slots

Ui takes a RadioGroupUi with one class string per slot, merged after the theme.

Slot Styles
Root Classes merged into the root slot of KlyRadioGroup`1 , after the theme and the app configuration.
Legend Classes merged into the legend slot of KlyRadioGroup`1 , after the theme and the app configuration.
Fieldset Classes merged into the fieldset slot of KlyRadioGroup`1 , after the theme and the app configuration.
Item Classes merged into the item slot of KlyRadioGroup`1 , after the theme and the app configuration.
Container Classes merged into the container slot of KlyRadioGroup`1 , after the theme and the app configuration.
Base Classes merged into the base slot of KlyRadioGroup`1 , after the theme and the app configuration.
Indicator Classes merged into the indicator slot of KlyRadioGroup`1 , after the theme and the app configuration.
Wrapper Classes merged into the wrapper slot of KlyRadioGroup`1 , after the theme and the app configuration.
Label Classes merged into the label slot of KlyRadioGroup`1 , after the theme and the app configuration.
Description Classes merged into the description slot of KlyRadioGroup`1 , after the theme and the app configuration.