Checkbox
A control that allows a user to select one or more items from a set.
Usage
import {Checkbox} from "@/components/ui/checkbox";
<Checkbox />;Components
Checkbox
| Prop | Type | Default | Description |
|---|---|---|---|
checked | boolean | "indeterminate" | - | Controlled. Whether the checkbox is checked. |
defaultChecked | boolean | "indeterminate" | - | Uncontrolled. Initial checked state. |
onCheckedChange | (checked: boolean) => void | - | Callback fired when the checked state changes. |
disabled | boolean | false | Whether the checkbox is disabled. |
loading | boolean | false | Whether the checkbox is in a loading state. Adds a pulse animation and disables interaction. |
size | "sm" | "md" | "lg" | "md" | Size variant of the checkbox. |
color | "primary" | "secondary" | "success" | "warning" | "destructive" | "primary" | Color scheme applied when the checkbox is checked. |
borderRadius | "none" | "sm" | "md" | "lg" | "xl" | "full" | "md" | Border radius of the checkbox container. |
baseClassName | string | - | Tailwind classes applied to the root element (overrides className). |
iconClassName | string | - | Tailwind classes applied to the icon element. |
Also extends all React Native Pressable component props.
Hooks
useCheckbox
The internal hook that powers the Checkbox component, providing state management and accessibility via @react-aria.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
checked | boolean | "indeterminate" | - | Controlled checked state. |
defaultChecked | boolean | "indeterminate" | - | Uncontrolled default checked state. |
onCheckedChange | (checked: boolean) => void | - | Callback fired when the checked state changes. |
disabled | boolean | - | Whether the checkbox is disabled. |
loading | boolean | - | Whether the checkbox is in a loading state. |
...props | AriaToggleButtonProps | - | Additional @react-aria/button toggle props. |
Returns:
{
state: {
isChecked: boolean;
setIsChecked: (isChecked: boolean) => void;
};
props: ComponentProps<typeof Pressable>;
}| Property | Type | Description |
|---|---|---|
state.isChecked | boolean | Whether the checkbox is currently checked. |
state.setIsChecked | (isChecked: boolean) => void | Setter for the checked state (no-op when controlled). |
props | ComponentProps<typeof Pressable> | Accessibility & interaction props for the root Pressable. |
Accessibility
The Checkbox component is built with accessibility in mind and includes:
Web Accessibility
- Follows the WAI-ARIA checkbox pattern .
- Uses
useToggleButtonto provide correct semantics and keyboard support (⌨️ Space / Enter to toggle). - Announces checked, unchecked, mixed (indeterminate) and disabled states via
aria-checkedandaria-disabled. - Works with
useFocusRingfor accurate focus management.
React Native Accessibility
- Sets
accessibilityRole="checkbox"so screen readers announce it correctly. - Updates
accessibilityState={{checked, disabled}}to reflect the current state, including"mixed"for indeterminate. - Ensures a touch target of at least 44×44 pt.
- Uses visual icon changes plus state announcements for immediate feedback.
Styling
Checkbox Classes
Slots:
baseThe rootPressableelement.iconThe icon (CheckIcon/DotIcon).
Variants:
size:smSmall icon size (w-2 h-2).md(default) Medium icon size (w-3.5 h-3.5).lgLarge icon size (w-5 h-5).
color:primary(default),secondary,success,warning,destructiveUsed whencheckedistrue.
borderRadius:none,sm,md(default),lg,xl,fullBorder radius of the checkbox.
disabled:trueAppliesopacity-50.
loading:trueAppliesanimate-pulse.
checked:trueApplies background color based oncolorvariant.
Base Classes:
base:flex flex-row items-center justify-center bg-transparent border focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2icon:text-primary-foreground