File Drop Zone
Picks files by drag and drop or with the keyboard.
Built on ui-sdk’s File Input, so accept, maxSize, maxFiles and multiple validate dropped
and chosen files alike. Chosen files are listed below with their sizes and a remove button.
It’s a form input like any other: the files submit with the form under its name, required
holds the form back until there’s one, a form reset clears them and a disabled <fieldset>
disables it.
Dependencies
What it's built from and what's built from it in Base, read from the imports in its source.
| Uses | ButtonprimitiveTextprimitive |
|---|---|
| Used by | Nothing yet. |
| Packages | @ui-sdk/core@0.1.0-beta.20@ui-sdk/react@0.1.0-beta.20lucide-react@1.73.0 |
Installation
Set the project up for Base once first, as Getting started shows. Then add it with the CLI, or by hand.
With the CLI
Manually
Install its packages:
Add the components it uses first, listed under Dependencies.
Then copy the source:
API reference
Generated from Base's types. Props marked ours are added here; the rest come from the ui-sdk part it wraps. Every part also accepts its element's native attributes.
FileDropZone
A drop zone with a browse button, and the chosen files below it.
- browseLabelours
The browse button's label.
Type ReactNode · Default Browse files
- hintours
Limits worth knowing before choosing, like file types and size.
Type ReactNode
- accept
The files to accept, like the
acceptattribute: MIME types ("image/png"), wildcards ("image/*") and extensions (".pdf"), in a comma-separated string or an array. Without it, any file.Type string | readonly string[]
- announcement
What screen readers hear after a change. Return null for nothing.
Type (change: FileInputChange) => string | null · Default "2 files accepted. 1 file rejected.", or "photo.png removed."
- capture
Opens the camera on phones instead of the files:
"user"for the front camera,"environment"for the back one, ortruefor the default one.Type boolean | "user" | "environment"
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: FileInputState) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: FileInputState) => string)
- controller
Adds and removes files from anywhere. Create one with
createFileInputController().Type { getValue: () => readonly File[]; setValue: (files: readonly File[], options?: FileInputChangeOptions) => boolean; addFiles: (files: readonly File[] | FileList, options?: FileInputChangeOptions) => boolean; ... 4 more ...; isDragging: () => boolean; }
- debug
Logs every state change with its reason to the console, in development builds.
Type boolean
- defaultValue
The files at first, when uncontrolled. A form reset returns to them.
Type File[] · Default []
- directory
Picks a whole folder, with every file inside it. Turns on
multiple.Type boolean
- disabled
Disables it like a native control: the trigger can't be focused or used, drops and pastes are ignored, and nothing is submitted.
Type boolean
- form
The id of a form to belong to, when it isn't inside that form.
Type string
- maxFiles
The most files accepted at a time. The first ones that pass the other checks are accepted, and the rest are rejected.
Type number
- maxSize
The largest size accepted, in bytes.
Type number
- minSize
The smallest size accepted, in bytes.
Type number
- multiple
Holds more than one file. New files join the ones it has, up to
maxFilesin all. Without it, a new file replaces the one it has.Type boolean · Default false
- name
The name the files submit under. Without one, nothing is submitted.
Type string
- onReject
Runs when files fail the checks, after
onValueChange, with every reason each failed, even when none were accepted.Type (rejected: FileRejection[], details: CommitDetails<FileInputValueChangeReason>) => void
- onValueChange
Runs when files are added or removed, with what changed in the details.
details.cancel()stops it.Type (value: File[], details: FileInputValueChangeDetails) => void
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<FileInputState>
- required
Blocks form submission until it holds a file, with the browser's own message.
Type boolean
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: FileInputState) => CSSProperties)
- validate
A check of your own. Return a reason, like
"duplicate", to reject the file, or nothing to accept it.acceptedholds the files of the same choice, drop or paste accepted before this one.Type (file: File, batch: { accepted: readonly File[]; }) => string | void | null
- value
The files, to control the file input.
Type File[]