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 5 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
8 changes: 6 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 @@ -52,13 +53,16 @@ export default class ContextMenuTrigger extends Component {

this.touchstartTimeoutId = setTimeout(
() => this.handleContextClick(event),
this.props.holdToDisplay
this.props.holdToDisplay,
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.

Woops, that's still not good I'm afraid.. To be fair the short syntax is easy to get confused by, but it should be expanded to this:

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to, I hate comma separated stuff

Copy link
Collaborator

Choose a reason for hiding this comment

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

But setTimeout takes two args, a callback and then a timeout (this.props.holdToDisplay). The way you fixed it now you left the timeout in the middle of the callback, so that's not gonna work :)

Copy link
Contributor Author

@danbovey danbovey Apr 27, 2017

Choose a reason for hiding this comment

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

Woops, yeah, this is why you should add curly brackets and semicolons as soon as you start doing more than one thing.

);
}
}

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

Expand Down