Skip to content

Drag and Drop events not firing #2329

Closed
@grofit

Description

@grofit

So I followed the basic use case: https://github.com/atom/electron/blob/master/docs/api/file-object.md

However for some reason none of those events fire, I have tried applying them to a containing div, an empty div, the document, the body. The events are never fired (I put a console.log as first line in all of them).

Is there anything special you have to do other than just get an DOM element and listen for those events?

I am running version 0.30.0 on windows 8.1.

Activity

hokein

hokein commented on Jul 24, 2015

@hokein
Contributor

The default_app in Electron is a good sample for usage of File object, could you refer to it? It maybe helpful for you.

grofit

grofit commented on Jul 24, 2015

@grofit
Author

its same code, but will give it a go in isolation and see if it has same issues.

grofit

grofit commented on Jul 25, 2015

@grofit
Author

Well the default app seems to work, which baffles me as I dont know how I do not get events fired yet I am using exactly the same code, the only differences are:

  • The code is located within a view model not within the index.html directrly
  • The element has a different id

Here is the basic usage:

this.Setup = function() {
        console.log("SETUP");
        var handler = document.getElementById("some-container");

        handler.ondragover = function () {
            console.log("DRAGGING");
            return false;
        };
        handler.ondragleave = handler.ondragend = function () {
            console.log("NOT DRAGGING");
            return false;
        };

        handler.ondrop = function (e) {
            console.log("DROPPING");
            e.preventDefault();
            var file = e.dataTransfer.files[0];
            console.log('File you dragged here is', file.path);
            return false;
        };
    }

Now I see the SETUP output in the console so I know it has started it, but there is never any output for DRAGGING, NOT DRAGGING or DROPPING when trying to drag and drop a file over the element.

zcbenz

zcbenz commented on Jul 28, 2015

@zcbenz
Contributor

@grofit Can you give a full example? Also the best way to determine whether it is a bug of Electron is to test your code in Chrome browser directly.

grofit

grofit commented on Jul 28, 2015

@grofit
Author

Well the odd thing is it works now, but I have not changed anything related to it, other than restarting the computer. So I don't know what caused it, and it worries me slightly that it magically started working.

Now I have a new issue where drag and drop events fire on child elements making it a massive event mess, but thats not related to this issue. So you can close this now.

grofit

grofit commented on Jul 28, 2015

@grofit
Author

HEY!

So it ended up happening again after a refactor and I compared what was different and it turns out that this is what was causing it (I think).

http://stackoverflow.com/questions/21339924/drop-event-not-firing-in-chrome

So it seems that you need to preventDefault on dragging events or it just seems to ignore drop events.

Only wanted to post it here incase anyone else had the seemingly random issue.

elicore

elicore commented on Nov 10, 2015

@elicore

I'm getting something similar. Tried copying the default_app code and it didn't work, then I tried the default_app itself and I can't drag anything there either. The same index.html file I'm using with the default_app code works well when opened in Chrome.

Using Electron 0.34.0 on Windows 10.

Lokua

Lokua commented on Nov 17, 2015

@Lokua

Same thing here.
Electron 0.35.0
Windows 10

HenryVonfire

HenryVonfire commented on Feb 19, 2016

@HenryVonfire

It happens to me too in windows 10 but the same application (a simple drag and drop) works fine in Linux.

jkudish

jkudish commented on Mar 4, 2016

@jkudish

Having the same problem on Windows 10 as well. Dropping a file doesn't work.

mihaipanait

mihaipanait commented on Jun 3, 2016

@mihaipanait

I get the same icon indicating the dropping isn't allowed, but only when i run the npm command (to start the electron app) inside an elevated cmd prompt on windows. If i don't run it as admin, then drag and drop works fine. It might be related to this:
https://blogs.msdn.microsoft.com/patricka/2010/01/28/q-why-doesnt-drag-and-drop-work-when-my-application-is-running-elevated-a-mandatory-integrity-control-and-uipi/

kerryChen95

kerryChen95 commented on Oct 19, 2016

@kerryChen95

Similar problem on Windows10/Electron1.4.1, I have cancelled dragover and dragenter events, drop event not fire, dragend event fire. But the same code works on Chrome53.

voodle-automaton

voodle-automaton commented on Dec 5, 2016

@voodle-automaton

So has anyone gotten Windows 10 Electron apps to accept dragged files?

Armaldio

Armaldio commented on Dec 5, 2016

@Armaldio
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jkudish@zcbenz@grofit@kerryChen95@hokein

        Issue actions

          Drag and Drop events not firing · Issue #2329 · electron/electron