Upload Drop Area
A drag-and-drop file area with a click-to-browse fallback. Built on a native
<input type="file">, so the browser owns file selection, keyboard operation
and form participation.
The drag target itself is the generic dropArea action (exported from the
package): it wires the dragover/dragleave/drop trio, reflects the state on a
data-dragover attribute and hands the raw DataTransfer to onDrop. It is
reusable on any element — a TreeView item, a kanban column — and it is a
pointer-only enhancement by design: drag-and-drop has no keyboard or
assistive-tech contract, so always pair it with an accessible alternative
(here, the click-to-browse input).
Import
Section titled “Import”<script> import UploadDropArea from "@invisible-ui/svelte/UploadDropArea.svelte";</script><script setup> import { UploadDropArea } from "@invisible-ui/vue";</script>import { UploadDropArea } from "@invisible-ui/react";<script type="module"> import "@invisible-ui/elements/define";</script>
<ds-upload-drop-area></ds-upload-drop-area>In Elements, picked and dropped files arrive in the bubbling files event,
and the files the accept filter leaves out in the bubbling reject event:
<ds-upload-drop-area accept="image/*" multiple name="photos"></ds-upload-drop-area>
<script type="module"> const area = document.querySelector("ds-upload-drop-area"); area.addEventListener("files", (event) => upload(event.detail.files)); area.addEventListener("reject", (event) => log(event.detail.rejected));</script>| Prop | Type | Default | Description |
|---|---|---|---|
accept | string | undefined | undefined | Accepted file types (the input's accept attribute), e.g. "image/*". |
multiple | boolean | false | Allow selecting/dropping more than one file. |
disabled | boolean | false | |
name | string | undefined | undefined | Form field name (the underlying file input). |
caption | string | undefined | undefined | Optional grey caption under the text (e.g. accepted formats / max size). |
onFiles | ((files: File[]) => void) | undefined | undefined | Called with the selected/dropped files. |
onRejected | ((rejected: UploadRejection[]) => void) | undefined | undefined | Called with the files the area left out: a type accept does not name, or a file beyond the first in an area without multiple. |
icon | Snippet | undefined | undefined | Replaces the built-in upload icon. |
| Prop | Type | Default | Description |
|---|---|---|---|
accept | string | undefined | Accepted file types (the input's accept attribute), e.g. "image/*". |
multiple | boolean | false | Allow selecting/dropping more than one file. |
disabled | boolean | false | |
name | string | undefined | Form field name (the underlying file input). |
caption | string | undefined | Optional grey caption under the text (e.g. accepted formats / max size). |
onFiles | (files: File[]) => void | undefined | Called with the selected/dropped files. |
onRejected | (rejected: UploadRejection[]) => void | undefined | Called with the files the area left out: a type accept does not name, or a file beyond the first in an area without multiple. |
Slots: default, icon.
| Prop | Type | Default | Description |
|---|---|---|---|
accept | string | — | Accepted file types (the input's accept attribute), e.g. "image/*" or ".pdf,.docx". The picker filters by it, and so does a drop. |
multiple | boolean | false | Allow selecting or dropping more than one file. |
disabled | boolean | false | |
name | string | — | Form field name (the underlying file input). |
caption | string | — | Optional caption under the text, such as the accepted formats or the size limit. |
onFiles | (files: File[]) => void | — | Called with the selected or dropped files. |
onRejected | (rejected: UploadRejection[]) => void | — | Called with the files the area left out: a type accept does not name, or a file beyond the first in an area without multiple. |
children | ReactNode | — | Replaces the default prompt text. |
icon | ReactNode | — | Replaces the built-in upload icon. |
| Attribute | Reactive | Description |
|---|---|---|
accept | yes | |
multiple | yes | |
disabled | yes | |
name | yes | |
caption | yes |
Reactive attributes re-render the element when they change after the first render.
Properties: files (read-only), disabled.
Emits: bubbling files CustomEvent with detail.files (a File[]) when files are picked or dropped and the area takes some; bubbling reject CustomEvent with detail.rejected ({ file, reason }[], reason type or count) for the files it leaves out.
Dropped and picked files are forwarded through the same onFiles callback.
Accepted files
Section titled “Accepted files”Picked and dropped files go through the same filter. accept has the format
of the file input’s accept attribute: extensions (.pdf), media types
(application/pdf) and type families (image/*), compared without case. A
file with no media type matches by extension only. Without multiple, the
area takes the first file that passes the filter.
The files the filter leaves out never reach onFiles and never join the
form. The area names each one in a message under it, with the hazard icon,
and reports them to onRejected (reject in Elements) as
{ file, reason }, where reason is "type" or "count". The message is
an alert, and the file input points at it through aria-describedby. It
stays until the next pick or drop. A drop with no file to take leaves the
files the input already holds.
The filter is a convenience. The browser’s picker can still offer every file, and a file’s name and media type can be wrong, so the app validates the files it receives, on the server too.
<UploadDropArea accept=".pdf,image/*" multiple onFiles={(files) => upload(files)} onRejected={(rejected) => track(rejected.map(({ file, reason }) => `${file.name}: ${reason}`))}/>The messages come from the catalog: uploadDropArea.rejectedType and
uploadDropArea.rejectedCount, both with a {name} placeholder.
Example
Section titled “Example”<UploadDropArea accept="image/*" multiple onFiles={(files) => upload(files)} />
<!-- The generic action, on any element: --><script> import { dropArea } from "@invisible-ui/svelte";</script><li use:dropArea={{ onDrop: (data) => moveInto(node, data) }}>Documents</li>In React, children replace the prompt and icon the glyph, and
useDropArea returns the props for a drop target of your own:
<UploadDropArea accept="image/*" multiple onFiles={upload} />;
function Folder({ node }) { const { dropAreaProps } = useDropArea({ onDrop: (data) => moveInto(node, data) }); return <li {...dropAreaProps}>Documents</li>;}Themeable via --ds-upload-drop-area-*.
Accessibility
Section titled “Accessibility”- The native file input is the control: Tab reaches it, Enter or Space opens the picker, and the prompt is its name.
- Drag and drop is a pointer enhancement; the picker offers the same files.
- Files the filter leaves out are named in an alert after the area, with the
hazard icon, so the message never relies on color. The input points at it
through
aria-describedby. - Assistive technology: not tested.