Skip to content

Commit 763fd33

Browse files
b-ryuClaudéric Demers
authored and
Claudéric Demers
committed
fix: pass isKeySorting to onSortOver and updateBeforeSortStart handler props (#531)
1 parent 3808437 commit 763fd33

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ There are already a number of great Drag & Drop libraries out there (for instanc
106106
| pressThreshold | Number | `5` | Number of pixels of movement to tolerate before ignoring a press event. |
107107
| distance | Number | `0` | If you'd like elements to only become sortable after being dragged a certain number of pixels. Cannot be used in conjunction with the `pressDelay` prop. |
108108
| shouldCancelStart | Function | [Function](https://github.com/clauderic/react-sortable-hoc/blob/master/src/SortableContainer/index.js#L48) | This function is invoked before sorting begins, and can be used to programatically cancel sorting before it begins. By default, it will cancel sorting if the event target is either an `input`, `textarea`, `select` or `option`. |
109-
| updateBeforeSortStart | Function | | This function is invoked before sorting begins. It can return a promise, allowing you to run asynchronous updates (such as `setState`) before sorting begins. `function({node, index, collection}, event)` |
109+
| updateBeforeSortStart | Function | | This function is invoked before sorting begins. It can return a promise, allowing you to run asynchronous updates (such as `setState`) before sorting begins. `function({node, index, collection, isKeySorting}, event)` |
110110
| onSortStart | Function | | Callback that is invoked when sorting begins. `function({node, index, collection, isKeySorting}, event)` |
111111
| onSortMove | Function | | Callback that is invoked during sorting as the cursor moves. `function(event)` |
112-
| onSortOver | Function | | Callback that is invoked when moving over an item. `function({index, oldIndex, newIndex, collection}, e)` |
112+
| onSortOver | Function | | Callback that is invoked when moving over an item. `function({index, oldIndex, newIndex, collection, isKeySorting}, e)` |
113113
| onSortEnd | Function | | Callback that is invoked when sorting ends. `function({oldIndex, newIndex, collection, isKeySorting}, e)` |
114114
| useDragHandle | Boolean | `false` | If you're using the `SortableHandle` HOC, set this to `true` |
115115
| useWindowAsScrollContainer | Boolean | `false` | If you want, you can set the `window` as the scrolling container |

src/SortableContainer/index.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,10 @@ export default function sortableContainer(
242242

243243
try {
244244
const {index} = node.sortableInfo;
245-
await updateBeforeSortStart({collection, index, node}, event);
245+
await updateBeforeSortStart(
246+
{collection, index, node, isKeySorting},
247+
event,
248+
);
246249
} finally {
247250
this._awaitingUpdateBeforeSortStart = false;
248251
}
@@ -801,12 +804,14 @@ export default function sortableContainer(
801804
this.newIndex = prevIndex;
802805
}
803806

804-
if (onSortOver && this.newIndex !== prevIndex) {
807+
const oldIndex = isKeySorting ? this.prevIndex : prevIndex;
808+
if (onSortOver && this.newIndex !== oldIndex) {
805809
onSortOver({
806810
collection: this.manager.active.collection,
807811
index: this.index,
808812
newIndex: this.newIndex,
809-
oldIndex: prevIndex,
813+
oldIndex,
814+
isKeySorting,
810815
});
811816
}
812817
}

types/index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface SortOver {
1616
oldIndex: number;
1717
newIndex: number;
1818
collection: Offset;
19+
isKeySorting: boolean;
1920
}
2021

2122
export interface SortEnd {

0 commit comments

Comments
 (0)