CheckboxListInput
The CheckboxListInput component is used to capture multiple selections with Bulma's checkbox list styling, typed data items, and Blazor-friendly binding.
How it works #
The CheckboxListInput component renders a typed collection of Bulma-styled checkboxes and binds the selected values to your Blazor state as a list.
How to use:
This demo shows the default multi-select behavior of the
How to use:
- Create a list of
CheckboxListInputItem<TValue>items for the available choices. - Add the
CheckboxListInputcomponent and set the matchingTValuetype. - Bind the selected values with
@bind-Values.
CheckboxListInput component.
Selected days: saturday, sunday
<CheckboxListInput TValue="string"
Items="@weekDayItems"
@bind-Values="@selectedDays" />
<p class="mt-3">
Selected days: @(selectedDays.Count == 0 ? "None" : string.Join(", ", selectedDays))
</p>
@code {
private readonly List<CheckboxListInputItem<string>> weekDayItems =
[
new("monday", "Monday"),
new("tuesday", "Tuesday"),
new("wednesday", "Wednesday"),
new("thursday", "Thursday"),
new("friday", "Friday"),
new("saturday", "Saturday"),
new("sunday", "Sunday")
];
private List<string> selectedDays = ["saturday", "sunday"];
}
Data parameter #
The CheckboxListInput component uses the
How to use:
This demo shows how to populate the checkbox list from a strongly typed data collection.
Items parameter to render typed checkbox data from your page or view model.
How to use:
- Create a typed list of
CheckboxListInputItem<TValue>values in your code. - Pass that list to the
Itemsparameter. - Bind the
Valuesparameter to track which items are selected.
Selected feature ids: 101, 103
<CheckboxListInput TValue="int"
Items="@featureItems"
@bind-Values="@selectedFeatureIds" />
<p class="mt-3">
Selected feature ids: @(selectedFeatureIds.Count == 0 ? "None" : string.Join(", ", selectedFeatureIds))
</p>
@code {
private readonly List<CheckboxListInputItem<int>> featureItems =
[
new(101, "Audit logs"),
new(102, "API access"),
new(103, "Dark theme"),
new(104, "Offline mode")
];
private List<int> selectedFeatureIds = [101, 103];
}
Sizes #
The CheckboxListInput component supports multiple sizes so you can match the list to the density and emphasis of the surrounding form layout.
How to use:
This demo shows the available size variants for
How to use:
- Add the
CheckboxListInputcomponent with your typed items and selected values. - Set
Sizeto one of the availableCheckboxListInputSizevalues:Small,Normal,Medium, orLarge. - Use the size that best fits the visual weight of the rest of your form.
CheckboxListInput.
<CheckboxListInput TValue="string"
Class="mb-4"
Items="@notificationItems"
Size="CheckboxListInputSize.Small"
@bind-Values="@smallValues" />
<CheckboxListInput TValue="string"
Class="mb-4"
Items="@notificationItems"
Size="CheckboxListInputSize.Normal"
@bind-Values="@normalValues" />
<CheckboxListInput TValue="string"
Class="mb-4"
Items="@notificationItems"
Size="CheckboxListInputSize.Medium"
@bind-Values="@mediumValues" />
<CheckboxListInput TValue="string"
Items="@notificationItems"
Size="CheckboxListInputSize.Large"
@bind-Values="@largeValues" />
@code {
private readonly List<CheckboxListInputItem<string>> notificationItems =
[
new("builds", "Build notifications"),
new("releases", "Release notifications"),
new("alerts", "Alert notifications")
];
private List<string> largeValues = ["releases"];
private List<string> mediumValues = ["releases"];
private List<string> normalValues = ["releases"];
private List<string> smallValues = ["releases"];
}
Orientation #
The CheckboxListInput component can render checkboxes horizontally or vertically, depending on how much horizontal space you want each option to take.
How to use:
This demo shows both supported orientation modes for
How to use:
- Add the
CheckboxListInputcomponent with your typed items and selected values. - Set
OrientationtoCheckboxListInputOrientation.HorizontalorCheckboxListInputOrientation.Vertical. - Use the default horizontal layout for compact forms, or vertical for stacked lists.
CheckboxListInput.
<CheckboxListInput TValue="string"
Class="mb-4"
Items="@taskItems"
Orientation="CheckboxListInputOrientation.Horizontal"
@bind-Values="@horizontalValues" />
<CheckboxListInput TValue="string"
Items="@taskItems"
Orientation="CheckboxListInputOrientation.Vertical"
@bind-Values="@verticalValues" />
@code {
private readonly List<CheckboxListInputItem<string>> taskItems =
[
new("planning", "Planning"),
new("design", "Design"),
new("testing", "Testing")
];
private List<string> horizontalValues = ["planning"];
private List<string> verticalValues = ["planning"];
}
Disabled #
The CheckboxListInput component can be disabled to prevent user interaction while still displaying the current selections.
How to use:
This demo shows how to render the entire checkbox list in a disabled state.
How to use:
- Add the
CheckboxListInputcomponent to your page. - Set
Disabled="true"to make the entire checkbox list non-interactive. - Pass the same typed items and selected values as usual.
<CheckboxListInput TValue="string"
Disabled="true"
Items="@environmentItems"
Values="@selectedEnvironments" />
@code {
private readonly List<CheckboxListInputItem<string>> environmentItems =
[
new("dev", "Development"),
new("test", "Testing"),
new("prod", "Production")
];
private readonly List<string> selectedEnvironments = ["dev", "test"];
}
Conditional disable individual checkboxes #
Individual checkbox items can be disabled by setting the
How to use:
This demo illustrates how to disable only selected checkbox items based on your application rules.
Disabled property on specific CheckboxListInputItem<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 permissions: read, export
<CheckboxListInput TValue="string"
Items="@permissionItems"
@bind-Values="@selectedPermissions" />
<p class="mt-3">
Selected permissions: @(selectedPermissions.Count == 0 ? "None" : string.Join(", ", selectedPermissions))
</p>
@code {
private readonly List<CheckboxListInputItem<string>> permissionItems =
[
new("read", "Read"),
new("write", "Write"),
new("delete", "Delete") { Disabled = true },
new("export", "Export")
];
private List<string> selectedPermissions = ["read", "export"];
}
Events: ValuesChanged #
The CheckboxListInput component exposes a
How to use:
This demo shows how to handle selection changes through the
ValuesChanged event, allowing you to react whenever the selected values list changes.
How to use:
- Set the
Valuesparameter to the current selection list. - Handle the
ValuesChangedcallback to update your page state when the selection changes. - Use the updated values elsewhere in your UI as needed.
ValuesChanged event.
Selected frameworks: Blazor, MAUI
<CheckboxListInput TValue="string"
Items="@frameworkItems"
Values="@selectedFrameworks"
ValuesChanged="OnValuesChanged" />
<p class="mt-3">@message</p>
@code {
private readonly List<CheckboxListInputItem<string>> frameworkItems =
[
new("blazor", "Blazor"),
new("minimal-api", "Minimal API"),
new("maui", "MAUI"),
new("worker", "Worker Service")
];
private string message = "Selected frameworks: Blazor, MAUI";
private List<string> selectedFrameworks = ["blazor", "maui"];
private Task OnValuesChanged(List<string> values)
{
selectedFrameworks = values;
message = values.Count == 0
? "Selected frameworks: None"
: $"Selected frameworks: {string.Join(", ", values)}";
return Task.CompletedTask;
}
}
Custom item template #
The CheckboxListInput component supports an
How to use:
This demo shows how to customize each checkbox label with richer markup while keeping the built-in behavior.
ItemTemplate parameter so you can render richer checkbox labels without replacing the component.
How to use:
- Pass your typed items to the
Itemsparameter. - Add an
ItemTemplateblock and use the current item context to render custom content. - Keep the checkbox selection binding with
Valuesor@bind-Values.
Selected notifications: deployments, mentions
<CheckboxListInput TValue="string"
Items="@notificationItems"
@bind-Values="@selectedNotifications">
<ItemTemplate Context="item">
<span>
<strong>@item.Text</strong>
<span class="is-size-7 has-text-grey ml-2">@GetDescription(item.Value)</span>
</span>
</ItemTemplate>
</CheckboxListInput>
<p class="mt-3">
Selected notifications: @(selectedNotifications.Count == 0 ? "None" : string.Join(", ", selectedNotifications))
</p>
@code {
private readonly List<CheckboxListInputItem<string>> notificationItems =
[
new("deployments", "Deployments"),
new("security", "Security alerts"),
new("mentions", "Mentions")
];
private List<string> selectedNotifications = ["deployments", "mentions"];
private static string GetDescription(string value) =>
value switch
{
"deployments" => "Production and staging release updates",
"security" => "Critical dependency and access warnings",
"mentions" => "Direct mentions from your teammates",
_ => string.Empty
};
}
Validations #
Integrate CheckboxListInput with Blazor's form validation system by using it inside an
How to use:
This demo shows how to validate a checkbox list selection before form submission.
EditForm and binding the selected values to a model property with validation attributes.
How to use:
- Wrap the component in an
EditFormand bind it to a model property with@bind-Values. - Add
DataAnnotationsValidatorand aValidationMessagefor the same property. - Use a validation attribute such as
MinLengthto require one or more selections.
Choose at least one delivery day and submit the form.
@using System.ComponentModel.DataAnnotations
@using Microsoft.AspNetCore.Components.Forms
<style>
.valid.modified:not([type=checkbox]) {
border-color: hsl(var(--bulma-success-h), var(--bulma-success-s), var(--bulma-success-l)) !important;
outline: 1px solid hsl(var(--bulma-success-h), var(--bulma-success-s), var(--bulma-success-l)) !important;
}
.invalid {
border-color: hsl(var(--bulma-danger-h), var(--bulma-danger-s), var(--bulma-danger-l)) !important;
outline: 1px solid hsl(var(--bulma-danger-h), var(--bulma-danger-s), var(--bulma-danger-l)) !important;
}
.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;">
<CheckboxListInput TValue="string"
Items="@deliveryDayItems"
@bind-Values="subscription.DeliveryDays" />
<ValidationMessage For="@(() => subscription.DeliveryDays)" />
</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 = "Choose at least one delivery day and submit the form.";
private readonly List<CheckboxListInputItem<string>> deliveryDayItems =
[
new("monday", "Monday"),
new("wednesday", "Wednesday"),
new("friday", "Friday")
];
protected override void OnInitialized()
{
editContext = new EditContext(subscription);
base.OnInitialized();
}
private void OnValidSubmit()
{
resultMessage = $"Submitted delivery days: {string.Join(", ", subscription.DeliveryDays)}";
}
private sealed class SubscriptionModel
{
[MinLength(1, ErrorMessage = "Please select at least one delivery day.")]
public List<string> DeliveryDays { get; set; } = [];
}
}
Methods: Select all and clear #
The CheckboxListInput component includes helper methods that are useful when you want to control selection programmatically.
How to use:
This demo demonstrates programmatic selection helpers for common developer workflows.
How to use:
- Capture a component reference with
@ref. - Call
SelectAllAsync()to select all enabled items. - Call
ClearAsync()to clear the current selection list.
Selected modules: billing
<div class="buttons">
<Button Class="mt-3" Color="ButtonColor.Link" Type="ButtonType.Submit" Size="ButtonSize.Small" @onclick="SelectAllAsync">
Select all
</Button>
<Button Class="mt-3" Color="ButtonColor.Light" Type="ButtonType.Submit" Size="ButtonSize.Small" @onclick="ClearAsync">
Clear
</Button>
</div>
<CheckboxListInput @ref="checkboxListInputRef"
TValue="string"
Items="@moduleItems"
Values="@selectedModules"
ValuesChanged="OnValuesChanged" />
<p class="mt-3">
Selected modules: @(selectedModules.Count == 0 ? "None" : string.Join(", ", selectedModules))
</p>
@code {
private CheckboxListInput<string> checkboxListInputRef = default!;
private readonly List<CheckboxListInputItem<string>> moduleItems =
[
new("billing", "Billing"),
new("catalog", "Catalog"),
new("orders", "Orders"),
new("reports", "Reports") { Disabled = true }
];
private List<string> selectedModules = ["billing"];
private Task ClearAsync() => checkboxListInputRef.ClearAsync();
private Task OnValuesChanged(List<string> values)
{
selectedModules = values;
return Task.CompletedTask;
}
private Task SelectAllAsync() => checkboxListInputRef.SelectAllAsync();
}