File drop zone
Drop, click or paste files into a real file input, so a plain form post sends them. Limits on type, size and count, a list with thumbnails, and French words out of the box.
Installation
pnpm add @heyramzi/uiUsage
import { FileDropZone } from "@heyramzi/ui/components/file-drop-zone";Keyboard and accessibility
| Key | Does |
|---|---|
| Tab | Moves focus to the zone, then to each file's remove button. |
| Space Enter | On the zone, opens the file picker. |
- The zone is a label over a visually hidden input type=file, so a screen reader announces a file field, and an outside label with for={id} names it.
- Refusals (wrong format, too heavy, too many) sit in a polite live region tied to the input by aria-describedby.
- Each remove button is named for its file, so a list of them reads apart.
- With one file and no multiple, the file takes the zone's place, and removing it puts focus back on the zone.
API reference
namestring- The file input's name: what the form post carries the files under.
idstring- The id of the real input, for an outside `<label for>`.
acceptstring- Same syntax as the input's `accept`: `.pdf`, `application/pdf`, `image/*`.
multipleboolean- Default
false maxFilesnumber- Most files the list holds when `multiple` is set.
maxFileSizenumber- Largest file, in bytes.
requiredboolean- Default
false disabledboolean- Default
false capturePasteboolean- Default
false - Takes files pasted anywhere on the page.
filesbindableFile[]- Default
[] - The chosen files. Kept in step with the real input, so a plain form post sends them.
onUpload(added: File[]) => void- Called with the files a drop, a paste or the picker just added.
onFileRejected(rejected: Rejection[]) => void- Called with each file turned away and why.
labelsPartial<Labels>classstring
| Prop | Type | Default |
|---|---|---|
name The file input's name: what the form post carries the files under. | string | |
id The id of the real input, for an outside `<label for>`. | string | |
accept Same syntax as the input's `accept`: `.pdf`, `application/pdf`, `image/*`. | string | |
multiple | boolean | false |
maxFiles Most files the list holds when `multiple` is set. | number | |
maxFileSize Largest file, in bytes. | number | |
required | boolean | false |
disabled | boolean | false |
capturePaste Takes files pasted anywhere on the page. | boolean | false |
files bindable The chosen files. Kept in step with the real input, so a plain form post sends them. | File[] | [] |
onUpload Called with the files a drop, a paste or the picker just added. | (added: File[]) => void | |
onFileRejected Called with each file turned away and why. | (rejected: Rejection[]) => void | |
labels | Partial<Labels> | |
class | string |