Collapsible File Tree
A recursive, data-driven tree of folders and files with expand/collapse toggles.
3 个框架初级
A file tree with a live filter that keeps ancestors, auto-expands and highlights matches.
<!-- Static, fully-expanded snapshot. The React/TypeScript tabs add the live
filter: a matching file drags its ancestor folders into view, the tree
auto-expands while a query is active, and the match is <mark>ed. -->
<nav class="w-full max-w-sm rounded-xl border border-gray-200 bg-white p-2 text-sm text-gray-700 dark:border-gray-800 dark:bg-gray-950 dark:text-gray-300">
<div class="relative mb-2">
<svg viewBox="0 0 16 16" fill="currentColor" class="pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400" aria-hidden="true"><path d="M7 2a5 5 0 0 1 3.9 8.1l3 3-1 1-3-3A5 5 0 1 1 7 2zm0 1.5a3.5 3.5 0 1 0 0 7 3.5 3.5 0 0 0 0-7z"/></svg>
<input type="search" placeholder="Filter files…" aria-label="Search files" class="w-full rounded-md border border-gray-200 bg-gray-50 py-1.5 pl-8 pr-2 text-sm text-gray-900 placeholder:text-gray-400 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 dark:border-gray-800 dark:bg-gray-900 dark:text-gray-100" />
</div>
<ul role="tree" aria-label="Files" class="space-y-0.5">
<li role="treeitem" aria-expanded="true">
<button type="button" class="flex w-full min-w-0 items-center gap-1.5 rounded-md px-2 py-1.5 text-left hover:bg-gray-100 dark:hover:bg-gray-900">
<svg viewBox="0 0 16 16" fill="currentColor" class="h-3.5 w-3.5 shrink-0 rotate-90 text-gray-400" aria-hidden="true"><path d="M6 4l4 4-4 4z"/></svg>
<svg viewBox="0 0 16 16" fill="currentColor" class="h-4 w-4 shrink-0 text-blue-500" aria-hidden="true"><path d="M1.5 4A1.5 1.5 0 0 1 3 2.5h3L7.5 4H13A1.5 1.5 0 0 1 14.5 5.5v6A1.5 1.5 0 0 1 13 13H3a1.5 1.5 0 0 1-1.5-1.5z"/></svg>
<span class="truncate font-medium text-gray-900 dark:text-gray-100">components</span>
</button>
<ul role="group" class="ml-3 space-y-0.5 border-l border-gray-200 pl-2 sm:ml-4 dark:border-gray-800">
<li role="treeitem"><span class="flex min-w-0 items-center gap-1.5 rounded-md px-2 py-1.5 hover:bg-gray-100 dark:hover:bg-gray-900"><span class="w-3.5 shrink-0"></span><svg viewBox="0 0 16 16" fill="currentColor" class="h-4 w-4 shrink-0 text-gray-400" aria-hidden="true"><path d="M4 1.5h4.6L13 5.9V14a.5.5 0 0 1-.5.5h-8A.5.5 0 0 1 4 14V2a.5.5 0 0 1 .5-.5z"/></svg><span class="truncate">button.tsx</span></span></li>
</ul>
</li>
</ul>
</nav>| Prop | 类型 | 默认值 | 说明 |
|---|---|---|---|
nodes必填 | TreeNode[] | - | Nodes |
label | string | 'Search files' | 加载时朗读的无障碍标签。 |
Typing filters the tree recursively: a matching file drags its parent folders into view, the whole tree force-expands while a query is active, and the matched substring is wrapped in `<mark>`. An empty result shows a friendly message instead of a blank panel.