Files
Ethan Palm 6c53a28e3a Document className and Tailwind arbitrary value support (#7301)
* Document className and Tailwind arbitrary value support

All built-in components now accept a className prop (mint#10540), and
dynamic Tailwind utilities work in className on MDX components
(mint#6737). Two pages stated the opposite.

- Correct the claims that Tailwind arbitrary values are unsupported in
  customize/custom-scripts and guides/custom-layouts
- Add className and arbitrary value guidance to the Tailwind section of
  custom-scripts, including the runtime-class limitation and the Tab
  content-panel caveat
- Add a Style components section to the components overview
- Add className property rows to every component reference page that
  supports it, and note the three components that do not
- Document inline Markdown support in component title props
- Correct the callouts page, which said typed callouts accept only
  children
- Replace inline style resizing with Tailwind classes in image embeds
- Add a help center article for Tailwind classes not applying in the
  editor's live preview, and note the limitation in custom-layouts
- Point skill.md at className before custom.css
- Accept className, keyframes, and unstyled in the Vale vocabulary

Resolves DOC-316, DOC-317

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Apply batched suggestions from code review

Co-authored-by: Ethan Palm <56270045+ethanpalm@users.noreply.github.com>

* Apply batched suggestions from code review

Co-authored-by: Ethan Palm <56270045+ethanpalm@users.noreply.github.com>

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-08 16:54:20 -07:00

208 lines
6.3 KiB
Plaintext

---
title: "Tree"
description: "Use the tree component to display hierarchical file and folder structures with collapsible nodes and syntax highlighting for path names."
keywords: ["tree", "file tree", "folder structure", "hierarchical navigation", "file system"]
boost: 3
---
Use tree components to display hierarchical structures like file systems, project directories, or nested content. The tree component supports keyboard navigation and accessibility features.
Create trees with either a Markdown list or the `Tree.Folder` and `Tree.File` components. `<Tree>` and `<FileTree>` are aliases, so either tag works with either syntax.
Use the Markdown list syntax for quick, static trees where every folder can expand by default. Use the component syntax when you need to control open state per folder with `defaultOpen`, mark folders as non-interactive with `openable`, or mix files and folders at arbitrary depth.
## Markdown list syntax
Write a nested Markdown list inside `<FileTree>` (or `<Tree>`) to describe a folder structure. Add a trailing slash to mark a folder, or nest items under it. Folders that contain nested items expand by default.
<FileTree>
- docs/
- index.mdx
- guides/
- configuration.mdx
- docs.config.ts
</FileTree>
````mdx File tree example
<FileTree>
- docs/
- index.mdx
- guides/
- configuration.mdx
- docs.config.ts
</FileTree>
````
Leave a blank line after the opening tag and before the closing tag so that the list parses as Markdown. Names strip inline formatting like `` `code` ``, `**bold**`, or `_italic_`.
## Basic tree
<Tree>
<Tree.Folder name="app" defaultOpen>
<Tree.File name="layout.tsx" />
<Tree.File name="page.tsx" />
<Tree.File name="global.css" />
</Tree.Folder>
<Tree.Folder name="lib">
<Tree.File name="utils.ts" />
<Tree.File name="db.ts" />
</Tree.Folder>
<Tree.File name="package.json" />
<Tree.File name="tsconfig.json" />
</Tree>
```mdx Tree example
<Tree>
<Tree.Folder name="app" defaultOpen>
<Tree.File name="layout.tsx" />
<Tree.File name="page.tsx" />
<Tree.File name="global.css" />
</Tree.Folder>
<Tree.Folder name="lib">
<Tree.File name="utils.ts" />
<Tree.File name="db.ts" />
</Tree.Folder>
<Tree.File name="package.json" />
<Tree.File name="tsconfig.json" />
</Tree>
```
## Nested folders
Create deeply nested structures by nesting `Tree.Folder` components within each other.
<Tree>
<Tree.Folder name="app" defaultOpen>
<Tree.File name="layout.tsx" />
<Tree.File name="page.tsx" />
<Tree.Folder name="api" defaultOpen>
<Tree.Folder name="auth">
<Tree.File name="route.ts" />
</Tree.Folder>
<Tree.File name="route.ts" />
</Tree.Folder>
<Tree.Folder name="components">
<Tree.File name="button.tsx" />
<Tree.File name="dialog.tsx" />
<Tree.File name="tabs.tsx" />
</Tree.Folder>
</Tree.Folder>
<Tree.File name="package.json" />
</Tree>
```mdx Nested folders example
<Tree>
<Tree.Folder name="app" defaultOpen>
<Tree.File name="layout.tsx" />
<Tree.File name="page.tsx" />
<Tree.Folder name="api" defaultOpen>
<Tree.Folder name="auth">
<Tree.File name="route.ts" />
</Tree.Folder>
<Tree.File name="route.ts" />
</Tree.Folder>
<Tree.Folder name="components">
<Tree.File name="button.tsx" />
<Tree.File name="dialog.tsx" />
<Tree.File name="tabs.tsx" />
</Tree.Folder>
</Tree.Folder>
<Tree.File name="package.json" />
</Tree>
```
## Highlight the active path
Add the `highlight` property to `Tree.File` or `Tree.Folder` to mark the current item. Use it to draw attention to a file or folder you reference in nearby prose, such as the file a reader should open next.
Highlighting a folder also tints its descendants, so the active path stands out.
<Tree>
<Tree.Folder name="app" defaultOpen>
<Tree.File name="layout.tsx" />
<Tree.File name="page.tsx" highlight />
<Tree.Folder name="api" defaultOpen highlight>
<Tree.File name="route.ts" />
</Tree.Folder>
</Tree.Folder>
<Tree.File name="package.json" />
</Tree>
```mdx Highlighted tree example
<Tree>
<Tree.Folder name="app" defaultOpen>
<Tree.File name="layout.tsx" />
<Tree.File name="page.tsx" highlight />
<Tree.Folder name="api" defaultOpen highlight>
<Tree.File name="route.ts" />
</Tree.Folder>
</Tree.Folder>
<Tree.File name="package.json" />
</Tree>
```
### Customize the highlight color
The `--tree-highlight` CSS variable defines the highlight color. Set it on the `Tree` root component to override the color for that tree.
```mdx Custom highlight color
<Tree style={{ "--tree-highlight": "rgb(59 130 246)" }}>
<Tree.Folder name="app" defaultOpen>
<Tree.File name="page.tsx" highlight />
</Tree.Folder>
</Tree>
```
## Keyboard navigation
The tree component supports keyboard navigation.
- **Arrow keys**: Navigate up and down through visible items.
- **Right arrow**: Expand a closed folder or move to the first child of an open folder.
- **Left arrow**: Collapse an open folder or move to the parent folder.
- **Home**: Jump to the first item in the tree.
- **End**: Jump to the last visible item in the tree.
- **Enter/Space**: Toggle folder open/closed state.
- **\***: Expand all sibling folders at the current level.
- **Type-ahead search**: Type characters to jump to items that start with those characters.
## Properties
### Tree
<ResponseField name="className" type="string">
Additional CSS classes to apply to the tree container.
</ResponseField>
### Tree.Folder
<ResponseField name="name" type="string" required>
The name of the folder displayed in the tree.
</ResponseField>
<ResponseField name="defaultOpen" type="boolean" default="false">
Whether the folder expands by default.
</ResponseField>
<ResponseField name="openable" type="boolean" default="true">
Whether users can open and close the folder. Set to false for non-interactive folders.
</ResponseField>
<ResponseField name="highlight" type="boolean" default="false">
Whether to highlight the folder as the active item. Emphasizes the active path by tinting descendants.
</ResponseField>
### Tree.File
<ResponseField name="name" type="string" required>
The name of the file displayed in the tree.
</ResponseField>
<ResponseField name="highlight" type="boolean" default="false">
Whether to highlight the file as the active item.
</ResponseField>