Skip to content
Browse documentation
DocsComponents

Checkbox

Select one or more independent options.

Notification channels

Installation

Terminal
pnpm dlx shadcn@latest add https://react-toolbox.io/r/checkbox.json

New 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

PropertyTypeDefault
labelReact.ReactNode—
rippleboolean—
classNamesCheckboxTheme

Classes for the component's rendered parts. Applied after legacy theme overrides.

—
themeDeprecated aliasCheckboxTheme

Use classNames for style slots; use ThemeProvider for design tokens.

—
refReact.Ref<CheckboxHandle>—

Callbacks

PropertyTypeDefault
onMouseEnterReact.MouseEventHandler<HTMLLabelElement>—
onMouseLeaveReact.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:

  • check
  • checked
  • checkmark-expand
  • disabled
  • field
  • input
  • ripple
  • text

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
tsx
type CheckboxTheme = Partial<
  Record<'checkmark-expand' | 'check' | 'checked' | 'disabled' | 'field' | 'input' | 'ripple' | 'text', string>
>;
CheckboxClassNames
tsx
type CheckboxClassNames = CheckboxTheme;
CheckboxHandle
tsx
interface CheckboxHandle {
  focus(): void;
  blur(): void;
  readonly inputElement: HTMLInputElement | null;
}
CheckboxProps
tsx
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.

Material Design 1: Selection controls