2.10.0
中文
Skip to content

Folder ​

A file tree for hierarchical file structures. Aligned with React @ant-design/x Folder (2.4+, including the 2.8 context menu).

中文:Folder 文件夹

When to use ​

  • Show file / folder hierarchies
  • Need selection, expand/collapse, preview, and a context menu
  • Need to drag-resize the tree and preview panes

Examples ​

Basic ​

Project Files
src
App.vue
main.ts
package.json
App.vue
<script setup lang="ts">
const msg = 'Hello Folder';
</script>

<template>
  <div>{{ msg }}</div>
</template>
Basic

File tree with inline content preview. Drag the divider between the tree and preview to resize.

Custom file service ​

remote
a.ts
b.ts
Custom file service

Load file content dynamically with fileContentService.

Controlled file selection ​

docs
guide.md
api.md
guide.md
# Guide
Controlled selection.
Controlled file selection

Control selection with selectedFile / onSelectedFileChange.

Custom icons ​

📁pages
index.html
readme.md
readme.md
# Pages
Custom icons

Customize directory and extension icons with directoryIcons. Set false to hide icons.

Context menu ​

Right-click any file or folder
my-project
src
App.vue
README.md
App.vue
<template><div>Hello</div></template>
Context menu

Global contextMenu with per-node overrides (including false to disable). Use ref methods updateNode / deleteNode / addNode for immutable updates.

Custom preview ​

notes.txt
notes.txt
custom preview · lang=txt
line1
line2
line3
Custom preview

Customize the preview pane with previewRender.

API ​

FolderProps ​

PropDescriptionTypeDefaultVersion
treeDataTree dataFolderTreeData[][]-
selectableEnable selectionbooleantrue-
selectedFileSelected file path (controlled)string[]--
defaultSelectedFileDefault selected file pathstring[][]-
onSelectedFileChangeSelection change(file: { path: string[]; title?: FolderTreeData['title']; content?: string }) => void--
directoryTreeWithInitial directory tree width (drag the divider to resize)number | string278-
emptyRenderEmpty state; false hides itfalse | VNode | string | (() => VNode | string | null)--
previewRenderCustom previewVNode | string | ((file, info) => VNode | string | null)--
expandedPathsExpanded paths (controlled)string[]--
defaultExpandedPathsDefault expanded pathsstring[]--
defaultExpandAllExpand all by defaultbooleantrue-
onExpandedPathsChangeExpand/collapse change(paths: string[]) => void--
fileContentServiceFile content loaderFileContentService--
onFileClickFile click(filePath: string, content?: string) => void--
onFolderClickFolder click(folderPath: string) => void--
directoryTitleTree title; false hides itfalse | VNode | string | (() => VNode | string | null)--
previewTitlePreview titlefalse | VNode | string | (({ title, path, content }) => VNode | string | null)--
directoryIconsCustom icons; false hides themfalse | Record<'directory' | string, VNode | string | (() => ...)>--
contextMenuGlobal context menu, overridable per nodeMenuProps['items'] | ((node, key) => MenuProps['items'])--
onRightClickRight-click callback(info: { event, node }) => void--
classNamesSemantic class namesRecord<SemanticType, string>--
stylesSemantic stylesRecord<SemanticType, CSSProperties>--

SemanticType: root | directoryTree | directoryTitle | filePreview | previewTitle | previewRender

FolderTreeData ​

PropDescriptionTypeDefault
titleDisplay namestring | VNode-
pathPath segmentstring-
contentOptional file contentstring-
childrenChildrenFolderTreeData[]-
contextMenuNode menu; false disables itMenuProps['items'] | false | ((key) => ...)-

FileContentService ​

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

Ref methods ​

ts
const folderRef = ref<FolderRef>();

folderRef.value?.getNode(['src', 'App.tsx']);
folderRef.value?.updateNode(['src', 'App.tsx'], { title: 'Main.tsx', path: 'Main.tsx' });
folderRef.value?.deleteNode(['src', 'unused.ts']);
folderRef.value?.addNode(['src'], { title: 'new.ts', path: 'new.ts', content: '' });
MethodDescriptionType
getNodeGet a node by path(path: string[]) => FolderTreeData | undefined
updateNodeImmutable update; returns new treeData(path, data) => FolderTreeData[]
deleteNodeImmutable delete; returns new treeData(path) => FolderTreeData[]
addNodeImmutable add; returns new treeData(parentPath, node) => FolderTreeData[]

Semantic structure ​

:::semantic

folder

:::