Components
Checkbox
Allow users to select one or multiple options from a set with accessible checkbox inputs.
Installation
Usage
import { Checkbox } from "@/registry/core/checkbox";
export default () => <Checkbox label="Accept terms and conditions" />;Examples
With Label
Controlled
import { useState } from "react";
export default () => {
const [checked, setChecked] = useState(false);
return (
<Checkbox
label="Subscribe to newsletter"
checked={checked}
onChange={e => setChecked(e.target.checked)}
/>
);
};API Reference
Checkbox
Extends input element props.
| Prop | Type | Default | Description |
|---|---|---|---|
size | 'sm', 'md' | 'sm' | Checkbox size |
label | string | - | Label text next to checkbox |
id | string | - | Custom input ID (auto-generated if not provided) |
disabled | boolean | false | Disable checkbox interaction |
checked | boolean | - | Controlled checked state |
defaultChecked | boolean | - | Uncontrolled default checked state |
onChange | (e: ChangeEvent) => void | - | Change event handler |
Accessibility
- Uses native
<input type="checkbox">with screen reader support - Automatically generates unique IDs if not provided
- Label is properly associated with input via
htmlFor - Keyboard accessible with standard checkbox behavior
- Focus ring provides clear visual feedback
- Disabled state is communicated via
aria-disabledon the label - Hover states are disabled when checkbox is disabled
Notes
- The checkbox input uses
sr-onlyto hide it visually while keeping it accessible - Check icon appears only when checkbox is checked
- Focus ring appears on keyboard focus with
ring-4style - Hover effects apply to both the checkbox and label for better UX
- All standard input HTML attributes are supported (except
sizewhich is used for visual sizing)