CheckboxGroup
A fieldset of native checkboxes bound to a list of values.
On this page
Examples
Checkbox group
Selected: email
Razor
<div class="flex flex-col gap-6 sm:flex-row sm:gap-12">
<KlyCheckboxGroup TValue="string" Legend="Notifications" Items="Items" @bind-Value="_selected" />
<KlyCheckboxGroup TValue="int" Legend="Days" Orientation="KlyOrientation.Horizontal" Items="Days" Value="@([1, 3])" Color="KlyColor.Neutral" />
</div>
<p class="w-full text-center text-sm text-(--klyroo-text-muted)" data-testid="checkbox-group-state">Selected: @(_selected.Count > 0 ? string.Join(", ", _selected) : "none")</p>
@code {
private IReadOnlyList<string> _selected = ["email"];
private static readonly KlyCheckboxItem<string>[] Items =
[
new("email", "Email") { Description = "Weekly digest." },
new("sms", "SMS"),
new("push", "Push") { Description = "Not available yet.", Disabled = true },
];
private static readonly KlyCheckboxItem<int>[] Days = [new(1, "Mon"), new(2, "Tue"), new(3, "Wed")];
}API
KlyCheckboxGroup<TValue>
Group of checkboxes that binds to the list of the selected values.
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 |
The checkboxes of the group, as KlyCheckboxItem`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. |
Whether the checkboxes 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 |
CheckboxGroupUi |
Per-instance class overrides of the slots of the checkbox group, see CheckboxGroupUi . They are merged after the theme and the Class parameter wins on the root slot. | |
Value (@bind-Value) |
IReadOnlyList |
The value of the control. Bind it with @bind-Value . | |
ValueExpression |
Expression |
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 CheckboxGroupUi with one class string per slot, merged after the theme.
| Slot | Styles |
|---|---|
Root |
Classes merged into the root slot of KlyCheckboxGroup`1 , after the theme and the app configuration. |
Legend |
Classes merged into the legend slot of KlyCheckboxGroup`1 , after the theme and the app configuration. |
Fieldset |
Classes merged into the fieldset slot of KlyCheckboxGroup`1 , after the theme and the app configuration. |
Item |
Classes merged into the item slot of KlyCheckboxGroup`1 , after the theme and the app configuration. |
Container |
Classes merged into the container slot of KlyCheckboxGroup`1 , after the theme and the app configuration. |
Base |
Classes merged into the base slot of KlyCheckboxGroup`1 , after the theme and the app configuration. |
Icon |
Classes merged into the icon slot of KlyCheckboxGroup`1 , after the theme and the app configuration. |
Wrapper |
Classes merged into the wrapper slot of KlyCheckboxGroup`1 , after the theme and the app configuration. |
Label |
Classes merged into the label slot of KlyCheckboxGroup`1 , after the theme and the app configuration. |
Description |
Classes merged into the description slot of KlyCheckboxGroup`1 , after the theme and the app configuration. |