Checkbox
Select one or more independent options.
Installation
pnpm dlx shadcn@latest add https://react-toolbox.io/r/checkbox.jsonNew here? Set up your project first. Styles, fonts, and required components are included.
Usage
Keep checked in state and update it from onChange. Use a visible label, or supply an aria-label for an otherwise unlabeled control.
Use the Code tab above for a complete example. The import follows your configured UI alias. See Theming to customize colors, spacing, and style slots.
State and callbacks
Checkbox is controlled: pass checked and update it with the boolean received by onChange. checked defaults to false. Do not use defaultChecked as a substitute for checked; the component renders its checked prop.
The change callback receives the next boolean first and the input click event second. Its ref exposes focus(), blur(), and inputElement.
API reference
Generated from the installed TypeScript source. Defaults are the values declared by each function; a dash means no parameter default is declared. Forwarded props can use the receiving component’s default. Callback types show the exact arguments passed to your handler.
Checkbox
| Property | Type | Default |
|---|---|---|
label | React.ReactNode | — |
ripple | boolean | — |
classNames | CheckboxThemeClasses for the component's rendered parts. Applied after legacy theme overrides. | — |
themeDeprecated alias | CheckboxThemeUse classNames for style slots; use ThemeProvider for design tokens. | — |
ref | React.Ref<CheckboxHandle> | — |
Callbacks
| Property | Type | Default |
|---|---|---|
onMouseEnter | React.MouseEventHandler<HTMLLabelElement> | — |
onMouseLeave | React.MouseEventHandler<HTMLLabelElement> | — |
onChange | (checked: boolean, event: React.MouseEvent<HTMLInputElement>) => void | — |
Also inherits Omit<React.InputHTMLAttributes<HTMLInputElement>, 'onChange' | 'type' | 'size' | 'onMouseEnter' | 'onMouseLeave'>, except the omissions and overrides in its exported props type below. Use the supported native aria-*, data-*, event, and element attributes as appropriate.
Additional defaults on inherited props: checked = false; className = ''; disabled = false.
Style slots
Pass a map of Tailwind classes to classNames. Available keys:
checkcheckedcheckmark-expanddisabledfieldinputrippletext
theme is the deprecated compatibility alias. When both are provided, classNames wins conflicting utilities within each slot. See Theming for tokens and override rules.
Exported TypeScript types
Expand a type to inspect its full declaration, including generic constraints, union branches, callback arguments, ref handles, and inherited props. Import these types from @/components/ui/material/checkbox.
CheckboxTheme
type CheckboxTheme = Partial<
Record<'checkmark-expand' | 'check' | 'checked' | 'disabled' | 'field' | 'input' | 'ripple' | 'text', string>
>;CheckboxClassNames
type CheckboxClassNames = CheckboxTheme;CheckboxHandle
interface CheckboxHandle {
focus(): void;
blur(): void;
readonly inputElement: HTMLInputElement | null;
}CheckboxProps
interface CheckboxProps
extends Omit<
React.InputHTMLAttributes<HTMLInputElement>,
'onChange' | 'type' | 'size' | 'onMouseEnter' | 'onMouseLeave'
> {
label?: React.ReactNode;
onMouseEnter?: React.MouseEventHandler<HTMLLabelElement>;
onMouseLeave?: React.MouseEventHandler<HTMLLabelElement>;
ripple?: boolean;
/** Classes for the component's rendered parts. Applied after legacy theme overrides. */
classNames?: CheckboxTheme;
/** @deprecated Use classNames for style slots; use ThemeProvider for design tokens. */
theme?: CheckboxTheme;
ref?: React.Ref<CheckboxHandle>;
onChange?: (checked: boolean, event: React.MouseEvent<HTMLInputElement>) => void;
}Material guidelines
- Use checkboxes for independent choices in a set. A single setting that takes effect immediately is usually better represented by a switch.
- Keep a clear label beside each option and make the label part of its interaction area.