Checkbox

Free

A glass checkbox whose tick draws itself, with a mixed state for a parent, rows that click anywhere, and a save that can fail and put itself back.

npx shadcn@latest add https://pixilui.com/r/checkbox.json

Preview

The tick draws itself just after the color comes up.
Save

When to use

Use it when

  • Picking several from a short list: the tools an agent may use, the sources a search reads.
  • A parent over a group, showing all, none or some (mixed) with an "n of m" count.
  • An agreement or opt-in inside a form that is submitted later.

Use something else when

  • A setting that takes effect at once: use Switch.
  • One choice among a few: use Radio group.
  • A long list with search: use a menu with checkbox rows.

Installation

Terminal
npx shadcn@latest add https://pixilui.com/r/checkbox.json

Adds checkbox.tsx, and installs clsx and tailwind-merge. The URL works in any app with a components.json, with no registry to add first.

Usage

example.tsx
import { Checkbox } from "@/components/pixilui/checkbox";

<Checkbox onCheckedChange={onCheckedChange}>Save changes</Checkbox>

The box is 14px at every width; a row's words wrap beside it, the box on the first line.

API reference

PropTypeDefault
namestring–A form field name: a hidden input carries value while the box is on.
defaultCheckedCheckboxCheckedfalseUncontrolled: the state on the first render.
checkedCheckboxChecked–Controlled: on, off, or "mixed" (a parent with some of its children on).
onCheckedChange(checked: boolean) => void | Promise<void>–Runs with the new state on a click, Space or Enter. Return a promise to save first: the box shows the new state, is aria-busy until it settles, and goes back if it rejects.
valuestring"on"The value sent with the form while on.

Also takes every native <button> attribute except onChange, value, defaultValue, role, and a ref.

Keyboard

TabMoves to each checkbox in turn.
Space EnterTurns the focused checkbox on or off.

Accessibility

  • A button with role="checkbox" and aria-checked true, false or mixed.
  • In a CheckboxRow the label names it and the second line describes it (aria-describedby); alone, give it an aria-label.
  • The row is a label, so a click on the words reaches the box once.
  • While a returned promise is pending the box is aria-busy and keeps its focus.

Motion

  • On, the candy glass cross-fades in over 200ms and the tick draws itself 40ms later in 220ms; mixed draws its dash in 180ms.
  • Press scales the box to .9; hover darkens the edge and previews a faint tick.
  • Boxes checked on the first render show their tick at once: it draws only after the page has painted.
  • Reduced motion: no transitions, the tick shown at once.
SwitchThe knob springs across and clears into a lens while held.
Radio groupThe picked radio's white bead springs in.
Dropdown menuA highlight glides between rows, and each row's icon plays as it lands.

PixilUI Pro opens soon. The first 20 licenses are $99.