From 45694a9929fcdcc1983d7988f162c6ab80022432 Mon Sep 17 00:00:00 2001 From: Danko Kozar Date: Tue, 5 Apr 2016 09:19:35 +0100 Subject: [PATCH] Fix for touchscreen laptops: input could be switched between mouse and touch --- lib/DraggableCore.es6 | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/DraggableCore.es6 b/lib/DraggableCore.es6 index d82ae3b9..7f0a096a 100644 --- a/lib/DraggableCore.es6 +++ b/lib/DraggableCore.es6 @@ -392,6 +392,18 @@ export default class DraggableCore extends React.Component { this.props.onDrag(e, coreEvent); }; + onMouseDown: EventHandler = (e) => { + dragEventFor = eventsFor.mouse; // on touchscreen laptops we could switch back to mouse + + return this.handleDragStart(e); + }; + + onMouseUp: EventHandler = (e) => { + dragEventFor = eventsFor.mouse; + + return this.handleDragStop(e); + }; + // Same as onMouseDown (start drag), but now consider this a touch device. onTouchStart: EventHandler = (e) => { // We're on a touch device now, so change the event handlers @@ -415,9 +427,9 @@ export default class DraggableCore extends React.Component { // Note: mouseMove handler is attached to document so it will still function // when the user drags quickly and leaves the bounds of the element. - onMouseDown: this.handleDragStart, + onMouseDown: this.onMouseDown, onTouchStart: this.onTouchStart, - onMouseUp: this.handleDragStop, + onMouseUp: this.onMouseUp, onTouchEnd: this.onTouchEnd }); }