import { DropZone } from "capsomer/react/drop-zone";
<DropZone accept="image/*,.pdf" maxBytes={5 * 1024 * 1024} maxFiles={4} multiple scope="page" paste
hint="Images and PDF, up to 5 MB each, up to 4 at a time." onAccepted={(files) => upload(files)} />
// An app that shows its own upload queue:
<DropZone accept="image/*" multiple acceptedList={false} onAccepted={(files) => queue.add(files)} />
Examples
File over
<div class="cap-drop" data-state="over" id="dz-over">
<label class="cap-drop-label">
<input class="cap-drop-input" type="file" multiple accept="image/*,.pdf" data-cap-part="input" aria-labelledby="dz-over-title" aria-describedby="dz-over-hint" />
<span class="cap-drop-icon" aria-hidden="true"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M12 16V4m0 0L7 9m5-5 5 5M4 16v3a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1v-3" /></svg></span>
<span class="cap-drop-title" id="dz-over-title"><span class="cap-drop-idle">Drop files here, or <span class="cap-drop-browse">browse</span></span><span class="cap-drop-over">Drop to upload</span></span>
<span class="cap-drop-hint" id="dz-over-hint">Images and PDF, up to 5 MB each, up to 4 at a time.</span>
</label>
<div class="cap-drop-status" role="status" data-cap-part="status"></div>
<div class="cap-drop-rejections" role="alert" data-cap-part="rejections"></div>
</div>
Files refused, each with its reason
<div class="cap-drop" data-state="rejected" id="dz-rejected">
<label class="cap-drop-label">
<input class="cap-drop-input" type="file" multiple accept="image/*,.pdf" data-cap-part="input" aria-labelledby="dz-rejected-title" aria-describedby="dz-rejected-hint" />
<span class="cap-drop-icon" aria-hidden="true"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M12 16V4m0 0L7 9m5-5 5 5M4 16v3a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1v-3" /></svg></span>
<span class="cap-drop-title" id="dz-rejected-title"><span class="cap-drop-idle">Drop files here, or <span class="cap-drop-browse">browse</span></span><span class="cap-drop-over">Drop to upload</span></span>
<span class="cap-drop-hint" id="dz-rejected-hint">Images and PDF, up to 5 MB each, up to 4 at a time.</span>
</label>
<div class="cap-drop-status" role="status" data-cap-part="status"></div>
<div class="cap-drop-rejections" role="alert" data-cap-part="rejections">
<p class="cap-drop-lead" data-tone="crit"><svg class="cap-status-glyph" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><path fill="currentColor" fill-rule="evenodd" d="M5 1h6l4 4v6l-4 4H5l-4-4V5zM7.2 4h1.6v5H7.2zM7.2 10.4h1.6V12H7.2z" /></svg>3 files were not added</p>
<ul class="cap-drop-files">
<li>fieldnotes-scan.heic: type not allowed. This takes images and PDF.</li>
<li>site-recording.pdf: too big at 8.4 MB. The limit is 5 MB.</li>
<li>logo-variant-5.png: too many files. The limit is 4 files at a time, so this one was left out.</li>
</ul>
</div>
</div>
Several files taken
<div class="cap-drop" id="dz-accepted">
<label class="cap-drop-label">
<input class="cap-drop-input" type="file" multiple accept="image/*,.pdf" data-cap-part="input" aria-labelledby="dz-accepted-title" aria-describedby="dz-accepted-hint" />
<span class="cap-drop-icon" aria-hidden="true"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M12 16V4m0 0L7 9m5-5 5 5M4 16v3a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1v-3" /></svg></span>
<span class="cap-drop-title" id="dz-accepted-title"><span class="cap-drop-idle">Drop files here, or <span class="cap-drop-browse">browse</span></span><span class="cap-drop-over">Drop to upload</span></span>
<span class="cap-drop-hint" id="dz-accepted-hint">Images and PDF, up to 5 MB each, up to 4 at a time.</span>
</label>
<div class="cap-drop-status" role="status" data-cap-part="status">
<p class="cap-drop-lead">3 files are ready to upload.</p>
<ul class="cap-drop-files">
<li><span class="cap-drop-file-name">spring-hero.jpg</span><span class="cap-drop-file-size">412 kB</span></li>
<li><span class="cap-drop-file-name">uptime-report-september.pdf</span><span class="cap-drop-file-size">1.8 MB</span></li>
<li><span class="cap-drop-file-name">annual-report-chart.png</span><span class="cap-drop-file-size">96 kB</span></li>
</ul>
</div>
<div class="cap-drop-rejections" role="alert" data-cap-part="rejections"></div>
</div>
<main>
<h1>Media library</h1>
<p>Drag a file anywhere on this page. A panel covers the window and says what releasing does.</p>
<div class="cap-drop" data-cap="drop-zone" data-scope="page" data-state="over" data-max-bytes="5242880" id="dz-page">
<label class="cap-drop-label">
<input class="cap-drop-input" type="file" multiple accept="image/*" data-cap-part="input" aria-labelledby="dz-page-title" aria-describedby="dz-page-hint" />
<span class="cap-drop-icon" aria-hidden="true"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M12 16V4m0 0L7 9m5-5 5 5M4 16v3a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1v-3" /></svg></span>
<span class="cap-drop-title" id="dz-page-title"><span class="cap-drop-idle">Drop files anywhere, or <span class="cap-drop-browse">browse</span></span><span class="cap-drop-over">Drop to upload</span></span>
<span class="cap-drop-hint" id="dz-page-hint">Images up to 5 MB each.</span>
</label>
<div class="cap-drop-status" role="status" data-cap-part="status"></div>
<div class="cap-drop-rejections" role="alert" data-cap-part="rejections"></div>
<div class="cap-drop-overlay" aria-hidden="true">
<div>
<p class="cap-drop-overlay-title">Drop to upload</p>
<p class="cap-drop-overlay-text">Release anywhere on this page to add the files.</p>
</div>
</div>
</div>
</main>
API reference
DropZone
Prop
Type
Required
Does
accept
string
The same list an input's accept attribute takes: "image/*,.pdf".
maxBytes
number
The largest file, in bytes.
maxFiles
number
The most files taken at once. A zone without multiple takes one.
multiple
boolean
name
string
The input's name, so a form posts the accepted files.
disabled
boolean
scope
"zone" | "page"
"page": a drag of files anywhere over the window is taken, with a full-window panel.
paste
boolean
Files pasted from the clipboard are taken too.
title
ReactNode
The idle title ("Drop files here, or browse" by default) and the line of rules under it.
hint
ReactNode
acceptedList
boolean
false: the zone does not list the files it took ("3 files are ready to upload." and the list), because the app shows its own upload queue. Refusals are still listed.
onAccepted
(files: File[], rejected: Rejection[]) => void
Called with the files that passed, and again with the files that did not.
Checks every file, in order. A file is refused for its type first, then its size; the files that pass are counted, and any beyond maxFiles are refused as too many. Nothing is dropped silently: every refusal comes back with a sentence that names the file.
acceptedText
(files: readonly FileLike[]): string
The words for what was taken: "photo.jpg is ready to upload", "3 files are ready to upload".
rejectedLead
(count: number): string
"1 file was not added", "3 files were not added".
dragHasFiles
(e: Pick<DragEvent, "dataTransfer">): boolean
True while the pointer carries files (and not a dragged link or a selection of text).
Checks files against the zone's rules, shows the result, puts the accepted files in the input, and tells the page with cap-drop-accepted and cap-drop-rejected. Returns the result.
attachDropZone
(zone: HTMLElement): () => void
Attaches one zone. Returns a function that detaches it.
enhance
(root?: ParentNode): () => void
Attaches to every [data-cap="drop-zone"] under root not yet attached. Returns a function that detaches them all.
CSS variables
Variable
Default
--cap-drop-edge
var(--line-strong)
Parts and data attributes
Class
Is
.cap-drop
the root
.cap-drop-browse
a part
.cap-drop-file-size
a part
.cap-drop-files
a part
.cap-drop-hint
a part
.cap-drop-icon
a part
.cap-drop-idle
a part
.cap-drop-input
a part
.cap-drop-label
a part
.cap-drop-lead
a part
.cap-drop-over
a part
.cap-drop-overlay
a part
.cap-drop-overlay-text
a part
.cap-drop-overlay-title
a part
.cap-drop-rejections
a part
.cap-drop-status
a part
.cap-drop-title
a part
Attribute
Values
data-accepted-list
off
data-scope
page
data-state
overrejected
data-tone
crit
State
Read from
:disabled
the platform
:empty
the platform
:focus-visible
the platform
:hover
the platform
Accessibility
Key
Does
Tab, Shift Tab
Moves to the zone (the input) and past it; the zone is one stop
Enter, Space on the focused zone
Opens the file picker
Ctrl V, Cmd V (with data-paste)
Takes files from the clipboard
Dropping is a pointer gesture; the picker is its keyboard equivalent and goes through the same check.
The control is a native file input. Its name is the title ("Drop files here, or browse"; "Drop to upload" while over), its description the line of rules ("Images and PDF, up to 5 MB each, up to 4 at a time.").
Refusals are role="alert", results role="status". The page-mode panel is aria-hidden: it repeats words the zone already carries, and a drag is not something a screen reader user does.
The idle edge reaches 3:1 against the page; the hint is --muted at 4.5:1 and, while over, --text on the tint.
Hit area: the whole zone, at least three controls high; density moves it.
Forced colors: the edge is CanvasText, over is Highlight, the refusal box keeps its border.
Reduced motion: the edge and tint change without easing.