ember-native-dom-helpers icon indicating copy to clipboard operation
ember-native-dom-helpers copied to clipboard

`selectFiles` Does Not Support "drop" Event

Open jherdman opened this issue 6 years ago • 9 comments

Ideally I could do something like:

await selectFiles('.my-selector', [
  new Blob(...),
], { eventType: 'drop' });

jherdman avatar Aug 14 '17 15:08 jherdman

@jherdman so that just triggers the drop event right?

webark avatar Aug 14 '17 15:08 webark

I wasn't aware of uploading files via drop had a different event.

cibernox avatar Aug 14 '17 16:08 cibernox

Exactly.

I have this mostly working in a PR, but it seems like changes to support this are breaking the tap helper. I'm not sure why yet.

jherdman avatar Aug 14 '17 16:08 jherdman

I wasn't aware of uploading files via drop had a different event.

Yeah, it's slightly different. https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API/File_drag_and_drop details here. It looks like it may be a bit more work than simply supporting firing the "drop" event (note event.dataTransfer).

jherdman avatar Aug 14 '17 16:08 jherdman

ya. hmm. ok. i might be able to look at that later. might be best to do a whole new helper cause the api is different.

Side Note: what could you "drop" that wouldn't be a file?

webark avatar Aug 14 '17 16:08 webark

If the api can be unified i'd rather have it be an option. If there is some fundamental difference that makes better to add a new helper, I'd suggest dropFiles('.selector', files)

cibernox avatar Aug 14 '17 16:08 cibernox

ya.. it's just the "event.target.files" vs "event.dataTransfer.items", and then it looks like you have to use a "getAsFile" method on each individual item. The api's are so different, that you'd have to write a whole new helper for it even if you abstracted it behind the same name.

webark avatar Aug 14 '17 16:08 webark

Documentation states that DataTransfer objects can't be constructed.

https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer

Can we construct a drop event programmatically that holds files at all?

LevelbossMike avatar Sep 07 '17 11:09 LevelbossMike

@LevelbossMike I'm not very aware of the nuances of drop events, but if DataTransfer can't be created, we might be able to create something that quacks as a DataTransfer object and assign it to the event, similarly to how we pass an array of files instead of a FileList to the change events on file inputs.

cibernox avatar Sep 07 '17 12:09 cibernox