Skip to content

Checkbox Tree

The CheckboxTree component renders a hierarchical tree where every node has a checkbox. Checking a group cascades to all of its descendants, and parent groups automatically show an indeterminate (mixed) state when only some of their descendants are selected. It supports an optional Select All row and expand/collapse of groups.

It is a compound component composed of CheckboxTree.Root, CheckboxTree.Group, and CheckboxTree.Item. Selection is controlled via selectedIds + onSelectionChange (leaf ids only); parent/child relationships are derived from JSX nesting. Enable showCount on the Root to render each group’s leaf-descendant count (e.g. “Resources (16)”) — it is computed automatically, with no count prop to maintain.

Playground

Installation

import { CheckboxTree } from '@harnessio/ui/components'
const [selectedIds, setSelectedIds] = useState<string[]>([])
return (
<CheckboxTree.Root
className="w-full rounded-cn-2 border border-cn-3"
selectedIds={selectedIds}
onSelectionChange={setSelectedIds}
defaultExpandedIds={['resources']}
showSelectAll
>
<CheckboxTree.Group id="resources" label="Resources">
<CheckboxTree.Item id="audit-logs" label="Audit logs" />
<CheckboxTree.Item id="roles" label="Roles" />
</CheckboxTree.Group>
</CheckboxTree.Root>
)