Drop files or browse for them, with type, size and count checks and a list of what was picked.
$ pnpm dlx shadcn@latest add https://dashral.com/r/file-dropzone.jsonInstallation
$ pnpm dlx shadcn@latest add https://dashral.com/r/file-dropzone.jsonAdds the component, the components it builds on, its npm packages and the theme tokens it uses. Using Dashral often? Add the registry to components.json once:
{
"registries": {
"@dashral": "https://dashral.com/r/{name}.json"
}
}Then add components by name:
$ pnpm dlx shadcn@latest add @dashral/file-dropzoneUsage
import { FileDropzone } from "@/components/dashral/file-dropzone"
<FileDropzone
label="Attachments"
accept="image/*,.pdf"
maxSize={5 * 1024 * 1024}
onValueChange={(files) => api.upload(files)}
/>Examples
One file
multiple={false}: a new file replaces the old one. title and hint set the text inside the drop area.
API reference
FileDropzone
| Prop | Type | Default |
|---|---|---|
value / defaultValue | File[]Picked files, controlled or initial. | [] |
onValueChange | (value: File[]) => voidCalled with the new value. | — |
accept | stringLike the accept attribute: "image/*", ".pdf,.docx". | — |
multiple | booleanSeveral files, or one that replaces the last. | true |
maxFiles / maxSize | numberHow many, and the largest size in bytes. | — |
title / hint | ReactNodeThe lines inside the drop area; by default the hint says what's accepted. | — |
showFiles | booleanfalse hides the list of picked files, to show your own (with upload progress, say). | true |
disabled / id / name | — | |
label | ReactNodeShown above, linked to the control. | — |
description | ReactNodeA hint under the control. | — |
error | boolean | ReactNodetrue shows the error style; a message also shows under the control. | — |
labelAction | ReactNodeAt the end of the label's row, e.g. a “Forgot password?” link or the current value. | — |
withAsterisk | booleanMarks the label with an asterisk, e.g. alongside required. | false |
classNames | { root, label, description, error, dropzone, files }Classes for each part. | — |
Keyboard
| Keys | Action |
|---|---|
| Tab | Focus the drop area |
| EnterorSpace | Open the file picker |
| Tab | Then each file's remove button |
Accessibility
- The drop area is a button, described by the hint, so it works without dragging.
- Refused files are listed in an alert with the reason; each file's remove button names the file.