Sortable onBeforeDragStart initialIndex incorrect
- Dominant language
- TypeScript
- Stars
- 17.6k
- Forks
- 924
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 2
Description
After a sortable item has been moved, the `initialIndex` value in `onBeforeDragStart` is incorrect. See [this CodeSandbox](https://codesandbox.io/p/sandbox/dnd-kit-disable-forked-dpshjt).
1. Move item 1 to after item 2. The console says that the `initialIndex` is `0` for both `onBeforeDragStart` and `onDragEnd`.
2. Drag item 1 and release it (without changing the position). The `initialIndex` for `onBeforeDragStart` is `0` and the `initialIndex` for `onDragEnd` is `1`. As this item is now in position `1`, `onBeforeDragStart` is returning the incorrect `initialIndex`.
3. Drag item 1 and release it (without changing the position). Now, the `onBeforeDragStart` has an `initialIndex` of `1`.
The [sortable documentation](https://dndkit.com/concepts/sortable) says that the `initialIndex` is
>The position the item was in when the drag started
Here are the CodeSandbox logs:
```
// Drag item 1 after item 2
{description: 'onBeforeDragStart', initialIndex: 0, index: 0, id: 1, atInitialIndex: 1}
{description: 'onDragEnd', initialIndex: 0, index: 1, id: 1, atInitialIndex: 1}
// Drag and release item 1, keeping it's position the same
{description: 'onBeforeDragStart', initialIndex: 0, index: 1, id: 1, atInitialIndex: 2}
{description: 'onDragEnd', initialIndex: 1, index: 1, id: 1, atInitialIndex: 1}
// Drag and release item 1, keeping it's position the same
{description: 'onBeforeDragStart', initialIndex: 1, index: 1, id: 1, atInitialIndex: 1}
{description: 'onDragEnd', initialIndex: 1, index: 1, id: 1, atInitialIndex: 1}
```
Contributor guide
Assessment
This issue has not been assessed yet.