Sortable icon indicating copy to clipboard operation
Sortable copied to clipboard

[bug] Can't cancel swap once an item has been hovered over

Open yjukaku opened this issue 4 years ago • 12 comments

Describe the bug

When using the Swap plugin, it's impossible to cancel a swap once the swap threshold has been met for an item. You can't drag the item back to its original place to prevent a swap. This happens with or without the revertOnSpill: true option.

To Reproduce Steps to reproduce the behavior:

  1. Go to https://sortablejs.github.io/Sortable/#swap
  2. Drag "Item 1" to hover over "Item 2", triggering Item 2 to get highlighted. Don't drop "Item 1", but instead try to prevent a swap by moving Item 1 back to its original place.
  3. See: It's not possible to prevent a swap.

Expected behavior

Dragging Item 1 back to its original place, or off of the list, should deactivate the swap.

Information

Sortable.version == 1.10.2

I didn't include a code sandbox since it's visible with Sortable.js's own Github site.

Thank you so much for your work on this library!

yjukaku avatar Jul 15 '20 13:07 yjukaku

+1

wangdanting avatar Aug 03 '20 12:08 wangdanting

I agree that your description is how it intuitively should work.

Accepting PR's!

waynevanson avatar Aug 31 '20 23:08 waynevanson

hi everyone! i have the exact same problem :) any news on this one ?

@yjukaku did you find any workaround ?

CaptainYouz avatar Oct 27 '20 13:10 CaptainYouz

I did not.

yjukaku avatar Oct 27 '20 13:10 yjukaku

I've made a fix here: https://github.com/JoakimFFCG/sortablejs/commit/90c4f894b88a6b8b89751f0eeb77333fd6111485#diff-b4ffb7cc6e458fc5b1fca6d2ee32068db651d86a4b1bf5df9e411bcb10d2be40

Here is a demo: https://jsbin.com/zefoloboyi/edit?html,js,output

There have been a lot of changes in the master branch since 1.10.2 and when I compiled the source in the master branch myself, the swap plugin appeared to be broken (as in, the swap option didn't alter the behaviour at all; items were sorted normally). So because I didn't have time to fix that as well, I based this fix on the 1.10.2 release tag. But, because there isn't any 1.10.X branch to merge this to, that means I can't make a PR, @waynevanson

Problem details The cause of this problem was that all logic that determines what other element to swap with were inside the dragOverValid event function. However, that event is only fired when hovering over another swappable element. I solved it by moving some logic to the dragOver event instead.

JoakimFFCG avatar Dec 01 '20 09:12 JoakimFFCG

Any news on that?

Danieliverant avatar Apr 01 '21 10:04 Danieliverant

any updates?

oleksiisolomko avatar May 13 '21 18:05 oleksiisolomko

Got the same problem here, any updates on the great fix of @JoakimFFCG ? :)

robinpoort avatar Jul 13 '21 09:07 robinpoort

Is this out of progress?

wChenonly avatar Sep 16 '22 06:09 wChenonly

@wChenonly I made a PR that seems to fix the issue: #2164 Probably needs a little bit more work; just waiting for a response from maintainers or anybody that sees an issue with it.

kishtra avatar Sep 16 '22 14:09 kishtra

Any updates about this issue?

jambortamas avatar Oct 22 '22 17:10 jambortamas

Are there any more updates for this? The issue still persists in version 1.15.2.

joelacus avatar Jul 12 '24 16:07 joelacus