Xzero UI
Pro library

File dropzone

A generous target for dropping one or more files.

$ pnpm dlx shadcn@4.23.0 add @xzero-ui/file-dropzone
Live · keyboard ready

When to use

When not to use

Installation

Register both Xzero UI namespaces in your project's components.json:

{
  "registries": {
    "@xzero-ui": "https://mcp.xzero.co.uk/r/{name}.json",
    "@xzero-ui-pro": "https://mcp.xzero.co.uk/r/pro/{name}.json"
  }
}
npx shadcn@4.23.0 add @xzero-ui/file-dropzone

Install xzero-foundation once, and import @/components/xzero/foundation.css in your app root. No Xzero token is used by this snapshot. For sample portraits, photos, fonts, or logos, download https://mcp.xzero.co.uk/install-assets.mjs and run node xzero-install-assets.mjs <receiving-project>.

Usage

import { FileDropzone } from "@/components/xzero/file-dropzone/file-dropzone";

export function AttachmentUpload() {
  return (
    <FileDropzone
      accept=".pdf,image/*"
      maxFiles={3}
      maxSize={10 * 1024 * 1024}
      onUpload={async (item, { onProgress, signal }) => {
        await uploadFile(item.file!, { onProgress, signal });
      }}
    />
  );
}

Examples

Folding prompt with a size limit

<FileDropzone
  label="Add receipts"
  accept="image/*,.pdf"
  maxFiles={10}
  maxSize={5 * 1024 * 1024}
  compactAt={2}
  listPlacement="inside"
  onFilesChange={setFiles}
/>

API reference

FileDropzone

A drop target and file picker with a file list that can run uploads with progress, retry, and removal.

PropTypeDefaultDescription
acceptstring–Accepted types, as in the native accept attribute (".pdf", "image/*"). Others are rejected with an error.
multiplebooleantrueAllow several files.
maxFilesnumber5Most files the list holds.
onFilesChange(files: File[]) => void–Called with the selected File objects whenever the list changes.
labelstring"Add files"Main prompt on the drop target.
descriptionstring"Drop files here or choose from your device"Secondary prompt.
defaultItemsFileDropzoneItem[]–Rows present at mount, such as earlier uploads. They render without an entrance.
onUpload(item: FileDropzoneItem, options: { onProgress: (percent: number) => void; signal: AbortSignal }) => Promise<void>–Uploads each added file. Report progress, resolve on success, reject with an Error whose message becomes the row's reason. Removing a row aborts the signal.
maxSizenumber–Bytes. Larger files fail with a size reason and never upload.
listPlacement"below" | "inside""below"Render the list under the target or inside its edge.
notestring–Replaces the small line under the description (defaults to accepted types or the file limit).
dropLabelstring–Label while files hover over the target.
compactAtnumber–Once the list holds this many files, the prompt folds to a slim bar.

FileDropzoneItem

One row in the list, used by defaultItems and onUpload.

PropTypeDefaultDescription
id (required)string–Stable id.
name (required)string–File name; its extension picks the type icon.
size (required)number–Bytes.
statusFileDropzoneStatus–Upload state of the row.
progressnumber–Upload percent.
errorstring–Failure reason shown on the row.
retryableboolean–Shows a retry button when failed.
fileFile–The File, for items the visitor added.
previewstring–Thumbnail URL shown instead of the type icon. Image files added by the visitor get an object URL automatically, revoked when the row is removed or the component unmounts. Falls back to the icon if the image fails.

Keyboard interactions

KeysAction
Enter / SpaceOn the drop target, opens the native file picker.
ArrowUp / ArrowDownIn the file list, moves focus to the same action (remove or retry) on the adjacent row.
Delete / BackspaceIn the file list, removes the focused row.
⌘ + V / Ctrl + VPastes files from the clipboard, such as a screenshot, while the pointer is over the dropzone or focus is inside it. Ignored inside text fields.

Accessibility

Motion

Responsive behavior

Performance

Notes for AI

Also in editors

Guidance for AI tools

File dropzone: A generous target for dropping one or more files. Follow the declared prop types and do not invent props. Keep keyboard access, reduced motion support, and both light and dark themes intact when adapting it.

Full library index: https://ui.xzero.co.uk/llms.txt

Browse all components