Checkbox
A control that toggles between checked, unchecked, and indeterminate states.
<NaviusCheckbox @bind-Checked="_checked"
class="... data-[checked]:bg-primary">
<NaviusCheckboxIndicator class="flex items-center justify-center">
<CheckIcon />
</NaviusCheckboxIndicator>
</NaviusCheckbox>
<label>Accept terms and conditions</label>
@code { private bool _checked = true; }Features
- Full keyboard navigation.
- Supports an indeterminate state (
@bind-CheckedStatewithbool?). - Can be controlled (
@bind-Checked) or uncontrolled (DefaultChecked). - Renders a hidden input so it participates in native form submission.
-
role="checkbox"with the correctaria-checkedstate (including"mixed").
Installation
Install the brain, or copy just this primitive in with the CLI.
navius add checkboxAnatomy
Import the parts and assemble them.
@using Navius.Primitives.Components.Checkbox
<NaviusCheckbox>
<NaviusCheckboxIndicator />
</NaviusCheckbox>API Reference
Root
Contains all the parts of a checkbox. Renders a button.
| Prop | Type | Default |
|---|---|---|
| Checked | bool | false |
| CheckedChanged | EventCallback<bool> | - |
| DefaultChecked | bool | false |
| CheckedState | bool? | - |
| CheckedStateChanged | EventCallback<bool?> | - |
| DefaultCheckedState | bool? | - |
| Disabled | bool | false |
| Required | bool | false |
| Name | string? | - |
| Value | string | "on" |
| ChildContent | RenderFragment? | - |
Data attributes
| Data attribute | Values |
|---|---|
| [data-checked] | Present when checked |
| [data-unchecked] | Present when unchecked |
| [data-indeterminate] | Present when indeterminate |
| [data-disabled] | Present when disabled |
Indicator
Renders when the checkbox is in a checked or indeterminate state. Renders a span.
| Prop | Type | Default |
|---|---|---|
| KeepMounted | bool | false |
| ChildContent | RenderFragment? | - |
Data attributes
| Data attribute | Values |
|---|---|
| [data-checked] | Present when checked |
| [data-unchecked] | Present when unchecked |
| [data-indeterminate] | Present when indeterminate |
| [data-disabled] | Present when disabled |
Accessibility
Adheres to the tri-state checkbox WAI-ARIA design pattern.
Keyboard interactions
| Key | Description |
|---|---|
| Space | Toggles the component's state. |