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.

Variations

Deeply nested groups

Groups can be nested to any depth. Each level indents its content, and every group reflects the aggregate state of all leaves beneath it.

Custom group icons

Each group renders a folder icon before its label by default. Pass the icon prop to override it with any IconV2 icon name.

Disabled nodes

Set disabled on the Root to disable the whole tree, or on an individual Group/Item.

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>
)