RadioListInput
The RadioListInput component is used to capture a single selection with Bulma's radio list styling, typed data items, and Blazor-friendly binding.
How it works #
The RadioListInput component renders a typed collection of Bulma-styled radio buttons and binds the selected value to your Blazor state through a single component.
How to use:
This demo shows the default single-select behavior of the
How to use:
- Create a list of
RadioListInputItem<TValue>items for the available choices. - Add the
RadioListInputcomponent and set the matchingTValuetype. - Bind the current selection with
@bind-Value.
RadioListInput component.
Selected attendance: going
<RadioListInput TValue="string"
Items="@attendanceItems"
@bind-Value="@selectedAttendance" />
<p class="mt-3">
Selected attendance: @selectedAttendance
</p>
@code {
private readonly List<RadioListInputItem<string>> attendanceItems =
[
new("going", "Going"),
new("not-going", "Not going"),
new("maybe", "Maybe")
];
private string selectedAttendance = "going";
}
Disable #
The RadioListInput component can be disabled to prevent user interaction while still displaying the current selected option.
How to use:
This demo shows how to render the entire radio list in a disabled state.
How to use:
- Add the
RadioListInputcomponent to your page. - Set
Disabled="true"to make the entire radio list non-interactive. - Pass the same typed items and selected value as usual.
Selected contact method: email
<RadioListInput TValue="string"
Items="@contactMethodItems"
Value="@selectedContactMethod"
Disabled="true" />
<p class="mt-3">
Selected contact method: @selectedContactMethod
</p>
@code {
private readonly List<RadioListInputItem<string>> contactMethodItems =
[
new("email", "Email"),
new("sms", "SMS"),
new("phone", "Phone")
];
private string selectedContactMethod = "email";
}
Conditional disable #
Individual radio items can be disabled by setting the
How to use:
This demo illustrates how to disable only selected radio items based on your application rules.
Disabled property on specific RadioListInputItem<TValue> entries.
How to use:
- Create your item collection in code.
- Set
Disabled = trueonly for the entries that should not be selectable. - Pass the updated collection to the
Itemsparameter.
Selected shipping method: standard
<RadioListInput TValue="string"
Items="@shippingItems"
@bind-Value="@selectedShippingMethod" />
<p class="mt-3">
Selected shipping method: @selectedShippingMethod
</p>
@code {
private readonly List<RadioListInputItem<string>> shippingItems =
[
new("standard", "Standard"),
new("express", "Express"),
new("overnight", "Overnight") { Disabled = true }
];
private string selectedShippingMethod = "standard";
}
Validations #
Integrate RadioListInput with Blazor's form validation system by using it inside an
How to use:
This demo shows how to validate a radio list selection before submission.
EditForm and binding the selected value to a model property with validation attributes.
How to use:
- Wrap the component in an
EditFormand bind it with@bind-Value. - Add
DataAnnotationsValidatorand aValidationMessagefor the same property. - Use a validation attribute such as
Requiredto require a selection before form submission.
Select a support plan and submit the form.
@using System.ComponentModel.DataAnnotations
@using Microsoft.AspNetCore.Components.Forms
<style>
.radio.valid.modified {
color: hsl(var(--bulma-success-h), var(--bulma-success-s), var(--bulma-success-l)) !important;
}
.radio.valid.modified input {
outline: 1px solid hsl(var(--bulma-success-h), var(--bulma-success-s), var(--bulma-success-l)) !important;
outline-offset: 0.15rem;
}
.radio.invalid {
color: hsl(var(--bulma-danger-h), var(--bulma-danger-s), var(--bulma-danger-l)) !important;
}
.radio.invalid input {
outline: 1px solid hsl(var(--bulma-danger-h), var(--bulma-danger-s), var(--bulma-danger-l)) !important;
outline-offset: 0.15rem;
}
.validation-message {
color: hsl(var(--bulma-danger-h), var(--bulma-danger-s), var(--bulma-danger-l)) !important;
}
</style>
<EditForm EditContext="@editContext" OnValidSubmit="OnValidSubmit">
<DataAnnotationsValidator />
<div style="max-width: 24rem;">
<RadioListInput TValue="string"
Items="@supportPlanItems"
@bind-Value="subscription.SupportPlan" />
<ValidationMessage For="@(() => subscription.SupportPlan)" />
</div>
<Button Class="mt-3" Color="ButtonColor.Primary" Type="ButtonType.Submit" Size="ButtonSize.Small">
Submit
</Button>
</EditForm>
<div class="mt-3">@resultMessage</div>
@code {
private SubscriptionModel subscription = new();
private EditContext? editContext;
private string resultMessage = "Select a support plan and submit the form.";
private readonly List<RadioListInputItem<string>> supportPlanItems =
[
new("basic", "Basic"),
new("standard", "Standard"),
new("premium", "Premium")
];
protected override void OnInitialized()
{
editContext = new EditContext(subscription);
base.OnInitialized();
}
private void OnValidSubmit()
{
resultMessage = $"Submitted support plan: {subscription.SupportPlan}";
}
private sealed class SubscriptionModel
{
[Required(ErrorMessage = "Please select a support plan.")]
public string? SupportPlan { get; set; }
}
}
Events: ValueChanged #
The RadioListInput component exposes a
How to use:
This demo shows how to handle selection changes through the
ValueChanged event, allowing you to react whenever the selected value changes.
How to use:
- Set the
Valueparameter to the current selection. - Handle the
ValueChangedcallback to update your page state when the selection changes. - Use the updated selected value elsewhere in your UI as needed.
ValueChanged event.
Selected theme: system
<RadioListInput TValue="string"
Items="@themeItems"
Value="@selectedTheme"
ValueChanged="OnValueChanged" />
<div class="mt-2">Selected theme: @selectedTheme</div>
@code {
private readonly List<RadioListInputItem<string>> themeItems =
[
new("light", "Light"),
new("system", "System"),
new("dark", "Dark")
];
private string selectedTheme = "system";
private void OnValueChanged(string value)
{
selectedTheme = value;
}
}