Sortable icon indicating copy to clipboard operation
Sortable copied to clipboard

Click-disabling event listener remains attached to document after sort finishes

Open dancoding opened this issue 5 years ago • 3 comments

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

dancoding avatar Sep 29 '20 02:09 dancoding

#1184

waynevanson avatar Sep 29 '20 08:09 waynevanson

Workaround https://github.com/donmbelembe/vue-dragscroll/issues/61#issuecomment-1058266843

Mihailoff avatar Dec 21 '22 03:12 Mihailoff

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

andrewheumann avatar Aug 31 '24 14:08 andrewheumann