Skip to content
EspañolEnglish
All components (283)

File tree

Navigation · FileTree

What it is and when to use it

A tree of files and folders built from a list of paths: folders first, natural order (a2 before a10) and an icon per file type.

When to use it

  • Showing or choosing among the files of a project, a repository or a package.
  • paths are the paths with / (src/index.ts); a path ending in / is an empty folder. The key of each row is its full path.
  • onSelect gives the path and whether it is a file or a folder; defaultOpenDepth says how many levels start open (1 by default); details adds a small text on the right, by path.
  • A folder without its own entry in details says how many items it holds.

When not to

  • A tree of data that are not files (categories, org chart): Tree.
  • An explorer with views, dragging and uploading: FileManager.
  • The files of an upload with its progress: FileList.

Keyboard: it is a Tree: Tab enters, Up and Down Arrow go through the rows, Right Arrow opens a folder and Left Arrow closes it, Home and End go to the ends, and typing jumps to the row that starts with that letter.

Accessibility: a tree grid (role="treegrid") named after label; each row says its level, its position and whether it is open. The file type is seen through the icon but the name always carries its extension written out.

Fine-tuning: the --amset-tree-* variables of the tree.

What it looks like

docs2 items
anexos0 items
guia.md
public2 items
hero.png
logo.svg
src3 items
index.ts
package.json
README.md

<FileTree
  label="Project files"
  paths={["src/index.ts", "src/components/Button.tsx", "docs/guia.md", "README.md"]}
/>

Props

Import it with import { FileTree } from '@amset/ui'. Required props are marked.

PropTypeWhat it does
labelrequiredstringWhat the tree is of: "Project files". Required.
pathsrequiredreadonly string[]The file paths, with `/`: `src/index.ts`. A path ending in `/` is an empty folder.
classNamestringMerged with the library classes; it does not replace them.
defaultOpenDepthnumberHow many folder levels start open. 1 by default.
defaultValuestring—
detailsReadonly<Record<string, string>>A small text to the right of each row, by path: the size of a file, the number of changes.
onSelect(path: string, kind: "file" | "folder") => voidCalled when a row is chosen, with its path and whether it is a file or a folder.
size"sm" | "md" | "lg"—
valuestring | nullThe chosen path, when controlled from outside.

It also accepts the attributes of the element it renders: className, style, data-*, aria-* and its events.

In the test bench

Every state and variant, to try one at a time, on its page at storybook.amsetui.com: