Pro unlocks unlimited templates48:00:00Get Pro →

Tree Checkbox

Nested checkboxes with cascade select. Checking a parent selects every descendant; partial children show the parent as indeterminate. Branches collapse with logical indent for LTR and RTL.

Gallery

Permissions tree with cascade select. Toggle Documents — parents show indeterminate when partial.

Loading…

Installation

CLI
npx @sonojs/ui@latest add tree-checkbox
Also needs
npx @sonojs/ui@latest add checkbox collapsible
npm i lucide-react

Usage

tree-checkbox.tsx
import { TreeCheckbox } from "@/components/tree-checkbox"

const data = [
  {
    id: "fruits",
    label: "Fruits",
    children: [
      { id: "apple", label: "Apple" },
      { id: "banana", label: "Banana" },
    ],
  },
]

export function Example() {
  return (
    <TreeCheckbox
      data={data}
      defaultExpanded={["fruits"]}
      onValueChange={(ids) => console.log(ids)}
    />
  )
}

Props

PropTypeDefaultDescription
dataTreeCheckboxNode[]-Forest of nodes (`id`, `label`, optional `children` / `disabled`).
valuestring[]-Controlled checked node ids (includes fully selected parents).
defaultValuestring[][]Initial checked ids when uncontrolled.
onValueChange(value: string[]) => void-Fires after cascade toggle.
expandedstring[]-Controlled open branch ids.
defaultExpandedstring[][]Initial open branches when uncontrolled.
onExpandedChange(expanded: string[]) => void-Fires when a branch opens or closes.
disabledbooleanfalseDisables the entire tree.
classNamestring-Merged onto the tree root.

Related