File Tree
A nested list of folders and files for browsing and previewing project files.
identity:
name: forecast
parameters:
- name: city
type: string
required: true
- name: days
type: numberUsage guidelines
- Use it to browse and preview files: Folders are disclosure buttons and files are buttons. The feature owns data loading, routing, renaming, drag and drop and per-item actions.
- It is not an ARIA tree:
FileTreerenders a labelled<section>of nested lists, notrole="tree". Every row is a separate tab stop, and arrow keys,Home,Endand typeahead do not move between rows. Keep trees short enough to tab through, or add a search or filter next to large ones. - Name the tree: Give
FileTreeanaria-labeloraria-labelledbythat says what the files belong to, such as "Weather plugin files". - Mark the open file with
selected:selectedsetsaria-current="true"and the highlighted row style. Keep one selected file, driven by the feature's state or route. - A file click previews, it does not navigate:
FileTreeFilerenders a<button>. HandleonClickto open the preview; do not render a link through it. - Use
disabledfor entries that cannot be opened: A disabled folder keeps its open state but cannot be toggled, and a disabled file leaves the tab order. - Let the context set the indent: Nesting
FileTreeFolderPanelraises the level and draws one guide per level. Passlevelonly when rendering a row outside its folder, such as a virtualized flat list.
Anatomy
FileTreeFolder is a Base UI Collapsible root rendered as <li>; FileTreeFile wraps its button in an <li>. FileTreeIcon is decorative, so the row's name comes from FileTreeLabel and any meta or badge text. Rows render one FileTreeGuide per nesting level themselves; render it directly only in a custom row.
Examples
Rendering from data
Render folders and files recursively from the feature's data. FileTreeMeta adds a short status after the label and FileTreeBadge a compact value such as a size. Both become part of the row's accessible name.
Controlled folders
Pass open and onOpenChange to FileTreeFolder when something outside the tree opens folders, such as an expand-all action or revealing the file that is open in the editor.
Workflow files
Disabled entries
A disabled folder keeps its current open or closed state and cannot be toggled, while a disabled file cannot be opened. Explain why with FileTreeMeta when the reason is not obvious.
Keyboard
| Key | Action |
|---|---|
| Tab | Moves focus to the next visible folder or file. Disabled folders and files are skipped. |
| Shift+Tab | Moves focus to the previous visible folder or file. |
| EnterorSpace | On a folder, expands or collapses it. On a file, activates it. |
API reference
FileTree
A composable hierarchical file list built with Base UI Collapsible. Renders a <section> element.
Folders are disclosure buttons and files are preview buttons; feature code owns data loading, routing, and item actions.
| Prop | Type | Default | Details |
|---|---|---|---|
render | ComponentRenderFn<HTMLProps, {}> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
FileTreeBadge
| Prop | Type | Default | Details |
|---|---|---|---|
render | ComponentRenderFn<HTMLProps, {}> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
FileTreeFile
| Prop | Type | Default | Details |
|---|---|---|---|
level | number | No default | |
selected | boolean | false | |
render | ComponentRenderFn<HTMLProps, FileTreeFileState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
| Attribute | Description |
|---|---|
data-selected | Present when the file is the selected row. |
data-disabled | Present when the file is disabled. |
FileTreeFolder
Groups all parts of the collapsible. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
className | string | ((state: CollapsibleRootState) => string | undefined) | No default | |
open | boolean | No default | |
defaultOpen | boolean | false | |
onOpenChange | ((open: boolean, eventDetails: CollapsibleRootChangeEventDetails) => void) | No default | |
disabled | boolean | false | |
render | ComponentRenderFn<HTMLProps, CollapsibleRootState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: CollapsibleRootState) => React.CSSProperties | undefined) | No default | |
| Attribute | Description |
|---|---|
data-open | Present when the collapsible is open. |
data-closed | Present when the collapsible is closed. |
data-starting-style | Present when the collapsible begins animating in. |
data-ending-style | Present when the collapsible is animating out. |
FileTreeFolderPanel
A panel with the collapsible contents. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
boolean | false | ||
keepMounted | boolean | false | |
className | string | ((state: CollapsiblePanelState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, CollapsiblePanelState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: CollapsiblePanelState) => React.CSSProperties | undefined) | No default | |
| Attribute | Description |
|---|---|
data-open | Present when the collapsible panel is open. |
data-closed | Present when the collapsible panel is closed. |
data-starting-style | Present when the panel begins animating in. |
data-ending-style | Present when the panel is animating out. |
| Variable | Description |
|---|---|
--collapsible-panel-height | Values: The collapsible panel's height. |
--collapsible-panel-width | Values: The collapsible panel's width. |
FileTreeFolderTrigger
A button that opens and closes the collapsible panel. Renders a <button> element.
| Prop | Type | Default | Details |
|---|---|---|---|
level | number | No default | |
className | string | ((state: CollapsibleTriggerState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, CollapsibleTriggerState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: CollapsibleTriggerState) => React.CSSProperties | undefined) | No default | |
nativeButton | boolean | true | |
| Attribute | Description |
|---|---|
data-panel-open | Present when the collapsible panel is open. |
FileTreeGuide
| Prop | Type | Default | Details |
|---|---|---|---|
render | ComponentRenderFn<HTMLProps, {}> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
FileTreeIcon
| Prop | Type | Default | Details |
|---|---|---|---|
type | 'archive' | 'code' | 'database' | 'file' | 'folder' | 'image' | 'json' | 'markdown' | 'pdf' | 'table' | 'text' | 'file' | |
children | React.ReactNode | No default | |
render | ComponentRenderFn<HTMLProps, {}> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
FileTreeLabel
| Prop | Type | Default | Details |
|---|---|---|---|
render | ComponentRenderFn<HTMLProps, {}> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
FileTreeList
| Prop | Type | Default | Details |
|---|---|---|---|
render | ComponentRenderFn<HTMLProps, {}> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
FileTreeMeta
| Prop | Type | Default | Details |
|---|---|---|---|
render | ComponentRenderFn<HTMLProps, {}> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |