Skip to content

FileTree

The FileTree component renders interactive hierarchical file trees with collapsible directories, file type icons, and optional annotations.

Basic example

Collapsed by default

Set defaultExpanded: false to start with all directories collapsed.

With annotations

Annotations appear as muted badges next to file names — useful for marking file status.

Properties

PropertyTypeDefaultDescription
rootstringOptional root directory label
treeFileNode[](required)Array of file/directory nodes (min 1)
defaultExpandedbooleantrueWhether directories start expanded

FileNode

PropertyTypeDefaultDescription
namestring(required)File or directory name
annotationstringOptional badge text (e.g. “new”)
childrenFileNode[]Child nodes (presence = directory)

Interaction events

When interactive: true is set, the file tree emits a filetree-select event when the user clicks a file or directory.

```ui:filetree
interactive: true
root: project
defaultExpanded: true
tree:
- name: src
children:
- name: index.ts
- name: utils.ts
- name: package.json
```

Event kind: filetree-select

Payload fieldTypeDescription
pathstringFull path from root (e.g., project/src/index.ts).
type"file" | "directory"Whether the clicked item is a file or directory.
expandedboolean | undefinedFor directories, whether it was expanded or collapsed. Not present for files.

Accessibility

  • The tree uses role="tree" on the root <ul> and role="treeitem" on each node.
  • Directories include aria-expanded indicating their open/closed state.
  • Keyboard navigation follows the WAI-ARIA Treeview pattern:
    • ArrowDown / ArrowUp — move focus between visible items
    • ArrowRight — expand directory, or move to first child
    • ArrowLeft — collapse directory, or move to parent
    • Enter / Space — toggle expand/collapse
    • Home / End — move to first/last visible item
  • Annotations are included in each item’s aria-label.