Skip to content

Checkbox Tree

beta

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.

Usage

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

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.

API Reference

CheckboxTree.Root Props

Prop
Required
Default
Type
selectedIdstruestring[]
onSelectionChangetrue(ids: string[]) => void
defaultExpandedIdsfalsestring[]
showSelectAllfalsefalseboolean
selectAllLabelfalse'Select All'string
showCountfalsefalseboolean
disabledfalseboolean
classNamefalsestring

CheckboxTree.Group Props

Prop
Required
Default
Type
idtruestring
labeltrueReact.ReactNode
disabledfalseboolean
iconfalse'folder'IconV2NamesType

CheckboxTree.Item Props

Prop
Required
Default
Type
idtruestring
labeltrueReact.ReactNode
disabledfalseboolean