# File Browser

> A folder's folders and files as a grid or a list: breadcrumbs, search, preview, upload with progress, new folder, rename, move, trash and a selection with the bulk action bar.

Component · Data · Pro kit · [Live page](https://ui.twentyfirst.media/pro/components/FileBrowser/)

A folder's folders and files as a grid or a list: breadcrumbs, search, preview, upload with progress,
new folder, rename, move, trash and a selection with the bulk action bar. Your app keeps the files and
does the uploads; the component shows them and asks.

- `items` are the current folder's contents (`kind: "folder"` or a file kind; without it the kind comes
  from `mime` or the extension). `path` is the breadcrumb trail; `onNavigate(id)` opens a folder or a
  crumb (crumbs with `href` are links, with `linkAs` for your router).
- A file with an image or PDF `preview` URL opens in a drawer; `onOpen(item)` gets every file. The kit
  loads only the URLs you give it.
- `onUpload(files)` adds Upload and accepts dropped files. Pass `uploads` with `progress` (and `part` /
  `parts` for large files uploaded in pieces) to show each file's state; `onCancelUpload` adds a stop button.
- `onCreateFolder`, `onRename` (in place, also F2), `onMove` with a `folders` tree (a picker dialog),
  `onTrash` (after a confirmation) and `onDownload`. Each may return a Promise.
- Keyboard: arrow keys move between items, Enter opens, Space selects, F2 renames, Delete trashes,
  ⌘/Ctrl+A selects all, Escape clears the selection.
- `view`, `selected`, `query` and `preview` work controlled or uncontrolled. Below 560px the toolbar
  wraps, the grid gets two columns and the list shows size and date under the name.

## Example

```tsx
import * as React from "react";
import { FileBrowser } from "@twentyfirstmedia/pro";
import type { FileBrowserItem, FileBrowserUpload } from "@twentyfirstmedia/pro";
import { landscape } from "./_art";

type Node = FileBrowserItem & { parent: string };

const START: Node[] = [
  { id: "contracts", parent: "root", name: "Contracts", kind: "folder", count: 3 },
  { id: "receipts", parent: "root", name: "Receipts", kind: "folder", count: 12, shared: true },
  { id: "brand", parent: "root", name: "Brand assets", kind: "folder", count: 8 },
  {
    id: "msa",
    parent: "root",
    name: "Northwind – master agreement.pdf",
    size: 412000,
    modified: "2026-04-16",
    shared: true,
  },
  {
    id: "offsite",
    parent: "root",
    name: "offsite-lake-house.png",
    size: 2400000,
    modified: "2026-04-15",
    thumbnail: landscape("#bcd3e6", "#f5d48a", "#7d9b76", "#56734f"),
    preview: landscape("#bcd3e6", "#f5d48a", "#7d9b76", "#56734f"),
  },
  { id: "pnl", parent: "root", name: "pnl-q1-2026.xlsx", size: 92000, modified: "2026-04-01" },
  { id: "dpa", parent: "root", name: "DPA template.docx", size: 96000, modified: "2026-03-30" },
  { id: "kit", parent: "root", name: "press-kit.zip", size: 36000000, modified: "2026-04-02" },
  {
    id: "c1",
    parent: "contracts",
    name: "Kestrel Bank – proposal v3.pdf",
    size: 1800000,
    modified: "2026-04-15",
  },
  {
    id: "c2",
    parent: "contracts",
    name: "NDA – Sunline.pdf",
    size: 210000,
    modified: "2026-02-11",
  },
];
const NAMES: Record<string, string> = {
  root: "All files",
  contracts: "Contracts",
  receipts: "Receipts",
  brand: "Brand assets",
};

export default function Preview() {
  const [nodes, setNodes] = React.useState(START);
  const [folder, setFolder] = React.useState("root");
  const [uploads, setUploads] = React.useState<FileBrowserUpload[]>([
    { id: "u1", name: "launch-video.mp4", size: 184000000, progress: 38, part: 7, parts: 18 },
  ]);
  const items = nodes
    .filter((n) => n.parent === folder)
    .map((n) =>
      n.kind === "folder"
        ? { ...n, count: nodes.filter((x) => x.parent === n.id).length || n.count }
        : n,
    );
  return (
    <FileBrowser
      items={items}
      path={[
        { id: "root", name: NAMES.root ?? "" },
        ...(folder === "root" ? [] : [{ id: folder, name: NAMES[folder] ?? folder }]),
      ]}
      onNavigate={setFolder}
      folders={[
        {
          id: "root",
          name: "All files",
          children: [
            { id: "contracts", name: "Contracts" },
            { id: "receipts", name: "Receipts" },
            { id: "brand", name: "Brand assets" },
          ],
        },
      ]}
      uploads={uploads}
      onCancelUpload={(id) => setUploads((u) => u.filter((x) => x.id !== id))}
      onUpload={(files) =>
        setUploads((u) => [
          ...u,
          ...files.map((f, i) => ({
            id: `${f.name}-${i}`,
            name: f.name,
            size: f.size,
            progress: 0,
          })),
        ])
      }
      onCreateFolder={(name) => {
        const id = name.toLowerCase().replace(/\W+/g, "-");
        NAMES[id] = name;
        setNodes((n) => [...n, { id, parent: folder, name, kind: "folder" }]);
      }}
      onRename={(id, name) => setNodes((n) => n.map((x) => (x.id === id ? { ...x, name } : x)))}
      onMove={(ids, to) =>
        setNodes((n) => n.map((x) => (ids.includes(x.id) ? { ...x, parent: to } : x)))
      }
      onTrash={(ids) => setNodes((n) => n.filter((x) => !ids.includes(x.id)))}
      onDownload={() => {}}
    />
  );
}
```

