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.jsonCheckbox
Using it in a form? See the react-hook-form and zod recipe.
Select all (indeterminate)
import { useState } from "react";
import { Checkbox } from "@/components/sheenui/checkbox/checkbox";
// Package build (after the first npm release, or a packed tarball): import { Checkbox } from "@sheenui/theme";
export function Example() {
const [items, setItems] = useState({ design: true, code: false, ship: false });
const all = Object.values(items).every(Boolean);
const some = Object.values(items).some(Boolean);
return (
<div className="flex flex-col gap-3">
<Checkbox
label="All tasks"
checked={all}
indeterminate={some && !all}
onCheckedChange={(v) => setItems({ design: v, code: v, ship: v })}
/>
<div className="ms-8 flex flex-col gap-3">
{(["design", "code", "ship"] as const).map((key) => (
<Checkbox
key={key}
label={key.charAt(0).toUpperCase() + key.slice(1)}
checked={items[key]}
onCheckedChange={(v) => setItems({ ...items, [key]: v })}
/>
))}
</div>
</div>
);
}Files to copy
4 folders · 4 files · 4 packages
- From
theme/src/ components/checkbox/hooks/use-latest.tslib/{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.
import { useState } from "react";
import { Button } from "@/components/sheenui/button/button";
import { Checkbox } from "@/components/sheenui/checkbox/checkbox";
// Package build (after the first npm release, or a packed tarball): import { Button, Checkbox } from "@sheenui/theme";
// This example also uses button: npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/button.json
export function Example() {
const [terms, setTerms] = useState(false);
return (
<form
onSubmit={(event) => {
event.preventDefault();
console.log(Object.fromEntries(new FormData(event.currentTarget)));
}}
className="flex flex-col items-start gap-4"
>
<Checkbox name="updates" label="Send me product updates" description="One email a month. Unsubscribe any time." defaultChecked />
<Checkbox name="terms" label="I accept the terms" checked={terms} onCheckedChange={setTerms} />
<Checkbox disabled label="Single sign-on" description="Managed by your administrator." />
<Button type="submit" disabled={!terms}>Create account</Button>
</form>
);
}Props
Keyboard
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
Related pages
67 components pages in all: browse them on All components.
By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .