Skip to content
This repository has been archived by the owner on Sep 1, 2020. It is now read-only.

Commit

Permalink
Remove e.preventDefault from handleTouchEnd (#102)
Browse files Browse the repository at this point in the history
* Remove e.preventDefault from handleTouchEnd

As far as I'm aware, this isn't needed. Fixes #98.

* Touch handled for mobile, Mobile view on examples

* Remove static from touchHandled

* Move inside lambda function

* Expand setTimeout

* Update ContextMenuTrigger.js

* Set touchHandled = false

* Remove trailing spaces
  • Loading branch information
danbovey authored and vkbansal committed Apr 28, 2017
1 parent d6fd507 commit 646865d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>React ContextMenu</title>
<link rel="stylesheet" href="https://unpkg.com/purecss@0.6.2/build/pure-min.css" integrity="sha384-UQiGfs9ICog+LwheBSRCt1o5cbyKIHbwjWscjemyBMT9YCUMZffs6UqUTd0hObXD" crossorigin="anonymous">
<link rel="stylesheet" href="./react-contextmenu.css">
Expand Down
12 changes: 10 additions & 2 deletions src/ContextMenuTrigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default class ContextMenuTrigger extends Component {
renderTag: 'div'
};

touchHandled = false;

handleMouseDown = (event) => {
if (this.props.holdToDisplay >= 0 && event.button === 0) {
Expand All @@ -47,18 +48,25 @@ export default class ContextMenuTrigger extends Component {
}

handleTouchstart = (event) => {
this.touchHandled = false;

if (this.props.holdToDisplay >= 0) {
event.persist();

this.touchstartTimeoutId = setTimeout(
() => this.handleContextClick(event),
() => {
this.handleContextClick(event);
this.touchHandled = true;
},
this.props.holdToDisplay
);
}
}

handleTouchEnd = (event) => {
event.preventDefault();
if (this.touchHandled) {
event.preventDefault();
}
clearTimeout(this.touchstartTimeoutId);
}

Expand Down

0 comments on commit 646865d

Please sign in to comment.