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

Remove e.preventDefault from handleTouchEnd #102

Merged
merged 9 commits into from
Apr 28, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/[email protected]/build/pure-min.css" integrity="sha384-UQiGfs9ICog+LwheBSRCt1o5cbyKIHbwjWscjemyBMT9YCUMZffs6UqUTd0hObXD" crossorigin="anonymous">
<link rel="stylesheet" href="./react-contextmenu.css">
Expand Down
7 changes: 6 additions & 1 deletion 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'
};

static touchHandled = false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be static but a regular instance property if you address it with this below. i.e. just remove the static keyword and all is fine.


handleMouseDown = (event) => {
if (this.props.holdToDisplay >= 0 && event.button === 0) {
Expand All @@ -50,6 +51,8 @@ export default class ContextMenuTrigger extends Component {
if (this.props.holdToDisplay >= 0) {
event.persist();

this.touchHandled = true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be inside the lambda function at line 57, otherwise it'll always be true not just when the touch actually triggered the "hold-to-display" functionality, and we're back at the point where preventDefault fires every time.


this.touchstartTimeoutId = setTimeout(
() => this.handleContextClick(event),
this.props.holdToDisplay
Expand All @@ -58,7 +61,9 @@ export default class ContextMenuTrigger extends Component {
}

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

Expand Down