# File Tree

Nested folders and files with disclosure carets and indented children.

File Tree presents a small explorer hierarchy. A folder discloses its children. A file is a label in that hierarchy.

```tsx
import { FileTree, Stack, Text } from "@zentara-co/zenos-ui";

function FileTreeExample() {
  return (
    <Stack gap="1" className="w-full max-w-sm">
      <Text className="font-medium text-text-subtle">Explorer</Text>
      <FileTree.Root>
        <FileTree.Folder label="components" defaultOpen>
          <FileTree.File label="button.tsx" />
          <FileTree.File label="card.tsx" />
        </FileTree.Folder>
        <FileTree.Folder label="lib">
          <FileTree.File label="utils.ts" />
        </FileTree.Folder>
        <FileTree.File label="package.json" />
      </FileTree.Root>
    </Stack>
  );
}
```

## Import

```tsx
import { FileTree } from "@zentara-co/zenos-ui";
```

## Composition

```tsx
<FileTree.Root>
  <FileTree.Folder label="src" defaultOpen>
    <FileTree.File label="index.ts" />
    <FileTree.Folder label="lib">
      <FileTree.File label="utils.ts" />
    </FileTree.Folder>
  </FileTree.Folder>
  <FileTree.File label="package.json" />
</FileTree.Root>
```

```text
FileTree.Root
├── FileTree.Folder
│   ├── FileTree.File
│   └── FileTree.Folder
└── FileTree.File
```

Folders may be empty. Nesting is the children of `FileTree.Folder`, so a closed folder hides every row inside it.

## Icons

Each row includes a folder or file glyph. Pass `icon` to replace that glyph with your own, or `icon={null}` to remove it. The disclosure caret stays on the folder trigger.

## Open state

`defaultOpen` sets the initial uncontrolled state. Use `open` and `onOpenChange` when another part of the interface must read or drive a folder. `disabled` keeps the folder visible and prevents it from opening.

## Anatomy

```text
FileTree.Root
FileTree.Folder
FileTree.File
```

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| Folder.label | ReactNode | — | Folder name and trigger label. |
| Folder.icon | ReactNode \| null | — | Replaces the folder glyph. null removes it. |
| Folder.defaultOpen | boolean | false | Initial uncontrolled open state. |
| Folder.open | boolean | — | Controlled open state. |
| Folder.onOpenChange | (open: boolean, eventDetails) => void | — | Runs when the folder opens or closes. |
| Folder.disabled | boolean | false | Keeps the folder closed and prevents activation. |
| File.label | ReactNode | — | Visible file name. |
| File.icon | ReactNode \| null | — | Replaces the file glyph. null removes it. |
| native props | React.HTMLAttributes<HTMLElement> | — | Forwards native attributes, events, aria-*, data-*, className, style, and ref. |

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

## Accessibility

A folder trigger is a button and exposes `aria-expanded`. Enter and Space toggle it. File rows are text, not controls, so they are not in the tab order. Decorative glyphs are hidden from assistive technology. Motion-reduction preferences disable the caret rotation and the height transition.

Use [Collapsible](/components/collapsible/) when the region is a single disclosure rather than a file hierarchy.

Source: https://zenos-ui.pages.dev/components/file-tree/