File Tree
Show a project's folders and files, with the files an agent added, changed, or deleted marked.
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
- 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".
In right-to-left layouts, the left and right arrows swap.
Installation
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.