File Tree
React file tree for editor sidebars with icons by file type, git status letters, spring folder animation, a filter that expands matches and keyboard support.
Installation
npx shadcn@latest add @minidev/file-tree
MiniDev UI is in the shadcn registry directory, so the short form works with no setup. Older CLI versions can use the full URL: npx shadcn@latest add https://ui.minidev.pro/r/file-tree.json
Usage
import { FileTree } from "@/components/ui/file-tree"
export function Example() {
return (
<FileTree />
)
}
API reference
| Prop | Type | Default |
|---|---|---|
| dataNested files and folders. Paths are built from names joined by "/". | FileTreeNode[] | SAMPLE |
| defaultExpandedFolder paths open on first render. | string[] | ["app", "app/dashboard", "components"] |
| selectedControlled selected path. | string | - |
| defaultSelected | string | "app/dashboard/page.tsx" |
| activePathThe file open in the editor. Defaults to the last selected file. | string | - |
| onSelectCalled with the path of a file or folder when it is selected. | (path: string) => void | - |
| searchableShow the filter field above the tree. | boolean | true |
| showStatusShow git status letters and folder change dots. | boolean | true |
| sortSort folders first, then names alphabetically. | boolean | true |
| titleHeader title, usually the project name. Pass an empty string to hide the header. | string | "lumen-web" |
| aria-label | string | - |
| className | string | - |
When to use
Use for repos, artifacts and agent workspaces. Folders are nodes with a children array (even empty); files have none. Paths passed to onSelect are names joined by "/". Keyboard follows the WAI-ARIA tree pattern. For a generic nested list without file semantics use TreeView; for a single file citation use FileReference.
Keyboard interactions
| Key | Action |
|---|---|
| ArrowDownorArrowUp | Moves to the next or previous visible item. |
| ArrowRight | Opens a closed folder. On an open folder, moves to its first child. |
| ArrowLeft | Closes an open folder. On a file or closed folder, moves to its parent. |
| HomeorEnd | Moves to the first or last visible item. |
| EnterorSpace | Selects the item and calls onSelect. On a folder it also opens or closes it. |
| * | Opens every folder at the same level as the focused item. |
| A-Z | Moves to the next item whose name starts with the typed letters. |
| ArrowDown | In the filter field, moves focus to the first item in the tree. |
| Escape | In the filter field, clears the filter. |
Accessibility
- The list is a WAI-ARIA
role="tree"ofrole="treeitem"nodes witharia-level,aria-posinset,aria-setsize,aria-expandedon folders andaria-selected. - Git status is part of each item's name, such as "page.tsx, modified". A closed folder with changes inside reads "contains changes". The open file has
aria-current="page". - While filtering, a polite live region announces the number of matches.
- Under reduced motion folders open and close with no height animation.
Frequently asked questions
How do I mark a node as a folder?
Give it a children array, even an empty one: { name: "migrations", children: [] }. A node without children is a file. Paths are names joined by "/", such as app/dashboard/page.tsx, and that is what onSelect receives.
Can folders load their contents when opened?
No. There is no expand callback, and an empty folder shows no children. Load the whole tree first, or update data from onSelect when a folder path comes in.
Why is my file order different from my data?
sort is on by default: folders first, then names A to Z. Pass sort={false} to keep the order of data.
What does the filter field do?
It keeps names that contain the text plus their parent folders, opens those folders, and highlights the match. Folders cannot be closed while filtering. Pass searchable={false} to hide it.
Dependencies
npm
Built from
Examples
Controlled selection
Hold the selected path in state and sync it with onSelect, which fires for files and folders alike.
Custom project
Pass nested data, the folders to open on first render and the file that starts selected; status letters come from each node.
Plain tree
Turn off the filter field, the git status and the header for a quiet picker inside a form or a sheet.