Checkbox
Boolean input with checkbox styling and two-way binding.
The Checkbox component provides a styled checkbox input for boolean selections.
Installation
bash
shellui add checkbox
Usage
Basic
<Checkbox Checked="@isChecked" CheckedChanged="@HandleChanged" />
@code {
private bool isChecked = false;
private void HandleChanged(bool value)
{
isChecked = value;
}
}
Two-way Binding
<Checkbox @bind-Checked="isChecked" />
@code {
private bool isChecked = false;
}
With Label
<div class="flex items-center space-x-2">
<Checkbox @bind-Checked="acceptTerms" />
<Label>I accept the terms and conditions</Label>
</div>
@code {
private bool acceptTerms = false;
}
Disabled
<div class="flex items-center space-x-2">
<Checkbox Checked="true" Disabled="true" />
<Label>Disabled checkbox</Label>
</div>
Form Integration
<Form OnValidSubmit="HandleSubmit">
<div class="space-y-4">
<div class="flex items-center space-x-2">
<Checkbox @bind-Checked="model.AcceptTerms" />
<Label>Accept terms and conditions</Label>
</div>
<div class="flex items-center space-x-2">
<Checkbox @bind-Checked="model.Subscribe" />
<Label>Subscribe to newsletter</Label>
</div>
<Button Type="submit">Submit</Button>
</div>
</Form>
@code {
private FormModel model = new();
private void HandleSubmit() { }
private class FormModel
{
public bool AcceptTerms { get; set; }
public bool Subscribe { get; set; }
}
}
API Reference
| Parameter | Type | Default | Description |
|---|---|---|---|
Checked |
bool |
false |
Checked state |
CheckedChanged |
EventCallback<bool> |
— | Fires when checked state changes |
Disabled |
bool |
false |
Disables the checkbox |
Class |
string? |
null |
Additional CSS classes |
Accessibility
- Proper ARIA attributes (
role="checkbox",aria-checked) - Keyboard navigation support (Space to toggle)
- Screen reader compatible