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

'click' gets triggered when element is dropped (mouse only) #103

Open
Samlibardi opened this issue Jul 12, 2018 · 4 comments
Open

'click' gets triggered when element is dropped (mouse only) #103

Samlibardi opened this issue Jul 12, 2018 · 4 comments

Comments

@Samlibardi
Copy link

Samlibardi commented Jul 12, 2018

How to reproduce:

  • Bind a click event to an element in a Slip list
  • Drag the element around
  • Drop it

This happens probably because the mousedown and mouseup events are triggered in the same position in the element.

So far, I've been able to work around this by adding the following:

this.target.node.addEventListener('click',function h(e) {
                            e.stopPropagation(); 
                            e.preventDefault(); 
                            this.removeEventListener(e.type,h,true);
                        },true);

in the onEnd method of the reorder state. This captures the click event and removes itself allowing it to be clicked (see #104 though). It feels very hacky and I don't know how well it behaves. It's been working fine for the time.

@kornelski
Copy link
Owner

click should be stopped by preventDefault on either mousedown or mouseup events. Maybe check handlers for these? I can't check now, but I vaguely remember it was tough to allow both text selection and prevent mouse events.

@Samlibardi
Copy link
Author

Samlibardi commented Jul 12, 2018 via email

@kornelski
Copy link
Owner

Bummer. Preventing in mousedown is not a good option, as it'll prevent text selection. Re-raising may have problems with trusted events too.

So I suppose stopping the click is the way to go.

@Samlibardi
Copy link
Author

Then I suppose adding a dedicated click handler in the Slip constructor is a cleaner solution than what I initially suggested. Returning true allows anchors and buttons to work properly as well. I'll try to apply this in my project and if it works fine I'll post a PR with the changes.

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

No branches or pull requests

2 participants