KANTO DS v1.12.0
Customise

Theme

Accent

Font

Corners

Density

Text size

Reset to Kanto
Forms

kt-drag-drop

GitHub Copy link

A file drop zone. Takes a drop or a click, lists what was picked, and lets each entry be removed.

Preview

A file drop zone. Takes a drop or a click, lists what was picked, and lets each entry be removed.

<kt-drag-drop accept="image/*" max-size="2097152" recommended-size="800×400px"></kt-drag-drop>zone.addEventListener('kt-files-change', (e) => console.log(e.detail.files)); zone.addEventListener('kt-files-rejected', (e) => { toast.error(e.detail.reason === 'size' ? 'File too large' : 'Unsupported format'); });

The element holds the files and reports them. Uploading is yours — it makes no requests.

In a form

Give it a name and it is a form control: a <form> submits every held file under that name, exactly as <input type="file" multiple> would, so a multipart/form-data post needs no extra code. Without a name it submits nothing, like the native input. required blocks submission until a file is held, and form.reset() empties it.

<form method="post" enctype="multipart/form-data"> <kt-drag-drop name="attachments" required></kt-drag-drop> <kt-button type="submit">Send</kt-button> </form>

Validation

accept on a native input is advisory: the OS dialog filters by it, but a dropped file bypasses it completely. So <kt-drag-drop> re-checks every file itself, by extension (.pdf), by mime prefix (image/*) or by exact type, and fires kt-files-rejected with what it turned away and why.

max-size is in bytes and has no native equivalent at all.

Accessibility

The zone is role="button" with a tab stop and Enter/Space activation, so it can be used without a pointer — a drop zone reachable only by dragging is unusable for anyone who does not drag. Each file's remove button carries the file name in its accessible label, rather than nine identical "Delete" buttons.

API

PropertyAttributeTypeDefault
headingheadingstring'Drag and drop or'
linkTextlink-textstring'browse your files'
recommendedSizerecommended-sizestring''
multiplemultiplebooleantrue
acceptacceptstring''
maxSizemax-sizenumber0 (no limit)
disableddisabledbooleanfalse
namenamestring''
requiredrequiredbooleanfalse

heading rather than title: an element already has a title, and reusing it would drop the prompt into a native tooltip over the whole zone.

GetterReturns
selectedFilesreadonly File[]
MethodDescription
clear()Empties the selection, fires kt-files-change
EventDetail
kt-files-change{ files: File[] } — the full current list
kt-files-rejected{ files: File[], reason: 'type' | 'size' }
PartDescription
baseThe dashed drop zone
listThe list of files