Skip to content
nexubDesign System
v11.9.0

Components · Form Controls

File Upload

StableAdded v0.0.1 · updated v11.1.0

A drop zone and file list: pick, drop or paste files, with type, size and count checks and per-file progress.

import { FileUpload } from '@nexub/react';
View as Markdown

Playground

Props

TSX
<FileUpload.Root accept={['image/*', '.pdf']} className="w-full max-w-120" maxFiles={3}>…</FileUpload.Root>

Examples

Default

Custom prompt and limits

Trigger, camera and busy

No drop zone: a button, a paperclip, the phone camera, and a busy compact zone.

States

  • default
  • disabled
  • invalid
  • readOnly

Props

Props
PropTypeDefaultDescription
acceptstring[]—MIME types or extensions, e.g. ['image/*', '.pdf']. Other files are rejected with a message.
maxFilesnumber—Most files kept; extras are rejected.
maxSizenumber—Largest file in bytes.
onFilesChange((files: File[]) => void)—The accepted files after every add or remove. Your app does the upload.
onReject((rejections: FileRejection[]) => void)—Files turned away, with the reason (type, size, count or custom).
validate((file: File) => string)—Your own check: return a message to reject the file. Validate again on the server.
filesFile[]—Controlled list: clear or set it from the page (files={[]} after a send) instead of remounting.
defaultFilesFile[]—Controlled list: clear or set it from the page (files={[]} after a send) instead of remounting.
transform((file: File) => File | Promise<File>)—Runs after the type check and before maxSize and validate, e.g. to shrink a photo.
capturefalse | true | 'user' | 'environment'—Opens the phone camera instead of the file list.
disabledboolean—Nothing can be added; busy shows an upload in progress (with progress, a bar).
busyboolean—Nothing can be added; busy shows an upload in progress (with progress, a bar).
progressnumber—Nothing can be added; busy shows an upload in progress (with progress, a bar).
FileUpload.Triggercompound—An outlined button (or iconOnly paperclip) that opens the picker, with no drop zone: Import CSV, attach, take a photo. asChild takes your own Button for another look. Rejections show under it.
FileUpload.Dropzonecompound—A <label> around the native file input: click, Enter, Space, drop or paste. Children replace the default prompt. Rejection messages are announced.
Dropzone size'sm' | 'md'—'sm' is a compact one-line zone.
FileUpload.Listcompound—Renders nothing until there are files.
FileUploadItem indexrequirednumber—Which accepted file this row shows. Rows past the file count render nothing.
FileUploadItem progress / onCancelnumber / () => void—Upload progress 0–100; below 100 shows a bar and, with onCancel, a cancel button.
FileUploadItem errorstring—Why this file failed; shown under its name.
invalidboolean—Error border on the drop zone and aria-invalid on its file input.
readOnlyboolean—Files stay listed; nothing can be picked, dropped, pasted or removed.

Accessibility

Keyboard

  • Enter / Space

    Opens the file picker from the focused drop zone.

Screen reader

  • Rejected files are listed in a live region (`role="alert"`) tied to the input with `aria-describedby`.