Checkbox
React Checkbox components are used to let users select one or more options from a list. They are commonly used in forms, settings panels, and preference selections.
This Checkbox component is built with React Aria Components' Checkbox and styled using Tailwind CSS and the Tailgrids theme tokens. It keeps native checkbox semantics, supports indeterminate and invalid states, and lets the label be the component's children.
Installation
npx @tailgrids/cli@latest add checkboxUsage
Import the component and pass the label as children. Without a visible label, provide an accessible name with aria-label.
import { Checkbox } from "@/components/tailgrids/checkbox";
export default function CheckboxExample() {
return <Checkbox defaultSelected>Accept terms and conditions</Checkbox>;
}Examples
Sizes
The Checkbox component supports two sizes: sm (default) and md.
With Label
Pass the label as the checkbox's children. Use isIndeterminate for a partially selected state.
Controlled
Control the state with isSelected and onChange. onChange receives the new boolean value.
Not subscribed
API Reference
Checkbox
Extends React Aria's Checkbox props.
| Prop | Type | Default | Description |
|---|---|---|---|
size | 'sm' | 'md' | 'sm' | Checkbox size |
children | ReactNode | - | The label displayed next to the checkbox |
isSelected | boolean | - | Controlled selected state |
defaultSelected | boolean | - | Initial selected state when uncontrolled |
onChange | (isSelected: boolean) => void | - | Called with the new state when it changes |
isIndeterminate | boolean | false | Shows the mixed state |
isDisabled | boolean | false | Disables the checkbox |
isReadOnly | boolean | false | Makes the checkbox read-only |
isRequired | boolean | false | Marks the checkbox as required |
isInvalid | boolean | false | Shows the invalid state |
aria-label | string | - | Accessible name when no visible label is used |
className | string | - | Additional classes for the root element |
Accessibility
- Uses a visually hidden native
<input type="checkbox">with standard keyboard support - The label is associated automatically; without a visible label, set
aria-label - Fully keyboard accessible with standard checkbox behavior (Space toggles)
- Visible focus ring provides clear keyboard feedback
- Disabled, invalid and indeterminate states are exposed to assistive technology
