File Upload

A drop zone or button for choosing files, and a list of the files chosen.

Installation

  1. Add the registryOnce per project
  2. Add file-upload

Usage

FileUpload holds the chosen files as File objects. It doesn't upload them: send them yourself, or give it a name to submit them with a form.

FileUploadDropzone accepts dropped files and opens the file picker on click. It's a button, so use spans inside it. FileUploadList renders its child for each file. FileUploadItemMetadata shows the file's name and size, and cuts a long name in the middle with Truncate, so its extension stays in sight.

accept, maxSize and maxFiles reject files, and onFileReject tells you which and why.

Composition

Examples

Upload progress

Put a FileUploadItemProgress in FileUploadItemMetadata to show progress while a file uploads.

With a label

Point a FieldLabel at the dropzone's id, or leave out htmlFor and the label names the dropzone and the trigger itself. Set invalid on the Field and explain a rejected file with a FieldError. The dropzone and the trigger read out the field's FieldDescription and FieldError, and turn invalid or disabled with the field.

One contact per row, up to 5 MB.

In a form

Give a Field or the upload a name, and the files submit under it, each as its own value, so formData.getAll(name) returns them. Pass form with a form's id when the upload sits outside it. With required, the form won't submit without a file, which fails as valueMissing. A form reset brings back defaultValue. A Form's onFormSubmit gets the File objects as an array.

One PDF, sent with your application.

With a button

FileUploadTrigger opens the file picker from a button, when a drop zone would take too much room.

Disabled

Props

The file also exports formatFileSize(bytes), which returns a size such as "2.4 MB".

The tables leave out className, style and render. Parts built on Base UI take them as its styling and composition guides describe.

FileUpload

FileUploadTrigger

FileUploadList

FileUploadItem

FileUploadItemProgress

FileUploadItemRemove