Skip to content
synccn

File Tree

Folders and files with icons and full keyboard navigation.

Selected: src/components/ui/button.jsx

Installation

$ pnpm dlx shadcn@latest add @synccn/file-tree

First time in this project? Connect synccn with one command.

Usage

import { FileTree } from "@/components/ui/file-tree";<FileTree data={tree} defaultExpanded={["src"]} />

API reference

Generated from the component's TypeScript types, so it always matches the code.

FileTree

Expandable tree for files and folders, with keyboard support (Up/Down to move, Right to open, Left to close, Enter to select). data: [{ name, children?: [...] }]

  • datarequired
    FileNode[]

    Top-level files and folders.

  • defaultExpanded
    string[]

    Default []

    Folder paths open at first, e.g. "src/components".

  • onSelect
    (path: string) => void

    Called with a file's path when it's chosen.

  • className
    string

    Extra classes for the root element.

Dependencies

Read from the component's imports when the site builds. The CLI installs all of these for you.

Helpers

npm packages

Keyboard

  • ↓or↑Move between rows
  • →Open a folder
  • ←Close a folder
  • EnterOpen a folder or choose a file

Accessibility

  • Uses tree and treeitem roles with aria-expanded on folders and aria-selected on the chosen file.

From the source

Read from this component's code when the site builds, so it can't drift.

  • ARIA roles: tree, treeitem
  • ARIA attributes: aria-expanded, aria-selected
  • Keys handled: ArrowUp, ArrowDown, ArrowLeft, ArrowRight
  • Shows a visible focus ring for keyboard users