File Tree Component
A hierarchical file/directory tree component composed of sub-components:
<file-tree>- Main tree container<file-tree--file>- File item (leaf node)<file-tree--dir>- Directory item (collapsible)
Demo
Demo with Drag-and-Drop
Features
- Collapsible directories with chevron indicators
- Hover effects on items
- Full keyboard navigation - Arrow keys, Space, Enter, F2 for rename
- Emits
file-selectedevents when files are clicked - Emits
dir-toggledevents when directories are expanded/collapsed - Drag-and-drop support - Move files and directories by dragging them
- Copy tree to clipboard - Focus any item and press Ctrl/Cmd+C to copy the tree structure in POSIX tree format
- Rename items - Press F2 on any focused item to rename it inline
- Namespaced sub-components living in the same pod
- Powered by fixture data (will eventually use GitHub API)
Usage
Basic Usage
<file-tree></file-tree>
The tree will render with default fixture data representing a typical repository structure.
With Drag-and-Drop
<file-tree dnd editable></file-tree>
Attributes:
dnd- Enables drag-and-drop functionalityeditable- When combined withdnd, prevents text selection while dragging
Drag-and-Drop Behavior:
- Drag files and directories to reorder or move them
- Visual feedback during drag (opacity change, drop zone highlighting)
- Emits
item-droppedevents withdraggedItemanddropTargetdetails - Files can be dropped into directories
Keyboard Shortcuts
The file tree supports comprehensive keyboard navigation:
| Key | Action |
|---|---|
| Arrow Up/Down | Navigate between visible items in the tree |
| Space | Toggle directory expansion/collapse |
| Enter | Toggle directory or select file |
| Tab | Move focus to next item (browser default) |
| Ctrl/Cmd+C | Copy tree structure from focused item (POSIX format) |
| F2 | Rename focused item (Enter to save, Escape to cancel) |
Copy Tree to Clipboard
Focus on any file or directory, then press Ctrl+C (or Cmd+C on Mac) to copy the tree structure starting from that item. The output will be in POSIX tree command format:
component/
โโโ cms-overlay/
โ โโโ cms-overlay.js
โ โโโ pod.toml
โ โโโ og.png
โโโ demo-automerge/
โ โโโ demo-automerge.js
โ โโโ style.css
โ โโโ pod.toml
โ โโโ post.md
โโโ file-tree/
โโโ file-tree.js
โโโ file-tree--file.js
โโโ file-tree--dir.js
โโโ pod.toml
โโโ post.md
Rename Items
Press F2 while any file or directory is focused to enter rename mode. An inline input will appear where you can type the new name. Press Enter to save or Escape to cancel. The component emits an item-renamed event with details about the old and new names.