Skip to content

Tree View

The TreeView component displays hierarchical data in an expandable/collapsible tree. It’s built from Tree, Folder, and File, with an optional CollapseButton. Folders automatically handle expand/collapse interactions, and each node shows a status icon driven by its ExecutionState (SUCCESS, RUNNING, FAILURE, PENDING, and more) alongside an optional duration.

Selection and expansion are controlled through the Tree props: initialSelectedId highlights a node and automatically expands its ancestors to reveal it, while initialExpendedItems opens specific folders on mount. Individual nodes can be made non-selectable with isSelectable={false}, a CollapseButton expands or collapses the whole tree at once, and the dir prop switches between left-to-right and right-to-left text direction.

Playground

Variations

With initial expanded items

Control which folders start expanded with initialExpendedItems.

A comprehensive example combining multiple nested levels, various execution states, durations, initial selection and expansion, collapse/expand all, and a mix of selectable and non-selectable items in a real-world CI/CD structure.

Installation

import {
Tree,
Folder,
File,
CollapseButton,
type TreeViewElement,
} from "@harnessio/ui/components";
import { ExecutionState } from "@harnessio/ui/types";
<Tree initialSelectedId="1-1" className="h-96 w-full rounded-cn-3 border">
<Folder
element="Documents"
value="folder-1"
status={ExecutionState.SUCCESS}
level={0}
>
<File value="1-1" status={ExecutionState.SUCCESS} level={1}>
File 1
</File>
</Folder>
</Tree>;