Skip to content

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.json
AttachmentsPDF or images, up to 5 MB.
Drop files here, or browse Images or PDF · up to 5 MB · 4 files max
  • FileUpload
  • toFileUploadItems
  • defaultFileUploadLabels
  • +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.

Attachments
Drop files here, or browse Images or PDF · up to 5 MB · 6 files max

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.ts
  • lib/{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.ts
  • motion/gate.ts
  • lib/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.

Profile photo
Drop files here, or browse PNG, JPEG, or WEBP · up to 2 MB

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.

Documents
Drop files here, or browse PDF, DOC, or DOCX · 3 files max

Props

PropTypeDefaultDescription
aria-describedbystringNoneIds of elements that describe the field, merged with the control's own description and error ids.
aria-invalidboolean | "true" | "false"NoneMarks the field as invalid (also set automatically when error is shown).
onBlurFocusEventHandler<HTMLElement>NoneCalled when focus leaves the control (not when it moves between the control's own parts).
namestringNoneSubmits the files with a form (multipart).
disabledbooleanfalseDisables the drop zone and its browse button.
valueFileUploadItem[]NoneThe file list (controlled). Use toFileUploadItems(files) to wrap existing Files.
defaultValueFileUploadItem[][]Sets the starting list when uncontrolled.
onValueChange((items: FileUploadItem[]) => void)NoneCalled with the new list whenever files are added, removed or their upload state changes.
uploadFileUploadHandlerNoneUploads one file. Report progress (0–100) and stop when the signal aborts. Throw to fail.
onFilesAccepted((files: File[]) => void)NoneCalled with the files that passed validation.
onFilesRejected((rejections: FileRejection[]) => void)NoneCalled with the files that didn't, and why.
acceptstringNoneLike the input's accept: "image/*,.pdf".
maxSizenumberNoneSets the largest file size accepted, in bytes.
minSizenumberNoneSets the smallest file size accepted, in bytes.
maxFilesnumber0Most files at once. With 1 (or multiple={false}), a new file replaces the old one.
multiplebooleantrueAllows adding several files at once.
capture"user" | "environment"NonePhones: open the camera directly.
previewsbooleantrueShows a thumbnail for each image file.
variant"default" | "compact""default""default": tall zone with an icon. "compact": one row, for dense forms.
labelReactNodeNoneText above the zone; part of the zone's accessible name.
descriptionReactNodeNoneMuted helper text under the label.
errorReactNodeNoneError message from outside (e.g. "Add at least one file").
localestringNoneLocale for sizes and lists.
actionsRefRefObject<FileUploadActions | null>NoneReceives an object of imperative actions, { addFiles, browse, clear }.
preventDropOnDocumentbooleantrueStop a file dropped just outside the zone from opening in the browser tab.
labelsPartial<FileUploadLabels>defaultFileUploadLabelsEvery other string, for translation: labels={{ title: "…" }}; omitted keys keep the English of defaultFileUploadLabels. All 29 keys of FileUploadLabels are listed in the key table under the props table.
classNamestringNoneAdds extra classes to the outer wrapper.
FileUploadLabels keys and English defaults (29)
Pass any key in labels; the rest keep the defaults of defaultFileUploadLabels.
KeyEnglish default
titleDrop files here, or
browsebrowse
dragActiveDrop to add your files
dragRejectSome of these files can’t be added
hint({ types, maxSize, maxFiles }) => [types, maxSize && `up to ${maxSize}`, maxFiles && maxFiles > 1 && `${max...
imagesImages
videosVideos
audioAudio
listLabelSelected files
summary(count, size) => `${count} ${count === 1 ? "file" : "files"} · ${size}`
removeAllRemove all
remove(name) => `Remove ${name}`
cancel(name) => `Cancel upload of ${name}`
retry(name) => `Retry upload of ${name}`
uploading(percent) => `Uploading… ${percent}%`
doneUploaded
failedUpload failed
progress(name) => `Uploading ${name}`
errorType() => "This file type isn’t accepted."
errorTooLarge(_, max) => `Larger than ${max}.`
errorTooSmall(_, min) => `Smaller than ${min}.`
errorTooMany(_, max) => `Only ${max} ${max === 1 ? "file" : "files"} allowed.`
errorDuplicate() => "Already added."
moreErrors(count) => `and ${count} more`
dismissDismiss
added(count) => `${count} ${count === 1 ? "file" : "files"} added`
removed(name) => `${name} removed`
uploaded(name) => `${name} uploaded`
uploadFailed(name) => `${name} failed to upload`

Keyboard

KeysAction
TabFocus the drop zone (it is a button).
Enter/SpaceOpen the file dialog.
Ctrl/Cmd + VPaste files while the zone is focused.
Tab, then Enter/SpaceCancel, Retry or Remove a file: each row's buttons are normal tab stops.

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

67 components pages in all: browse them on All components.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .