Overview
Reference usage
Accessible file picker and drag-and-drop surface that validates dropped files, announces results, and can render consumer-driven upload progress rows.
Usage
Use browseLabel when the picker action needs more specific text, such as directory or import flows. Native input attributes still pass through to the real file input, so directory selection can use webkitdirectory:
Upload queue and retry
FileUpload owns local validation, not network upload. Each picker selection or drop is validated as one batch before callbacks run:
onFilesAcceptedreceives the accepted nativeFile[]so you can enqueue uploads.onRejectreceives rejected files withtoo-large,wrong-type, ortoo-manyreasons.onFilesChangereceives the full locally resolved queue. Accepted rows start aspending; rejected rows start aserrorwith a visible message andrejectionReason.
The default file list includes a remove button for every row. In uncontrolled use, removing a row immediately updates the local queue and frees a maxFiles slot. In controlled use, removal reports the next queue through onFilesChange; update files with that value to reflect the change. Resetting an associated native form clears the uncontrolled queue and reports an empty list through onFilesChange.
Pass the controlled files prop to show your uploader's current pending, uploading, ready, or error state. Set progress from 0–100 while an entry uploads. When you provide onFileRetry, failed rows render a retry button and return the complete entry to your upload queue handler. The component never starts, cancels, or retries a network request by itself.
Variants
variant chooses how the surface is drawn; validation, callbacks and the controlled files queue behave the same in each.
dropzone(the default) is the large dashed area with a title, a description and a Browse button, with the file rows below it.compactis for a short list on a form (reference documents on an agent). The settled files are one bordered list of rows (name, size, remove), an arriving file is one line (name, a progress bar, its percent, and a text Cancel upload button), and the zone is one dashed line (a secondary button and one line of help) that stays below the list. SetbrowseLabelto the button's words anddescriptionto the line beside it.buttonis only the secondary button, with an upload glyph, and a line of text beside it (summary, usually what was uploaded). It draws no rows; read the file throughonFilesChange.
Cancel upload is drawn on an uploading row in the compact variant when you pass onFileCancel. The component never stops a network request: stop the upload and drop the entry from files.
In the compact and button variants a file that fails local validation is a danger alert between the list and the zone, not a row, and it is announced as an alert. The alert says what the last attempt did not add, so choosing the next file clears it (in controlled use, the queue onFilesChange reports no longer holds it). Word it with rejectionMessage, which receives the file, the reason and the limits:
The default dropzone keeps a rejection as a row that names the file. File sizes read as 4 KB and 12 MB: a whole unit prints without a decimal.
Click to upload or drop files
image files or PDF
Images or PDF, up to 5 MB.
When to use
- Collecting one or more files while keeping the native picker available for keyboard and assistive-technology users.
- Showing per-file upload progress or rejection errors below a prominent dropzone surface.
- You only need a hidden native file input with no custom UI.
Examples
Basic file upload
Drag-and-drop file picker with acceptance and rejection feedback.
Reference documents, uploading and too large
variant="compact" is a short list on a form: settled files are one bordered list (name, size, remove), an arriving file is one line (name, bar, percent, Cancel upload), and the one-line zone stays below. A file over the limit is a danger alert between the list and the zone that names the file and says nothing was added; the next file chosen clears it.
Props
Name | Type | Default | Description |
|---|---|---|---|
id | text | Stable id for the native file input. Required when composing with FormField. | |
accept | text | Native file accept filter. | |
multiple | boolean | false | Allow more than one file. Default false. |
maxSize | number | Maximum allowed file size in bytes. | |
maxFiles | number | Maximum number of files allowed. Files beyond this limit are rejected. | |
disabled | boolean | Disables the file picker and drag-and-drop surface. | |
required | boolean | ||
name | text | Native input name used for form submission. | |
variant | 'dropzone' | 'compact' | 'button' | 'dropzone' | How the surface is drawn.
- 'dropzone' is the large dashed area with a title, a description and a Browse button, the
file rows below it.
- 'compact' is a one-line dashed zone (a secondary button and one line of text) that sits
under the file rows, for a short list on a form. The rows are one bordered list (name, size,
remove), an uploading file is one line (name, bar, percent, Cancel upload), and a file that
fails local validation is a danger alert between the rows and the zone saying nothing was
added, not a row. The alert stays until the next file is chosen.
- 'button' is just the secondary button and a line of text beside it (summary), for one
file whose details the page already shows. It draws no rows; read the files through
onFilesChange. A rejection is still an alert. |
summary | text | The line of text beside the button in the 'button' variant, usually what was uploaded, such
as the file name and what was read from it. Falls back to description. | |
rejectionMessage | (rejection: FileUploadRejection) => string | Words for a local validation failure. Receives the file, the reason and the limits, and returns the sentence shown for it, so a page can say "documents" instead of "files" and add what happened to the rest of the batch. Defaults to a generic sentence naming the file and the limit. | |
cancelLabel | text | 'Cancel upload' | Visible text of the cancel action on an uploading file. Only drawn when onFileCancel is set. |
title | text | 'Click to upload or drop files' | Visible title for the dropzone. |
description | text | Visible description below the title. Defaults to a summary derived from accept. | |
draggingLabel | text | 'Drop to add' | Visible label shown while files are dragged over the dropzone. |
browseLabel | text | 'Browse files' | Visible text for the browse button. |
borderBeamVisible | boolean | true | Adds focus and drag-active border emphasis to the dropzone. |
files | FileUploadEntry[] | Consumer-driven file rows, including upload progress and error states. | |
idle | snippet | Replaces the default resting-state dropzone body. | |
dragActive | snippet | Replaces the default drag-active dropzone body. | |
fileList | snippet | Replaces the default file-list renderer. Receives the live resolved rows, including an empty array, and a removal callback when the queue is mutable. | |
onFilesAccepted | (files: File[]) => void | Fires with accepted files after local validation passes. | |
onFilesChange | (entries: FileUploadEntry[]) => void | Fires with the full resolved entry list after local validation changes it. | |
onReject | (files: RejectedFile[]) => void | Fires with rejected files and reasons after local validation runs. | |
onFileRetry | (entry: FileUploadEntry) => void | Called when the retry button is activated for a failed file. | |
onFileCancel | (entry: FileUploadEntry) => void | Called when Cancel upload is activated on an uploading file. The component does not remove the
row itself: stop the upload and drop the entry from files. Without it an uploading file has
no cancel action. | |
oncancel | EventHandler<Event, T>undefinednull |