File Drop
A drop area that receives local files by drag and drop or the file picker.
Drag documents here, or
PDF, Markdown, TXT or DOCX. Up to 5 files, 15 MB each.
Usage guidelines
- Always include a
FileDropTrigger: Dragging needs a pointer. The trigger is the keyboard and screen reader path: it is a button that opens the system file picker, while the hidden file input stays out of the tab order. - Name the area and the trigger: Render the root as a landmark with a name, such as
render={<section aria-label="Knowledge base upload" />}, and give the trigger visible text that says what it does. - Pick one selection mode: Without
multiple,onFileSelectreceives exactly one file and a selection of several files is rejected as a whole. Withmultiple,onFilesSelectreceives the accepted files andmaxFileskeeps the first ones. - Report every rejection:
acceptfilters both dropped and picked files. Files that fail it arrive inonFilesRejectwith reasontype; files over the limit arrive with reasoncount. Show the message in arole="alert"element next to the area. Withmultiple, a mixed drop callsonFilesSelectfirst andonFilesRejectafter it, with the sameeventDetails.event, so one message can cover the whole selection. - Check file size yourself:
FileDropchecks type and count only. State the accepted types and the size limit in visible text, filter oversized files inonFilesSelect, and report them with the other rejections. To cap the total across several selections, pass the remaining slots asmaxFiles. - Keep the files in feature state:
FileDropis not a form control. It does not register withFieldorForm, and its input has noname. Store the selected files and send them when the form submits, and validate a missing file in the submit handler. - Style the drop state with data attributes: The root has no surface styles. Use
data-draggingfor the drag highlight anddata-disabledfor the unavailable state; the trigger receives the same attributes. - Use
disabledwhen uploads are unavailable: The area refuses drops and the trigger becomes a disabled button. Explain why in nearby text. - Folders need
expandDirectories: Dropped folders are skipped by default. SetexpandDirectoriesto replace each folder with the files inside it, recursively; the sameacceptand count rules apply to the result.
Anatomy
FileDrop renders a <div> with a hidden <input type="file"> inside it. accept and multiple configure both that input and the drop validation. A drag that carries no files, such as selected text, passes through untouched.
Examples
Single file and rejection feedback
Without multiple, the area accepts one file. Once a file is chosen, a second FileDropTrigger rendered as a Button replaces it.
Drag a CSV of question and answer pairs here, or
Inside a form
Keep the chosen file in state and check for it when the form submits. The submit button stays enabled; submitting without a file shows the error and links it to the trigger with aria-describedby. While the package installs, the submit button shows loading, repeated submits are ignored and the area is disabled. A rejected package reports in the same error message, and success is announced in a status region.
Disabled
A disabled area ignores drops and disables its trigger. The surrounding text says why uploads are unavailable.
Document limit reached for the Sandbox plan
Upgrade to upload more documents.
Keyboard
| Key | Action |
|---|---|
| Tab | Moves focus to the trigger. The hidden file input is not a tab stop. |
| EnterorSpace | Opens the system file picker from the trigger. |
API reference
FileDrop
Receives local files via drag-and-drop or the system file picker, letting non-file drags pass through untouched. Renders a <div> element.
Exposes data-dragging and data-disabled without imposing surface styles; validates accept and file counts unless validate={false}.
| Prop | Type | Default | Details |
|---|---|---|---|
accept | string | No default | |
disabled | boolean | false | |
expandDirectories | boolean | No default | |
multiple | boolean | false | |
maxFiles | number | No default | |
validate | boolean | true | |
onFileSelect | ((file: File, eventDetails: FileDropEventDetails) => void) | No default | |
onFilesSelect | (files: File[], eventDetails: FileDropEventDetails) => void | No default | |
onFilesReject | (rejections: FileDropRejection[], eventDetails: FileDropEventDetails) => void | No default | |
className | string | ((state: FileDropState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, FileDropState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: FileDropState) => React.CSSProperties | undefined) | No default | |
Valid prop combinations:
multiple: boolean,maxFiles?: number,validate?: true,onFileSelect?: undefined,onFilesSelect: (files: File[], eventDetails: FileDropEventDetails) => void,onFilesReject?: ((rejections: FileDropRejection[], eventDetails: FileDropEventDetails) => void)multiple?: false,maxFiles?: undefined,validate?: true,onFileSelect: (file: File, eventDetails: FileDropEventDetails) => void,onFilesSelect?: undefined,onFilesReject?: ((rejections: FileDropRejection[], eventDetails: FileDropEventDetails) => void)multiple?: boolean,maxFiles?: undefined,validate: false,onFileSelect?: undefined,onFilesSelect: (files: File[], eventDetails: FileDropEventDetails) => void,onFilesReject?: undefined
| Attribute | Description |
|---|---|
data-dragging | Present while files are being dragged over the drop area. |
data-disabled | Present when the drop area is disabled. |
FileDropTrigger
Opens the system file picker as the keyboard and screen-reader path to the drop area. Renders a <button> element.
| Prop | Type | Default | Details |
|---|---|---|---|
nativeButton | boolean | true | |
className | string | ((state: FileDropState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, FileDropState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: FileDropState) => React.CSSProperties | undefined) | No default | |
| Attribute | Description |
|---|---|
data-dragging | Present while files are being dragged over the drop area. |
data-disabled | Present when the drop area is disabled. |