Skip to content

Commit 45694a9

Browse files
committed
Fix for touchscreen laptops: input could be switched between mouse and touch
1 parent dcc744f commit 45694a9

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lib/DraggableCore.es6

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,18 @@ export default class DraggableCore extends React.Component {
392392
this.props.onDrag(e, coreEvent);
393393
};
394394

395+
onMouseDown: EventHandler = (e) => {
396+
dragEventFor = eventsFor.mouse; // on touchscreen laptops we could switch back to mouse
397+
398+
return this.handleDragStart(e);
399+
};
400+
401+
onMouseUp: EventHandler = (e) => {
402+
dragEventFor = eventsFor.mouse;
403+
404+
return this.handleDragStop(e);
405+
};
406+
395407
// Same as onMouseDown (start drag), but now consider this a touch device.
396408
onTouchStart: EventHandler = (e) => {
397409
// We're on a touch device now, so change the event handlers
@@ -415,9 +427,9 @@ export default class DraggableCore extends React.Component {
415427

416428
// Note: mouseMove handler is attached to document so it will still function
417429
// when the user drags quickly and leaves the bounds of the element.
418-
onMouseDown: this.handleDragStart,
430+
onMouseDown: this.onMouseDown,
419431
onTouchStart: this.onTouchStart,
420-
onMouseUp: this.handleDragStop,
432+
onMouseUp: this.onMouseUp,
421433
onTouchEnd: this.onTouchEnd
422434
});
423435
}

0 commit comments

Comments
 (0)