Checkbox
A composable, accessible Checkbox component for modern React applications.
tsx
import { Checkbox } from '@nofinite/nui';Interactive Preview
Loading preview...
A binary selection control that allows users to toggle between checked, unchecked, and indeterminate states. Supports controlled and uncontrolled usage, labels, disabled state, and accessibility-friendly behavior.
Usage
Basic Checkbox
tsx
import { Checkbox } from '@nofinite/nui';
<Checkbox label="Accept terms" />
<Checkbox defaultChecked label="Subscribed" />
<Checkbox checked={true} label="Controlled checkbox" />Indeterminate Checkbox
tsx
<Checkbox indeterminate label="Select all" />Controlled Checkbox
tsx
const [checked, setChecked] = useState(false);
<Checkbox
checked={checked}
onChange={setChecked}
label="Enable notifications"
/>;Disabled Checkbox
tsx
<Checkbox disabled label="Disabled option" />Variants
Checkbox supports state-based variants.
tsx
<Checkbox /> // Unchecked
<Checkbox defaultChecked /> // Checked
<Checkbox indeterminate /> // Indeterminate
<Checkbox disabled /> // DisabledAvailable variants:
unchecked– Default empty checkboxchecked– Selected checkbox with checkmarkindeterminate– Mixed state with dash indicatordisabled– Non-interactive checkbox
Guidelines:
- Use
indeterminatefor parent selection logic (e.g., partial list selection). - Use controlled mode (
checked) when state is managed externally. - Use disabled when interaction must be prevented but state remains visible.
States
| State | Description |
|---|---|
checked | Displays checkmark indicator |
indeterminate | Displays dash indicator |
unchecked | Empty checkbox |
disabled | Reduced opacity and no interaction |
Accessibility
- Renders a native
<input type="checkbox">for full semantic support - Uses
aria-checked="mixed"for indeterminate state - Focus-visible ring improves keyboard navigation
- Label wrapping ensures large clickable target
- SVG indicators are
aria-hiddento avoid redundancy
Best Practices
Do
- Use labels for clarity and accessibility
- Use controlled mode when checkbox state affects other UI
- Use indeterminate for hierarchical selections (e.g., tree views)
Don’t
- Rely solely on visual state without labels
- Use indeterminate as a permanent state
- Disable checkbox without explaining why interaction is blocked
API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
checked | boolean | — | — |
defaultChecked | boolean | — | — |
indeterminate | boolean | false | — |
onChange | ((checked: boolean) => void) | — | — |
label | ReactNode | — | — |