Skip to content

Commit 640eccd

Browse files
seanogdevowen-m1
authored andcommitted
Add option to only apply delay on touch events (#1482)
1 parent 9fae052 commit 640eccd

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ var sortable = new Sortable(el, {
8484
group: "name", // or { name: "...", pull: [true, false, 'clone', array], put: [true, false, array] }
8585
sort: true, // sorting inside list
8686
delay: 0, // time in milliseconds to define when the sorting should start
87+
delayOnTouchOnly: false, // only delay if user is using touch
8788
touchStartThreshold: 0, // px, how many pixels the point should move before cancelling a delayed drag event
8889
disabled: false, // Disables the sortable if set to true.
8990
store: null, // @see Store
@@ -247,6 +248,13 @@ Demo: https://jsbin.com/zosiwah/edit?js,output
247248
---
248249

249250

251+
#### `delayOnTouchOnly` option
252+
Whether or not the delay should be applied only if the user is using touch (eg. on a mobile device). No delay will be applied in any other case. Defaults to `false`.
253+
254+
255+
---
256+
257+
250258
#### `swapThreshold` option
251259
Percentage of the target that the swap zone will take up, as a float between `0` and `1`.
252260

Sortable.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@
529529
dragoverBubble: false,
530530
dataIdAttr: 'data-id',
531531
delay: 0,
532+
delayOnTouchOnly: false,
532533
touchStartThreshold: parseInt(window.devicePixelRatio, 10) || 1,
533534
forceFallback: false,
534535
fallbackClass: 'sortable-fallback',
@@ -819,7 +820,7 @@
819820
}
820821

821822
// Delay is impossible for native DnD in Edge or IE
822-
if (options.delay && (!this.nativeDraggable || !(Edge || IE11OrLess))) {
823+
if (options.delay && (options.delayOnTouchOnly ? touch : true) && (!this.nativeDraggable || !(Edge || IE11OrLess))) {
823824
// If the user moves the pointer or let go the click or touch
824825
// before the delay has been reached:
825826
// disable the delayed drag

0 commit comments

Comments
 (0)