Skip to content

Commit 5471666

Browse files
authored
fix: when onDragInit return false it should stop (#979)
- when `onDragInit` returns `false` then the row or cell dragging shouldn't be allowed - this is similar to previous PR #978
1 parent 8c659c9 commit 5471666

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/slick.interactions.ts

+10-8
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export function Draggable(options: DraggableOption) {
5656

5757
function executeDragCallbackWhenDefined(callback?: (e: DragEvent, dd: DragItem) => boolean | void, evt?: MouseEvent | Touch | TouchEvent, dd?: DragItem) {
5858
if (typeof callback === 'function') {
59-
callback(evt as DragEvent, dd as DragItem);
59+
return callback(evt as DragEvent, dd as DragItem);
6060
}
6161
}
6262

@@ -80,13 +80,15 @@ export function Draggable(options: DraggableOption) {
8080
deltaX = targetEvent.clientX - targetEvent.clientX;
8181
deltaY = targetEvent.clientY - targetEvent.clientY;
8282
originaldd = Object.assign(originaldd, { deltaX, deltaY, startX, startY, target });
83-
executeDragCallbackWhenDefined(onDragInit as (e: DragEvent, dd: DragPosition) => boolean | void, event, originaldd as DragItem);
84-
85-
document.body.addEventListener('mousemove', userMoved);
86-
document.body.addEventListener('touchmove', userMoved);
87-
document.body.addEventListener('mouseup', userReleased);
88-
document.body.addEventListener('touchend', userReleased);
89-
document.body.addEventListener('touchcancel', userReleased);
83+
const result = executeDragCallbackWhenDefined(onDragInit as (e: DragEvent, dd: DragPosition) => boolean | void, event, originaldd as DragItem);
84+
85+
if (result !== false) {
86+
document.body.addEventListener('mousemove', userMoved);
87+
document.body.addEventListener('touchmove', userMoved);
88+
document.body.addEventListener('mouseup', userReleased);
89+
document.body.addEventListener('touchend', userReleased);
90+
document.body.addEventListener('touchcancel', userReleased);
91+
}
9092
}
9193
}
9294

0 commit comments

Comments
 (0)