Skip to content

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.

hero.tsx

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, onFileSelect receives exactly one file and a selection of several files is rejected as a whole. With multiple, onFilesSelect receives the accepted files and maxFiles keeps the first ones.
  • Report every rejection: accept filters both dropped and picked files. Files that fail it arrive in onFilesReject with reason type; files over the limit arrive with reason count. Show the message in a role="alert" element next to the area. With multiple, a mixed drop calls onFilesSelect first and onFilesReject after it, with the same eventDetails.event, so one message can cover the whole selection.
  • Check file size yourself: FileDrop checks type and count only. State the accepted types and the size limit in visible text, filter oversized files in onFilesSelect, and report them with the other rejections. To cap the total across several selections, pass the remaining slots as maxFiles.
  • Keep the files in feature state: FileDrop is not a form control. It does not register with Field or Form, and its input has no name. 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-dragging for the drag highlight and data-disabled for the unavailable state; the trigger receives the same attributes.
  • Use disabled when 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. Set expandDirectories to replace each folder with the files inside it, recursively; the same accept and count rules apply to the result.

Anatomy

tsx
tsx

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

single-file.tsx

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.

Drop a .difypkg plugin package here

form.tsx

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.

disabled.tsx

Keyboard

KeyAction
TabMoves focus to the trigger. The hidden file input is not a tab stop.
EnterorSpaceOpens 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}.

Base UI FileDrop docs

Props
PropTypeDefaultDetails
acceptstringNo default
disabledbooleanfalse
expandDirectoriesbooleanNo default
multiplebooleanfalse
maxFilesnumberNo default
validatebooleantrue
onFileSelect((file: File, eventDetails: FileDropEventDetails) => void)No default
onFilesSelect(files: File[], eventDetails: FileDropEventDetails) => voidNo default
onFilesReject(rejections: FileDropRejection[], eventDetails: FileDropEventDetails) => voidNo default
Base UI FileDrop docs

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
Data attributes
AttributeDescription
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.

Base UI FileDropTrigger docs

Data attributes
AttributeDescription
data-dragging

Present while files are being dragged over the drop area.

data-disabled

Present when the drop area is disabled.