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-disabling event listener remains attached to document after sort finishes #1937

Open
dancoding opened this issue Sep 29, 2020 · 3 comments

Comments

@dancoding
Copy link

PLEASE READ THE CONTRIBUTION GUIDELINES HERE!

Failure to comply may have your issue automatically closed.

Reproduction

Scenario

https://codesandbox.io/s/green-water-dq651?file=/src/index.js

Steps to Reproduce

Summary of steps if applicable.

  1. Make sure to test in Chrome or Edge. (For reasons I don't understand, the bug does not occur in Firefox.)

  2. Drag the lowest item ("eight") QUICKLY downward and release it.

  3. Click the "Click Me" button. Nothing will happen. (This is the bug.)

  4. Click the "Click Me" button again. This time, clicking the button will trigger an alert as it should.

Describe the bug

Your fix for Issue 1184 has an unintended consequence. In Line 1138, you add an event listener to the document that stops propagation on any click event if the variable "ignoreNextClick" holds the value "true."

In theory, the "ignoreNextClick" variable will get set to "false" the first time the _onDragStart event fires. However, it's possible for this event NEVER TO FIRE if the user drags a sortable item quickly out of the sortable area and releases it. In that case, the event listener is still attached to the document, and the first time the user clicks anything in the DOM, it won't respond.

It took me a couple of hours to figure out that it was Sortable JS causing this problem and not something else in my code. I hope you can spare other developers this pain!

Expected behavior

When I click a button (or anything else) in the DOM after performing a drag-and-drop, it should behave normally. I shouldn't have to click it twice thanks to the "ignoreNextClick" event listener getting left attached to the document. (Remember, this only happens in the circumstances described above, and when "forceFallback" is set to "true.")

Version

package version
sortablejs ^1.10.2-?
@types/sortablejs ^x.x.x-? || N/A

Additional Context

Let me know if anything isn't clear!

  • Dan
@waynevanson
Copy link
Contributor

#1184

@Mihailoff
Copy link

Workaround donmbelembe/vue-dragscroll#61 (comment)

@andrewheumann
Copy link

andrewheumann commented Aug 31, 2024

A related issue: the disableNextClick value persists after a destroy() call, and the associated click listener can still intercept and cancel click events.

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

4 participants