Skip to content

Tree View

The TreeView component displays hierarchical data in an expandable/collapsible tree. It’s built from Tree, Folder, File, and an optional CollapseButton, and supports selection, status indicators, execution details, and RTL/LTR text direction.

Variations

Basic tree structure

Create a simple tree with folders and files. The tree automatically handles expand/collapse interactions.

With status indicators

The tree displays status icons based on the ExecutionState. It supports states like SUCCESS, RUNNING, FAILURE, PENDING, and more.

With initial selection

Specify an initially selected item with initialSelectedId. The tree automatically expands the parent folders to reveal it.

With initial expanded items

Control which folders start expanded with initialExpendedItems.

Non-selectable items

Make specific items non-selectable by setting isSelectable={false}.

With collapse button

Add an expand/collapse-all control with the CollapseButton component.

RTL support

The tree supports right-to-left text direction with the dir prop.

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