Skip to content

Commit 06b8d9f

Browse files
SamyPessekiejo
authored andcommitted
Add onSortOver prop to SortableContainer (clauderic#278)
1 parent 590e3fe commit 06b8d9f

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ There are already a number of great Drag & Drop libraries out there (for instanc
105105
| 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`. |
106106
| onSortStart | Function | | Callback that is invoked when sorting begins. `function({node, index, collection}, event)` |
107107
| onSortMove | Function | | Callback that is invoked during sorting as the cursor moves. `function(event)` |
108+
| onSortOver | Function | | Callback that get's invoked when moving over an item. `function({index, oldIndex, newIndex, collection}, e)` |
108109
| onSortEnd | Function | | Callback that is invoked when sorting ends. `function({oldIndex, newIndex, collection}, e)` |
109110
| useDragHandle | Boolean | `false` | If you're using the `SortableHandle` HOC, set this to `true` |
110111
| useWindowAsScrollContainer | Boolean | `false` | If you want, you can set the `window` as the scrolling container |
@@ -156,11 +157,11 @@ const SortableList = SortableContainer(({items}) => {
156157
return (
157158
<ul>
158159
{items.map((value, index) => (
159-
<SortableItem
160+
<SortableItem
160161
key={`item-${index}`}
161162
index={index}
162163
sortIndex={index}
163-
value={value}
164+
value={value}
164165
/>
165166
))}
166167
</ul>

src/SortableContainer/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
6969
contentWindow: PropTypes.any,
7070
onSortStart: PropTypes.func,
7171
onSortMove: PropTypes.func,
72+
onSortOver: PropTypes.func,
7273
onSortEnd: PropTypes.func,
7374
shouldCancelStart: PropTypes.func,
7475
pressDelay: PropTypes.number,
@@ -565,7 +566,7 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
565566
}
566567

567568
animateNodes() {
568-
const {transitionDuration, hideSortableGhost} = this.props;
569+
const {transitionDuration, hideSortableGhost, onSortOver} = this.props;
569570
const nodes = this.manager.getOrderedRefs();
570571
const deltaScroll = {
571572
left: this.scrollContainer.scrollLeft - this.initialScroll.left,
@@ -579,6 +580,7 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
579580
top: (window.pageYOffset - this.initialWindowScroll.top),
580581
left: (window.pageXOffset - this.initialWindowScroll.left),
581582
};
583+
const prevIndex = this.newIndex;
582584
this.newIndex = null;
583585

584586
for (let i = 0, len = nodes.length; i < len; i++) {
@@ -723,6 +725,15 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
723725
if (this.newIndex == null) {
724726
this.newIndex = this.index;
725727
}
728+
729+
if (onSortOver && this.newIndex !== prevIndex) {
730+
onSortOver({
731+
newIndex: this.newIndex,
732+
oldIndex: prevIndex,
733+
index: this.index,
734+
collection: this.manager.active.collection,
735+
});
736+
}
726737
}
727738

728739
autoscroll = () => {

0 commit comments

Comments
 (0)