FileUpload
Select and validate local files through a drop area or compact button.
Anatomy#
Usage#
Use FileUpload to collect local files before the application sends them. Selection and validation happen in the component; upload transport belongs to the caller.
Selecting files#
variant sets the appearance: area (the default) shows a large dashed drop area, and button
shows a compact picker button. Clicking anywhere in the visible control, including its padding,
icon, and text, opens the file picker; file previews and removal actions are outside the picker hit
area.
dropzone (default true) controls only whether files can be dropped onto the control; it does not
change how the control looks.
Use multiple when the value can hold more than one File. New files are appended to the
selection, and value and onValueChange use a File[]. Without multiple, a new file replaces
the current one, and the value is File | null.
File list#
The selected files appear in a list below the control, with an image thumbnail for image files and
fileIcon for other types. Set fileList={false} to omit the list and render the selection
yourself from onValueChange.
Use itemRender to replace each entry. It receives file, index, previewUrl, remove, and
disabled, and must return an <li>.
Rejections and forms#
accept, minSize, maxSize, and maxFiles validate each picked or dropped file before it is
added. maxFiles counts files already selected and applies only with multiple. Accepted files
from the same batch are still added.
Rejected files are reported to onValueInvalid as rejections, each with the file and its
reasons array (named after ValidityState keys):
typeMismatch: not matchingacceptrangeUnderflow: smaller thanminSizerangeOverflow: larger thanmaxSizetooLong: exceedsmaxFilesduplicate: already selected
readOnly keeps the selected list visible but blocks adding and removing files. disabled removes
all interaction. Both inherit the enclosing Field’s state when omitted, and an explicit false
overrides it.
Keyboard interaction#
| Key | Description |
|---|---|
| ↵ / Space | Opens the native operating system file picker dialog when the upload control is focused. |
Examples#
Multiple and max files#
Set multiple and maxFiles to cap selections, and handle onValueInvalid for rejected files.
Rejections#
Map onValueInvalid reason codes to messages. Validation runs before the file is added to the
value.
Button variant#
Set variant="button" for a compact picker button instead of the drop area. The selected file still
comes from onValueChange.
Form#
Place FileUpload in form.Field so the schema owns required files and submit output.
Disabled and read-only#
disabled blocks new files. readOnly keeps the current list visible without allowing add or
remove.
API Reference#
Attributes#
data-disableddata-invaliddata-readonlydata-requireddata-draggingProps#
Props for the FileUpload component. Renders a <div> element by default.