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

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

Open
yjukaku opened this issue Jul 15, 2020 · 8 comments
Open

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

yjukaku opened this issue Jul 15, 2020 · 8 comments
Labels
enhancement good first issue Swap

Comments

@yjukaku
Copy link

@yjukaku yjukaku commented Jul 15, 2020

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!

@wangdanting
Copy link

@wangdanting wangdanting commented Aug 3, 2020

+1

@waynevanson waynevanson added Swap enhancement labels Aug 31, 2020
@waynevanson
Copy link
Contributor

@waynevanson waynevanson commented Aug 31, 2020

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

Accepting PR's!

@waynevanson waynevanson added status:accepting-pulls good first issue labels Aug 31, 2020
@CaptainYouz
Copy link

@CaptainYouz CaptainYouz commented Oct 27, 2020

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

@yjukaku did you find any workaround ?

@yjukaku
Copy link
Author

@yjukaku yjukaku commented Oct 27, 2020

I did not.

JoakimFFCG added a commit to JoakimFFCG/sortablejs that referenced this issue Nov 30, 2020
JoakimFFCG added a commit to JoakimFFCG/sortablejs that referenced this issue Nov 30, 2020
@JoakimFFCG
Copy link

@JoakimFFCG JoakimFFCG commented Dec 1, 2020

I've made a fix here: JoakimFFCG@90c4f89#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.

@Danieliverant
Copy link

@Danieliverant Danieliverant commented Apr 1, 2021

Any news on that?

@oleksiisolomko
Copy link

@oleksiisolomko oleksiisolomko commented May 13, 2021

any updates?

@robinpoort
Copy link

@robinpoort robinpoort commented Jul 13, 2021

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

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

No branches or pull requests

9 participants