mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 10:21:05 +00:00
feat(file-uploader-drop-container): rework FileUploaderDropContainer
(#1125)
- convert `FileList` to `File[]` to be consistent with `FileUploader` and `FileUploaderButton` - add `files` prop for two-way binding - dispatch instead of forward the `change` event (detail signature: `File[]`)
This commit is contained in:
parent
7586b2a10f
commit
8d3ac75170
4 changed files with 60 additions and 32 deletions
|
@ -1,6 +1,7 @@
|
|||
<script>
|
||||
/**
|
||||
* @event {FileList} add
|
||||
* @event {File[]} add
|
||||
* @event {File[]} change
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -9,13 +10,19 @@
|
|||
*/
|
||||
export let accept = [];
|
||||
|
||||
/**
|
||||
* Obtain a reference to the uploaded files
|
||||
* @type {File[]}
|
||||
*/
|
||||
export let files = [];
|
||||
|
||||
/** Set to `true` to allow multiple files */
|
||||
export let multiple = false;
|
||||
|
||||
/**
|
||||
* Override the default behavior of validating uploaded files
|
||||
* The default behavior does not validate files
|
||||
* @type {(files: FileList) => FileList}
|
||||
* @type {(files: File) => File}
|
||||
*/
|
||||
export let validateFiles = (files) => files;
|
||||
|
||||
|
@ -68,7 +75,9 @@
|
|||
on:drop|preventDefault|stopPropagation="{({ dataTransfer }) => {
|
||||
if (!disabled) {
|
||||
over = false;
|
||||
dispatch('add', validateFiles(dataTransfer.files));
|
||||
files = validateFiles([...dataTransfer.files]);
|
||||
dispatch('add', files);
|
||||
dispatch('change', files);
|
||||
}
|
||||
}}"
|
||||
>
|
||||
|
@ -104,9 +113,10 @@
|
|||
name="{name}"
|
||||
multiple="{multiple}"
|
||||
class:bx--file-input="{true}"
|
||||
on:change
|
||||
on:change="{({ target }) => {
|
||||
dispatch('add', validateFiles(target.files));
|
||||
files = validateFiles([...target.files]);
|
||||
dispatch('add', files);
|
||||
dispatch('change', files);
|
||||
}}"
|
||||
on:click
|
||||
on:click="{({ target }) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue