kt-drag-drop
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.
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.
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
| Property | Attribute | Type | Default |
|---|---|---|---|
heading | heading | string | 'Drag and drop or' |
linkText | link-text | string | 'browse your files' |
recommendedSize | recommended-size | string | '' |
multiple | multiple | boolean | true |
accept | accept | string | '' |
maxSize | max-size | number | 0 (no limit) |
disabled | disabled | boolean | false |
name | name | string | '' |
required | required | boolean | false |
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.
| Getter | Returns |
|---|---|
selectedFiles | readonly File[] |
| Method | Description |
|---|---|
clear() | Empties the selection, fires kt-files-change |
| Event | Detail |
|---|---|
kt-files-change | { files: File[] } — the full current list |
kt-files-rejected | { files: File[], reason: 'type' | 'size' } |
| Part | Description |
|---|---|
base | The dashed drop zone |
list | The list of files |