Drag-and-Drop File Upload for React
A glass drag-and-drop file upload for React that validates files on drop and lists each one with a thumbnail, progress bar, cancel and retry.
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/file-upload.jsonFileUploadtoFileUploadItemsdefaultFileUploadLabels- +1 more
Using it in a form? See the react-hook-form and zod recipe.
Upload with progress
Drop files, click the zone (or press Enter / Space on it), or paste. Images and PDFs up to 5 MB, six at most. A file with “error” in its name fails halfway so you can try Retry. No files handy? Add the samples: two are rejected on purpose.
import { useState } from "react";
import { FileUpload } from "@/components/sheenui/file-upload/file-upload";
import { type FileUploadHandler, type FileUploadItem } from "@/components/sheenui/file-upload/parts/model";
// Package build (after the first npm release, or a packed tarball): import { FileUpload, type FileUploadHandler, type FileUploadItem } from "@sheenui/theme";
// Your uploader: report progress, honor the abort signal, throw to fail.
async function uploadWithProgress(
url: string,
file: File,
{ onProgress, signal }: { onProgress: (percent: number) => void; signal: AbortSignal },
) {
// XMLHttpRequest (or fetch + a stream) goes here; call onProgress(0..100) as bytes leave.
onProgress(100);
await fetch(url, { method: "POST", body: file, signal });
}
export function Example() {
const [files, setFiles] = useState<FileUploadItem[]>([]);
const uploaded = files.filter((item) => item.status === "done").length;
const upload: FileUploadHandler = async (file, { onProgress, signal }) => {
await uploadWithProgress("/api/files", file, { onProgress, signal });
};
return (
<>
<FileUpload
label="Attachments"
accept="image/*,.pdf"
maxSize={5 * 1024 * 1024}
maxFiles={6}
upload={upload}
onValueChange={setFiles}
/>
<p>{uploaded} uploaded</p>
</>
);
}Files to copy
6 folders · 8 files · 4 packages
- From
theme/src/ components/file-upload/components/status-icons/hooks/{use-controllable.ts, use-latest.ts, use-media-query.ts, use-preferences.ts}motion/tokens.tslib/{cn.ts, form.ts, warn-once.ts}styles/
- shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/file-upload.jsonRegistry item: file-upload. The styles need the Tailwind v4 glass UI setup.- The examples also use
components/button/components/spinner/hooks/use-magnetic.tsmotion/gate.tslib/state-light.tsx
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/button.json- Packages
pnpm add @base-ui/react clsx motion tailwind-merge
Compact, one file
variant="compact" fits dense forms. With maxFiles={1} a new file replaces the old one; capture opens the camera on phones.
import { FileUpload } from "@/components/sheenui/file-upload/file-upload";
import { type FileUploadHandler } from "@/components/sheenui/file-upload/parts/model";
// Package build (after the first npm release, or a packed tarball): import { FileUpload, type FileUploadHandler } from "@sheenui/theme";
export function Example() {
const upload: FileUploadHandler = async (file, { onProgress }) => {
onProgress(100); // send the file to your server here
};
return (
<FileUpload
variant="compact"
label="Profile photo"
accept="image/png,image/jpeg,image/webp"
maxFiles={1}
maxSize={2 * 1024 * 1024}
capture="user"
upload={upload}
/>
);
}In a form, no upload step
Without upload, files are only collected. With name they submit as multipart form data like a native file input.
import { Button } from "@/components/sheenui/button/button";
import { FileUpload } from "@/components/sheenui/file-upload/file-upload";
// Package build (after the first npm release, or a packed tarball): import { Button, FileUpload } from "@sheenui/theme";
// This example also uses button: npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/button.json
export function Example() {
return (
<form onSubmit={(e) => {
e.preventDefault();
const files = new FormData(e.currentTarget)
.getAll("documents")
.filter((f): f is File => f instanceof File && f.size > 0);
console.log(files.map((f) => f.name).join(", ") || "No files yet");
}}>
<FileUpload name="documents" label="Documents" accept=".pdf,.doc,.docx" maxFiles={3} />
<Button type="submit">Send</Button>
</form>
);
}Props
FileUploadLabels keys and English defaults (29)
Keyboard
Accessibility
- Dragging is never required: the zone is a real button, and pasting works too.
- Each file row has a progress bar with a name; added, failed and removed files are announced politely.
- Rejected files (type, size, count) show a message linked to the zone. Every string is translatable through labels.
- The zone is named by the label, the prompt and the limits hint together (“Attachments Drop files here, or browse Images, up to 5 MB”), so the visible text is part of its name.
All exports on this page
FileUpload— File upload: a glass dropzone plus a live file list.defaultFileUploadLabels— Default English strings of FileUploadLabels; spread it and override single keys to reword.toFileUploadItems— Wrap Files as idle items, e.g.
When to use the file upload field
- Use it as a React dropzone for an attachments area on a support ticket or a CSV import screen, where people drop files, click to browse or paste from the clipboard and see a live list with per-file status.
- Use it for uploads with real progress: pass an upload function and each file gets its own progress bar, a cancel button that aborts the signal, a retry button after failure and a done tick.
- Use it for image uploads such as a gallery or avatar picker, where previews gives image files thumbnails and everything else gets a tinted icon with its extension.
- Skip it when you only need a single bare file picker inside a native form; an Input with type="file" is lighter and needs no dropzone, list or upload handling.
- Pair it with its own label, description and error props for labeling, Progress or Toast for wider upload feedback, and Button next to it to open the file dialog or clear the list through actionsRef.
Frequently asked questions
Related pages
67 components pages in all: browse them on All components.
By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .