Skip to content

Commit ec86e8a

Browse files
committed
Replicated pull request fix for touch events
react-grid-layout#545
1 parent 72a7660 commit ec86e8a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/DraggableCore.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ export default class DraggableCore extends React.Component<DraggableCoreProps, D
242242
// https://developers.google.com/web/updates/2017/01/scrolling-intervention
243243
const thisNode = this.findDOMNode();
244244
if (thisNode) {
245+
addEvent(thisNode, eventsFor.mouse.start, this.onMouseDown, {passive: false});
245246
addEvent(thisNode, eventsFor.touch.start, this.onTouchStart, {passive: false});
246247
}
247248
}
@@ -257,6 +258,7 @@ export default class DraggableCore extends React.Component<DraggableCoreProps, D
257258
removeEvent(ownerDocument, eventsFor.touch.move, this.handleDrag);
258259
removeEvent(ownerDocument, eventsFor.mouse.stop, this.handleDragStop);
259260
removeEvent(ownerDocument, eventsFor.touch.stop, this.handleDragStop);
261+
removeEvent(thisNode, eventsFor.mouse.start, this.onMouseDown, {passive: false});
260262
removeEvent(thisNode, eventsFor.touch.start, this.onTouchStart, {passive: false});
261263
if (this.props.enableUserSelectHack) removeUserSelectStyles(ownerDocument);
262264
}
@@ -446,7 +448,7 @@ export default class DraggableCore extends React.Component<DraggableCoreProps, D
446448
return React.cloneElement(React.Children.only(this.props.children), {
447449
// Note: mouseMove handler is attached to document so it will still function
448450
// when the user drags quickly and leaves the bounds of the element.
449-
onMouseDown: this.onMouseDown,
451+
// onMouseDown is added on `componentDidMount` so the click can be cancelled
450452
onMouseUp: this.onMouseUp,
451453
// onTouchStart is added on `componentDidMount` so they can be added with
452454
// {passive: false}, which allows it to cancel. See

0 commit comments

Comments
 (0)