Skip to content
Hazine

Checkbox Tree with Mixed Parent

A parent checkbox that controls an indented list of child checkboxes and shows a mixed state when only some are checked. Use it for permission scopes or export field selection.

How it differs. Two levels: the parent derives checked, unchecked or mixed from its children and sets them all when toggled. Children hang off a guide line under the parent, which carries a running count.

Install

pnpm dlx shadcn@latest add @hazine/checkbox-tree-mixed-parent

Adds 1 file, 1 Hazine item (@hazine/use-controllable-state), and 2 packages (lucide-react, class-variance-authority).

First time? Add the registry to components.json
{
  "registries": {
    "@hazine": "https://api.hazine.dev/r/{name}.json"
  }
}

Needed once per project. Items resolve each other through the @hazine namespace.

Props13

labelrequired
string
Text of the parent checkbox. Also names the group of children.
description
string
itemsrequired
CheckboxTreeItem[]
value
string[]
Values of the checked children.
defaultValue
string[]
onValueChange
(value: string[]) => void
name
string
Form field name given to every child checkbox.
disabled
boolean = false
loading
boolean = false
loadingLabel
string = "Loading options"
error
React.ReactNode
Validation message. Marks the parent invalid while present.
empty
React.ReactNode = "No options available."
Shown in place of the children when `items` is empty.
formatCount
(checked: number, total: number) => string = defaultFormatCount
Count at the end of the parent row, also announced after each change.

Also accepts every prop of Omit<React.ComponentProps<"div">, "defaultValue" | "onChange" | "children"> and VariantProps<typeof checkboxTreeMixedParentVariants>.

Accessibility

Keyboard
Keyboard support for Checkbox Tree with Mixed Parent
KeyEffect
TabMoves to the parent checkbox, then to each enabled child in order
Space on the parentChecks every enabled child, or clears them when all are already checked
Space on a childToggles that child and updates the parent to checked, unchecked or mixed
Screen reader

The parent is a button with role checkbox and aria-checked true, false or mixed, so the mixed state is correct before hydration. Children are native checkboxes in a group labelled by the parent, and the count describes the parent and repeats in a status region.

  • Announces: {label}: {checked} of {total}
  • Announces: Loading options
Reduced motion
Colour transitions only. The loading skeleton does not pulse.
Checked
Not checked yet. Automated results appear here once CI has run.

Dependencies3

  • @hazine/use-controllable-state
  • lucide-react
  • class-variance-authority

Filled chips are registry items the CLI adds for you. Outlined chips are npm packages.

Tokens shipped0

None. The item is styled by the tokens your theme already has.

More in Selection Controls