Skip to content

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.

src/registry/ui/file-tree.tsx/r/file-tree.json

Installation

bash
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

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

export function Example() {
  return (
    <FileTree />
  )
}

API reference

FileTree props
PropTypeDefault
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-
defaultSelectedstring"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.booleantrue
showStatusShow git status letters and folder change dots.booleantrue
sortSort folders first, then names alphabetically.booleantrue
titleHeader title, usually the project name. Pass an empty string to hide the header.string"lumen-web"
aria-labelstring-
classNamestring-

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

Keyboard interactions
KeyAction
ArrowDownorArrowUpMoves to the next or previous visible item.
ArrowRightOpens a closed folder. On an open folder, moves to its first child.
ArrowLeftCloses an open folder. On a file or closed folder, moves to its parent.
HomeorEndMoves to the first or last visible item.
EnterorSpaceSelects 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-ZMoves to the next item whose name starts with the typed letters.
ArrowDownIn the filter field, moves focus to the first item in the tree.
EscapeIn the filter field, clears the filter.

Accessibility

  • The list is a WAI-ARIA role="tree" of role="treeitem" nodes with aria-level, aria-posinset, aria-setsize, aria-expanded on folders and aria-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

lucide-reactmotion

Built from

No other MiniDev files

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.

All Developer tool UI components for React

Learn more