## Props

### FileBrowser

| Prop | Type | Notes |
| --- | --- | --- |
| `surface?` | `Surface` | `"glass"` for a translucent surface over a map, photo or video; `"solid"` opts out inside a glass provider. |
| `items` | `FileBrowserItem[]` | The current folder's folders and files. |
| `path?` | `{ id: string; name: string; href?: string }[]` | Breadcrumbs from the root to the current folder (`href` makes them links). |
| `onNavigate?` | `(folderId: string) => void` | A folder or a breadcrumb was opened. |
| `onOpen?` | `(item: FileBrowserItem) => void` | A file was opened (files with an image or PDF `preview` also open the preview drawer). |
| `previewOnOpen?` | `boolean` | Set `false` to open files only through `onOpen`. |
| `linkAs?` | `ElementType` | Router link for breadcrumbs and "Open" (default `a`, or the provider's `linkAs`). |
| `view?` | `"grid" \| "list"` |  |
| `defaultView?` | `"grid" \| "list"` |  |
| `onViewChange?` | `(view: "grid" \| "list") => void` |  |
| `selected?` | `string[]` |  |
| `defaultSelected?` | `string[]` |  |
| `onSelectedChange?` | `(ids: string[]) => void` |  |
| `query?` | `string` |  |
| `defaultQuery?` | `string` |  |
| `onQueryChange?` | `(query: string) => void` |  |
| `localSearch?` | `boolean` | Filters `items` by name as you type (default); `false` when your server searches. |
| `search?` | `boolean` | `false` hides the search field. |
| `searchPlaceholder?` | `string` |  |
| `preview?` | `string \| null` | The id of the file shown in the preview drawer. |
| `defaultPreview?` | `string \| null` |  |
| `onPreviewChange?` | `(id: string \| null) => void` |  |
| `onUpload?` | `(files: File[]) => void` | Shows Upload and accepts dropped files; upload them yourself and pass `uploads`. |
| `accept?` | `string` | File types for the picker (`accept`). |
| `uploads?` | `FileBrowserUpload[]` |  |
| `onCancelUpload?` | `(id: string) => void` |  |
| `onCreateFolder?` | `(name: string) => void \| Promise<void>` |  |
| `onRename?` | `(id: string, name: string) => void \| Promise<void>` |  |
| `onMove?` | `(ids: string[], folderId: string) => void \| Promise<void>` | With `folders`: Move opens a folder picker. |
| `folders?` | `FileBrowserFolder[]` | The folder tree for the move picker. |
| `onTrash?` | `(ids: string[]) => void \| Promise<void>` |  |
| `onDownload?` | `(ids: string[]) => void` |  |
| `foldersFirst?` | `boolean` | Folders before files (default true). |
| `loading?` | `boolean` |  |
| `emptyText?` | `string` |  |
| `label?` | `string` | Accessible name (default "Files"). |
| `actions?` | `ReactNode` | More controls in the toolbar. |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |

### BulkActionBar

| Prop | Type | Notes |
| --- | --- | --- |
| `count` | `number` | How many items are selected; the bar hides at 0 (unless `keepOpen`). |
| `actions?` | `BulkActionBarAction[]` |  |
| `onClear?` | `() => void` | Shows "Clear" and is called by it. |
| `label?` | `string` | Accessible name of the toolbar (default "Bulk actions"). |
| `keepOpen?` | `boolean` | Stays visible with 0 selected (e.g. while an exit animation runs in your list). |
| `floating?` | `boolean` | Default: the bar floats, sticky at the bottom of its scroll area (as in DataTable). `false` keeps it in the flow, e.g. at the top of a mail list. |
| `children?` | `ReactNode` | More controls after the actions (a menu, a select). |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |

### Breadcrumb

| Prop | Type | Notes |
| --- | --- | --- |
| `items` | `(string \| Crumb)[]` | The trail; the last one is the current page. Items with `href` are links, with `onClick` buttons. |
| `linkAs?` | `ElementType` | The element links render as (default `a`), e.g. Next.js `Link`. |
| `onNavigate?` | `(index: number) => void` | Makes every crumb but the last a button; receives its index. |
| `label?` | `string` | Accessible name of the navigation (default "Breadcrumb"). |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |
