Skip to documentation content

File Tree

Show a project's folders and files, with the files an agent added, changed, or deleted marked.

file-tree-demo

Overview

File Tree shows the files an agent is working in. Folders open and close, one node can be chosen, and each file the agent touched carries a letter: A for added, M for modified, D for deleted. Use onSelect to show the chosen file in a Code View.

Pass the tree as nested nodes. A node with children, even an empty list, is a folder. Each node's id is its path from the root, such as app/invoices/page.tsx, unless you pass id.

Anatomy

FileTree
  • HeaderAn optional title, such as the project name
  • FolderA chevron, a folder icon, and the name
  • FileA file icon, the name, and a change letter

Behavior

Folders

Clicking a folder chooses it and opens or closes it. A closed folder that holds changes shows a dot, so a change is never hidden inside it. Open folders are controlled with expanded and onExpandedChange, or start from defaultExpanded.

Choosing

Clicking a node, or pressing Enter or Space on it, chooses it and calls onSelect. The chosen node keeps a neutral fill. Control it with selected, or start from defaultSelected.

Changes

Added files show a green A, modified files an amber M, and deleted files a red D with the name struck through. Files the agent did not touch show nothing.

Accessibility

File Tree follows the tree view pattern. The tree is named by its title, or by "Files". Each node reports its level, its place among its siblings, whether it is chosen, and, for a folder, whether it is open. Only one node is a tab stop; arrow keys move between nodes. Change letters are read as "Added", "Modified", and "Deleted", and a closed folder's dot as "Contains changes".

KeyAction
ArrowDown and ArrowUpMove to the next or previous visible node
ArrowRightOpen a closed folder, or move into an open one
ArrowLeftClose an open folder, or move to the parent
Home and EndMove to the first or last visible node
EnterChoose the node, and open or close a folder
SpaceChoose the node
*Open every folder beside the focused node
LettersMove to the next node whose name starts with them

In right-to-left layouts, the left and right arrows swap.

Installation

npx honestui@latest add file-tree

Usage

import { FileTree } from "@/components/ai/file-tree"

<FileTree nodes={workspace.files} onSelect={(id) => openFile(id)} />

<FileTree
  title={project.name}
  nodes={workspace.files}
  expanded={openFolders}
  onExpandedChange={setOpenFolders}
  selected={activeFile}
  onSelect={setActiveFile}
/>

API reference

FileTree

Accepts native div props beyond those listed.

PropTypeDefaultDescription
nodesFileTreeNode[]RequiredThe top-level folders and files.
titleReactNodeNoneA heading that also names the tree.
expandedstring[]NoneThe ids of open folders, controlled.
defaultExpandedstring[][]The folders open at first.
onExpandedChange(expanded: string[]) => voidNoneRuns when a folder opens or closes.
selectedstring | nullNoneThe chosen node's id, controlled.
defaultSelectedstring | nullnullThe node chosen at first.
onSelect(id: string, node: FileTreeNode) => voidNoneRuns when a node is chosen.
labelsPartial<FileTreeLabels>EnglishThe tree's name and the change names.

Types

ExportShape
FileTreeNodename, and optional id, children, and change
FileTreeChange"added", "modified", or "deleted"