Skip to content

Animated Checkbox for React

An animated checkbox for React whose check pops in, with an indeterminate state for “select all”, built on Base UI's accessible checkbox.

npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/checkbox.json

Select all (indeterminate)

Files to copy

4 folders · 4 files · 4 packages
From theme/src/
  • components/checkbox/
  • hooks/use-latest.ts
  • lib/{cn.ts, field-control-shell.tsx, form.ts}
  • styles/
shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/checkbox.jsonRegistry item: checkbox. The styles need the Tailwind v4 glass UI setup.
The examples also use
  • components/button/
  • components/spinner/
  • hooks/{use-magnetic.ts, use-media-query.ts, use-preferences.ts}
  • motion/{gate.ts, tokens.ts}
  • lib/state-light.tsx
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/button.json
Packages
pnpm add @base-ui/react clsx motion tailwind-merge

In a form

Checkboxes submit with the form through name. Here the button stays disabled until the terms are accepted.

Props

PropTypeDefaultDescription
classNamestringNoneClasses for the outer element: the <label> (or the wrapper holding an error); the control itself when there is neither.
controlClassNamestring | ((state: CheckboxRootState) => string | undefined)NoneClasses for the checkbox box itself. Base UI's state function form works here.
labelReactNodeNoneText next to the box. Clicking it toggles the checkbox. Without a label, give the checkbox an aria-label.
descriptionReactNodeNoneSecondary line under the label. It sits inside the same <label>, so screen readers read it with the label.
errorReactNodeNoneError message under the control. Marks it invalid (aria-invalid, danger border) and is announced; linked with aria-describedby.
checked / defaultCheckedbooleanfalseControlled or uncontrolled state.
indeterminatebooleanfalseShows a dash: some, but not all, children are checked.
onCheckedChange(checked) => voidNoneCalled with the new checked state when the control is toggled.
disabledbooleanfalseMakes the control non-interactive.

Keyboard

KeysAction
Tab/Shift + TabMove focus to or from the checkbox.
SpaceToggle it (Enter does not, as with a native checkbox).

Accessibility

  • A real checkbox role; indeterminate sets aria-checked="mixed".
  • The label and description share one <label>, so clicking either toggles it.
  • The unchecked border keeps 3:1 contrast; forced colors fill the box with Highlight. The touch hit area is 44 x 44 px.

When to use Checkbox

  • Use Checkbox as a React checkbox component for independent yes or no options in a settings form, such as email me about product updates, where each choice can be on or off without affecting the others.
  • Use the indeterminate prop for a select all row above a list, so the parent shows a mixed state when only some of the child checkboxes are checked.
  • Use label and description for a terms and conditions line, with the explanation under the label sharing one label element so clicking either toggles the box.
  • Skip it when the setting applies immediately with no submit step. Use Switch for that, and RadioGroup when exactly one option out of several must be picked.
  • Pair it with Field or a form library for validation, Button for the submit action, and DataTable, which uses checkbox cells for row selection and bulk actions.

Frequently asked questions

67 components pages in all: browse them on All components.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .