Open
Description
Provide a general summary of the feature here
I use DropZone in a form, and would like to have an easy way to set the associated input's files
property. Currently I have to construct my own FileList
, but the original dataTransfer
is right there, just discarded:
react-spectrum/packages/@react-aria/dnd/src/useDrop.ts
Lines 253 to 267 in 3691c7f
🤔 Expected Behavior?
I wish I could just do this:
<DropZone
onDrop={(event) => {
ok(inputRef.current);
inputRef.current.files = event.dataTransfer.files;
}}
>
<FileTrigger
ref={inputRef}
allowsMultiple
>
<Button>Select files</Button>
</FileTrigger>
<span>Drop files here</span>
</DropZone>
😯 Current Behavior
Currently I have to do this:
<DropZone
onDrop={async (event) => {
const dataTransfer = new DataTransfer();
const files = await Promise.all(
event.items
.filter((x) => x.kind === 'file')
.map(async (x) => x.getFile()),
);
for (const file of files) dataTransfer.items.add(file);
ok(inputRef.current);
inputRef.current.files = dataTransfer.files;
}}
>
<FileTrigger
ref={inputRef}
allowsMultiple
>
<Button>Select files</Button>
</FileTrigger>
<span>Drop files here</span>
</DropZone>