logoAnt Design X

DesignDevelopmentComponentsX MarkdownX SDKX SkillPlayground
  • Introduction
  • Overview
  • Common
    • Bubble
    • Conversations
    • Notification
      2.0.0
  • Confirmation
    • Think
      2.0.0
    • ThoughtChain
      2.0.0
  • Wake
    • Welcome
    • Prompts
  • Express
    • Attachments
    • Sender
    • Suggestion
  • Feedback
    • Actions
    • CodeHighlighter
      2.1.0
    • FileCard
      2.0.0
    • FolderFile Tree
      2.4.0
    • Mermaid
      2.1.0
    • Sources
      2.0.0
  • Others
    • XProvider

Folder
File Tree

File tree component for displaying hierarchical file structure.
Importimport { Folder } from "@ant-design/x";
Sourcex/components/folder
Docs
Edit this page...
Versionsupported since 2.4.0
Changelog
loading

When to use

  • Display hierarchical file/folder structure
  • File selection and expand/collapse features needed

Code examples

API

Common props ref: Common props

FolderProps

PropertyDescriptionTypeDefaultVersion
treeDataFile tree dataFolderTreeData[][]-
selectableWhether to enable selection functionalitybooleantrue-
selectedFileSelected file paths (controlled)string[]--
defaultSelectedFileDefault selected file pathsstring[][]-
onSelectedFileChangeCallback when file selection changes(file: { path: string[]; name?: string; content?: string }) => void--
directoryTreeWithDirectory tree widthnumber | string278-
emptyRenderContent to display when emptyReact.ReactNode | (() => React.ReactNode)--
previewRenderCustom file preview contentReact.ReactNode | ((file: { content?: string; path: string[]; title?: React.ReactNode; language: string }, info: { originNode: React.ReactNode }) => React.ReactNode)--
expandedPathsArray of expanded node paths (controlled)string[]--
defaultExpandedPathsArray of default expanded node pathsstring[]--
defaultExpandAllWhether to expand all nodes by defaultbooleantrue-
onExpandedPathsChangeCallback when expand/collapse changes(paths: string[]) => void--
fileContentServiceFile content serviceFileContentService--
onFileClickFile click event(filePath: string, content?: string) => void--
onFolderClickFolder click event(folderPath: string) => void--
directoryTitleDirectory tree titleReact.ReactNode | (() => React.ReactNode)--
previewTitleFile preview titlestring | (({ title, path, content }: { title: string; path: string[]; content: string }) => React.ReactNode)--
directoryIconsCustom icon configurationRecord<'directory' | string, React.ReactNode | (() => React.ReactNode)>--

FolderTreeData

PropertyDescriptionTypeDefaultVersion
titleDisplay namestring--
pathFile pathstring--
contentFile content (optional)string--
childrenSub-items (valid only for folder type)FolderTreeData[]--

FileContentService

File content service interface, used for dynamically loading file content.

typescript
interface FileContentService {
loadFileContent(filePath: string): Promise<string>;
}

Semantic DOM

Design Token

Component TokenHow to use?
Token NameDescriptionTypeDefault Value
colorBgDirectoryBackground color of directorystringrgba(0,0,0,0.04)
Global TokenHow to use?
Basic Usage

Basic usage.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Custom File Service

Custom file content service.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Controlled File Selection

Controlled file selection.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Fully Controlled Mode

Fully controlled mode.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Searchable File Tree

Searchable file browser.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Custom Icons

Custom file icons.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
use-x-chat
SKILL.md
reference
API.md
CORE.md
EXAMPLES.md
No data
Please select a file
x-request
SKILL.md
reference
API.md
CORE.md
EXAMPLES_SERVICE_PROVIDER.md
No data
Please select a file
Current Selected File:None
Project File Browser
x-chat-provider
SKILL.md
reference
EXAMPLES.md
No data
Please select a file
Current Selected File: use-x-chat/SKILL.md
Expanded Nodes: use-x-chat
File Browser
use-x-chat
SKILL.md
reference
API.md
CORE.md
EXAMPLES.md
No data
Please select a file
Total Files: 12
Matching Results: 12
Project File Browser
project-root
src
components
Header.tsx
Footer.tsx
Sidebar.tsx
pages
Home.tsx
About.tsx
Contact.tsx
utils
helpers.ts
constants.ts
public
index.html
favicon.ico
package.json
README.md
No data
Please select a file
Custom Icon File Browser
Display different icons based on file type
my-project
docs
README.md
API.pdf
src
components
Button.tsx
styles.css
utils
helpers.ts
assets
logo.png
banner.jpg
data
users.xlsx
report.docx
archive.zip
package.json
No data
Please select a file
项目文件浏览器
src
components
Button.tsx
Input.tsx
utils
helper.ts
package.json
No data
Please select a file
  • root
    Root
  • directoryTree
    Directory tree container
  • directoryTitle
    Directory tree title
  • filePreview
    File preview container
  • previewTitle
    Preview title
  • previewRender
    Preview content