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';Playground
Props
<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
defaultdisabledinvalidreadOnly
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| accept | string[] | — | MIME types or extensions, e.g. ['image/*', '.pdf']. Other files are rejected with a message. |
| maxFiles | number | — | Most files kept; extras are rejected. |
| maxSize | number | — | 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. |
| files | File[] | — | Controlled list: clear or set it from the page (files={[]} after a send) instead of remounting. |
| defaultFiles | File[] | — | 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. |
| capture | false | true | 'user' | 'environment' | — | Opens the phone camera instead of the file list. |
| disabled | boolean | — | Nothing can be added; busy shows an upload in progress (with progress, a bar). |
| busy | boolean | — | Nothing can be added; busy shows an upload in progress (with progress, a bar). |
| progress | number | — | Nothing can be added; busy shows an upload in progress (with progress, a bar). |
| FileUpload.Trigger | compound | — | 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.Dropzone | compound | — | 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.List | compound | — | Renders nothing until there are files. |
| FileUploadItem indexrequired | number | — | Which accepted file this row shows. Rows past the file count render nothing. |
| FileUploadItem progress / onCancel | number / () => void | — | Upload progress 0–100; below 100 shows a bar and, with onCancel, a cancel button. |
| FileUploadItem error | string | — | Why this file failed; shown under its name. |
| invalid | boolean | — | Error border on the drop zone and aria-invalid on its file input. |
| readOnly | boolean | — | 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`.
On iOS & Android: FileUpload
@nexub/react-nativeAlpha
import { FileUpload } from '@nexub/react-native';
<FileUpload accept={['image/*']} multiple maxSize={5_000_000} pickFiles={pickImages} capture={takePhoto} transform={resize} />Web vs mobile
Same tokens and prop names. Where the platforms differ:
| Web | iOS & Android | |
|---|---|---|
| Picking | Click or drop files. | Bring your picker: pickFiles (expo-document-picker) and capture (expo-image-picker or expo-camera) for a camera button. |
| Checks | accept, transform, maxSize, validate, maxFiles. | The same checks in the same order; rejected files stay in the list with their error. |
Interactive preview of @nexub/react-native rendered for the web. Native chrome (switches, pickers, Liquid Glass) looks like the platform on a device.
On device

iPhone (iOS simulator)

Pixel (Android emulator)
Screenshots from the latest CI run of the showcase app; the live frame renders the same code for the web.
FileUpload props
| Prop | Type | Default | Description |
|---|---|---|---|
| pickFiles | (options: { multiple: boolean; accept?: readonly string[] }) => Promise<readonly F[] | null | undefined> | — | Opens your file picker and resolves to what was picked ([] or null when cancelled), e.g.
expo-document-picker's getDocumentAsync or expo-image-picker's launchImageLibraryAsync.
Gets multiple and accept so you can pass them on. No picker, no "Upload files" button. |
| capture | () => Promise<F | null | undefined> | — | Takes a photo and resolves to it (null when cancelled), e.g. expo-image-picker's
launchCameraAsync. Adds a camera button (named by captureLabel). |
| accept | string[] | — | Accepted types: MIME types (image/png), wildcards (image/*) and extensions (.pdf). |
| multiple | boolean | false | Let the picker return several files at once. Files still add up to maxFiles. |
| maxFiles | number | — | Most files in the list; extra ones are turned away with a message. |
| maxSize | number | — | Largest file in bytes, checked after transform. Bigger files are turned away with a message. |
| transform | (file: F) => F | Promise<F> | — | Runs on each file after the accept check and before maxSize and validate, e.g. to shrink
a photo with expo-image-manipulator. Resolve to the file to keep. If it throws, the file is
turned away with the error's message. |
| validate | (file: F) => string | null | undefined | — | Your own check, run last: return a message to turn the file away. Validate again on the server. |
| files | F[] | — | Controlled list. Pass it with onFilesChange to clear or set the list from outside. |
| defaultFiles | F[] | — | The starting list when uncontrolled. |
| onFilesChange | (files: F[]) => void | — | Called with the whole new list after files are added or removed. |
| onReject | (rejections: FileRejection<F>[]) => void | — | Files turned away by accept, transform, maxSize, maxFiles or validate. They also show in the list with their error until removed. |
| disabled | boolean | — | Nothing can be picked; the buttons look disabled. |
| readOnly | boolean | — | Files stay listed; nothing can be picked or removed. |
| busy | boolean | — | An upload is running: picking is blocked and a bar shows progress. |
| progress | number | — | 0–100 while busy. |
| addLabel | string | 'Upload files' | The pick button's text. |
| captureLabel | string | messages.takePhoto ('Take photo') | The camera button's text. Shown with capture. |
| style | StyleProp<ViewStyle> | — | — |