Skip to content
kitn AI/UI

File Tree

kai-file-tree

Pass a flat array of paths and get a collapsible, keyboard-navigable file explorer — folders are derived from the slashes automatically, no tree to build by hand.

  • Shadow DOM
  • ARIA tree / treeitem
  • 1 event
  • Derived folder structure
  • Fills its container

Set files in JavaScript (it’s an array, so it can’t be an attribute):

<kai-file-tree style="display:block;height:320px"></kai-file-tree>
<script type="module">
import '@kitn.ai/ui/elements';
const tree = document.querySelector('kai-file-tree');
tree.files = [
{ path: 'index.html', type: 'html' },
{ path: 'src/app.ts', type: 'other' },
{ path: 'src/lib/format.ts', type: 'other' },
{ path: 'assets/logo.svg', type: 'image' },
];
tree.setAttribute('active-file', 'src/app.ts');
tree.addEventListener('kai-select', (e) => console.log('selected', e.detail.path));
</script>
  • Folders are derived — any / in a path creates intermediate folder nodes; no explicit folder entries needed.
  • active-file — plain attribute; update it in response to kai-select to keep selection in sync.
  • defaultExpanded — assign it in JavaScript (el.defaultExpanded = ['src']). Omit to start all folders open; pass an array to restrict which start expanded.
  • Keyboard — proper ARIA tree: arrow keys move focus, Enter/Space selects or toggles, Home/End jump to first/last row.

A mixed project with HTML, TypeScript, CSS, images, and a PDF. src/app.ts starts highlighted via active-file.

Multiple levels of nesting across src/components, src/hooks, and docs.

A design system asset bundle covering SVG images, PDFs, HTML preview, JSON tokens, and CSS.

Only src starts open — tests, src/routes, and src/middleware start collapsed.

PropertyTypeDefaultNotes
files [] The files to render. Set as a JS property (array of `{ path, url?, code?, language?, type? }`).
activeFile Selected file path — highlighted in the tree.
defaultExpanded Folder paths expanded initially. Omit to start with all folders open.
EventDetailNotes
Fired when a file is selected. `detail.path` = the file's path.

This element wraps these SolidJS components — reach for them directly when you need finer control than the props expose.

FileTree