Installation
Usage
"use client"
import { FileManager, type FileItem } from "@/components/file-manager"
const files: FileItem[] = [
{ id: "docs", name: "Documents", kind: "folder", parentId: null, modified: "2026-11-10T09:00:00Z" },
{ id: "plan", name: "Plan.pdf", parentId: "docs", size: 240000, modified: "2026-11-10T09:00:00Z" },
{ id: "harbour", name: "Harbour.jpg", parentId: null, size: 3100000, modified: "2026-11-11T18:30:00Z" },
]
export function Files() {
return (
<FileManager
className="h-[36rem]"
defaultItems={files}
onItemsChange={(_items, change) => {
// Every move, rename, upload and delete arrives here; send it to your storage.
void fetch("/api/files", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(change) })
}}
onUpload={async (file, { parentId, signal }) => {
const body = new FormData()
body.append("file", file)
body.append("parentId", parentId ?? "")
const response = await fetch("/api/upload", { method: "POST", body, signal })
return response.json()
}}
/>
)
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
| items / defaultItems | FileItem[] | [] | Files and folders: { id, name, parentId?, kind?, size?, modified?, owner?, thumbnail?, starred?, shared?, trashed? }. parentId is the folder an item sits in; leave it out at the top level. Kept by you or by the component. |
| onItemsChange | (items, change) => void | — | The new list and what happened: create, upload, rename, move, duplicate, star, trash, restore or delete. |
| onUpload | (file, { parentId, signal, onProgress }) => Promise<Partial<FileItem> | void> | — | Uploads a file to your storage and returns its details. Turns on Upload and dropping files in. |
| onOpen | (item) => void | — | Opens a file on Enter or double-click. Without it, files open in Quick Look. |
| onDownload | (items) => void | — | Shows Download in the menus and the selection bar. |
| folder / defaultFolder | string | null | null | The open folder; null is the top level. |
| onFolderChange | (folder) => void | — | Called when another folder opens. |
| view / defaultView | "grid" | "list" | "grid" | Tiles, or rows sortable by name, date and size. |
| rootLabel | string | "My files" | Name of the top level. |
| title | ReactNode | — | Shown at the top of the sidebar. |
| sidebar / details / filters | boolean | true | The locations sidebar, the details panel (when wide enough) and the type chips. |
| storage | { used: number; total: number } | — | A storage meter in the sidebar, in bytes. |
| label | string | "Files" | Accessible name of the file manager. |
Accessibility
- The files are an ARIA listbox with multiple selection: arrow keys move (up and down by row in the grid), Shift extends, Ctrl or Cmd A selects all, Home and End jump, and typing a name's first letters finds it.
- Enter opens, F2 renames, Space shows Quick Look, Delete moves to the Trash, Ctrl or Cmd X then V moves, Alt + Up goes to the parent folder, and Shift F10 or the Menu key opens the actions menu.
- Dragging is never required: "Move to…" lists every folder, and on touch, press and hold opens the menu.
- Every change is announced in a polite status message, with Undo for moves, renames and the Trash; deleting from the Trash asks first.
- Quick Look is a modal dialog that keeps focus and returns it to the file; uploads report progress as progress bars and can be cancelled.
- Under prefers-reduced-motion the selection bar and messages appear without sliding.
Changelog
- v1.0.0Latest
First release.
