dnd-kit icon indicating copy to clipboard operation
dnd-kit copied to clipboard

[Sortable] Swapping strategy always swaps with the initial position

Open rsdrsd opened this issue 2 years ago • 2 comments

First of all, many thanks for the great library. Most possibilities are already covered. However there's still a situation I can't get my head around. Let me try to explain.

The current swapping strategy always swaps with the initial position (the position where dragging started). I was wondering if it's possible to swap with the current position?

So imagine I have the following situation:

A B C
D E F
G

In the current situation, if I drag A to G the result will be:

G B C
D E F
A

But what I am looking for is that the result becomes:

D B C
G E F
A

Is this possible with the current swapping strategy?

rsdrsd avatar Apr 09 '22 12:04 rsdrsd

Have you tried updating the order of the items in onDragOver?

clauderic avatar Apr 14 '22 01:04 clauderic

Sorry for my late reply. I was on a holiday. I'd forgotten to mention the example I was talking about. I'ts the Sortable -> Grid -> Swappable example.

https://5fc05e08a4a65d0021ae0bf2-ipdskkittb.chromatic.com/?path=/story/presets-sortable-grid--swappable

rsdrsd avatar May 02 '22 18:05 rsdrsd