# File Tree Selection Example

> Example implementation of file tree-selection.

A shadcn/ui block from the [@ai-elements](https://ai-sdk.dev/elements) registry, listed on [shadcn.exchange](https://shadcn.exchange/r/ai-elements/example-file-tree-selection).

- Page, with a live preview: https://shadcn.exchange/r/ai-elements/example-file-tree-selection
- Screenshot: https://abzjhwgwpdpz7ua5.public.blob.vercel-storage.com/shots/ai-elements/example-file-tree-selection-light-647536854df11b70.png
- Registry item: https://ai-sdk.dev/elements/api/registry/example-file-tree-selection.json
- Listed: 2026-10-13, source last changed 2026-10-13

## Install

```bash
npx shadcn@latest add https://ai-sdk.dev/elements/api/registry/example-file-tree-selection.json
```

Run it in a project that has shadcn/ui set up. It adds the files below and installs what they depend on.

## Dependencies

- Registry items: `https://elements.ai-sdk.dev/file-tree.json`

## Files

### `registry/default/examples/file-tree-selection.tsx`

```tsx
"use client";

import {
  FileTree,
  FileTreeFile,
  FileTreeFolder,
} from "@/components/ai-elements/file-tree";
import { useState } from "react";

const Example = () => {
  const [selectedPath, setSelectedPath] = useState<string>();

  return (
    <FileTree onSelect={setSelectedPath} selectedPath={selectedPath}>
      <FileTreeFolder name="src" path="src">
        <FileTreeFile name="app.tsx" path="src/app.tsx" />
        <FileTreeFile name="index.ts" path="src/index.ts" />
      </FileTreeFolder>
      <FileTreeFile name="package.json" path="package.json" />
    </FileTree>
  );
};

export default Example;
```
