Get StartedComponentsStylingThemingMath & Science
MCP

Data

File Tree

A tree of folders and files with the icons already wired up: the folder icon switches between closed and open, files get a document icon, and folders get a chevron. Built on Tree View, so every Tree View prop works here too.

Pass plain data (id, name, children) instead of writing a render function. Use TreeView directly when you need checkboxes, renaming or a fully custom row.

Markdown

Import

tsx
import { FileTree } from "@indoku/ui"

Anatomy

<FileTree items={[{ id, name, children?, icon? }]} />​node with children (even [])  ->  folder: chevron + folder icon (closed or open) + namenode without children         ->  file:   file icon + name

Examples

Default icons

Folders open and close, and the icon follows. Folders with an empty children array still count as folders.

Project

src
index.ts
empty-folder
package.json
README.md

Icons by file type

fileIcon accepts a function that receives the node, so you can choose an icon from the name or extension. folderIcon and folderOpenIcon take plain elements.

src
components
button.tsx
card.tsx
index.ts
empty-folder
package.json
README.md

Icon on a single node

Set icon on a node to override the icon for that node, in both the open and closed state.

docs
intro.md
src
index.ts

Controlled

Use expandedValue and selectedValue to drive the tree from your own state. Values are node ids.

src
index.ts
empty-folder
package.json
README.md

Selected: none

No chevron, no guides, multiple selection

Turn off the chevron with showChevron={false} and the guide lines with indentGuides={false}. selectionMode comes straight from Tree View.

src
index.ts
empty-folder
package.json
README.md

Props

FileTree

PropTypeDefaultDescription
items*FileTreeNode[]–Top-level nodes.
labelReactNode–Heading shown above the tree.
folderIconReactNode | ((node: FileTreeNode) => ReactNode)a folder iconIcon of a closed folder.
folderOpenIconReactNode | ((node: FileTreeNode) => ReactNode)an open folder iconIcon of an open folder.
fileIconReactNode | ((node: FileTreeNode) => ReactNode)a document iconIcon of a file; pass a function to choose by name or extension.
showChevronbooleantrueShow the chevron before folders.
indentGuidesbooleantrueVertical guide lines for nested levels.

* required. Style props and HTML attributes are accepted as well.

Accessibility

  • Same behavior as Tree View: WAI-ARIA tree pattern, arrow keys to move and expand or collapse, Home and End, Enter or Space to select.
  • Default icons are decorative (aria-hidden). When you pass your own icons, keep them decorative too; the node name carries the meaning.

Notes

  • items should be a stable reference (module constant or useMemo). A new array on every render rebuilds the tree.
  • Node id must be unique across the whole tree, not just among siblings. Paths such as src/components/button.tsx work well.
  • Default icons are inline SVG, so the component adds no icon dependency. Any React element works as a custom icon.

Created by @indokudev