shadcn.io is not affiliated with official shadcn/ui
Checkbox examples · Standard
Indeterminate Checkbox for React
A checkbox that starts indeterminate, the dash that stands for a partial selection.
A checkbox can be neither checked nor unchecked. This one starts in the indeterminate state, the dash that tells people some, but not all, of what it stands for is selected. The state is controlled, and the first click moves it to checked; after that it toggles like any other box. Use it for select-all boxes over lists and table rows, as in the nested list.
Preview
Installation
FAQ
When should I use indeterminate state?
On a parent checkbox when only some of its children are checked: a select-all over a list, a permission group partly granted, a table with a few rows selected. A plain yes-or-no never needs it.
How do I manage indeterminate state in React?
This demo holds the state and starts it at indeterminate. The first change stores the next checked value.
Pass indeterminate while the dash should show, and checked as a boolean. onCheckedChange receives the next boolean.
What does indeterminate look like visually?
Base UI marks the box indeterminate, but the indicator in the checkbox file only holds a CheckIcon: render a MinusIcon there for the indeterminate state to show a dash.
What happens when users click an indeterminate checkbox?
The first click stores the next boolean, so the dash becomes a check. The click after that clears it. The box is controlled, so both moves go through the same handler.
Related
- Nested List CheckboxA select-all checkbox over three indented
- Simple CheckboxA checkbox with a label for a single
- Vertical List CheckboxA stacked list of programming language
- Basic Data Table with CheckboxesA table of products with a checkbox on
- Todo Style CheckboxA to-do item whose label is struck
- Disabled CheckboxTwo disabled checkboxes, one unchecked