Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize event.dataTransfer for drag and drop events #2676

Closed
erikbrannstrom opened this issue Dec 8, 2014 · 8 comments
Closed

Normalize event.dataTransfer for drag and drop events #2676

erikbrannstrom opened this issue Dec 8, 2014 · 8 comments

Comments

@erikbrannstrom
Copy link

I'm currently implementing drag-and-drop in a React application where different kinds of data is dragged and dropped. This means I want to check for certain types on the event.dataTransfer object to see if drop should be enabled or not. Basically it looks like this:

onDragOver: function (event) {
    if (event.dataTransfer.types.indexOf('application/x-custom-type') > -1) {
        event.preventDefault();
    }
}

This works fine in Chrome, but less so in Firefox. It turns out that in Firefox the type of DataTransfer.types is DOMStringList, which does not have an indexOf method. According to the latest drafts of the HTML5 specification (W3C, WHATWG), returning an array like Webkit does is correct. Obviously, the fix is easy on my side (check which one of indexOf and contains is available and use that one), but I thought it might be useful to fix this in React instead, since it is at least related to the event system.

I could probably take a stab at this, but I wanted to gauge the interest. Perhaps the DataTransfer object is deemed to be out of scope for the synthetic event handler.

@zpao
Copy link
Member

zpao commented Dec 10, 2014

I think this seems like a pretty reasonable thing to do in React. We fixup other properties. cc @syranide

@syranide
Copy link
Contributor

I'm not overly familiar with all the intricasies fo dragdrop/dataTransfer, but IIRC there's quite a lot that can be normalized/polyfilled and that seems like a worthwhile endeavour to me at least! 👍

@erikbrannstrom
Copy link
Author

Cool! As I said, I can give it a go if you'd like. Basically, what I'm thinking is adding a SyntheticDataTransfer class which implements the defined DataTransfer interface from the specification, plus perhaps a nativeDataTransfer property. All interface properties and calls will return the corresponding property from the native DataTransfer object, except types which will be converted to an array if it is a DOMStringList.

If that sounds good it should be pretty straightforward to implement, though I'm not sure where the tests for this should go?

@gaearon gaearon changed the title Normalize type of DataTransfer.types Normalize event.dataTransfer for drag and drop events Mar 27, 2016
@aweary aweary self-assigned this Sep 19, 2017
@aweary
Copy link
Contributor

aweary commented Sep 19, 2017

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

As of Firefox 52, the DataTransfer.types property returns a frozen array of DOMStrings as per spec, rather than a DOMStringList.

The latest versions of Firefox are spec-compliant. Should we still consider polyfilling this for older versions of Firefox? cc @sophiebits

@sophiebits
Copy link
Collaborator

Seems like we may as well; it should be a simple check. A few percent of users are still on old Firefox.

@aweary
Copy link
Contributor

aweary commented Sep 19, 2017

Sounds good 👍 after launch it would be great if we could address #9301 so there's less ambiguity around what we should/shouldn't polyfill.

@nhunzaker
Copy link
Contributor

It's been almost a year. The new Firefox ESR is 60, and the old one is 52. Is this still worth doing?

@sophiebits
Copy link
Collaborator

Probably not worth it if all current browsers are fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants