This repository was archived by the owner on Sep 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 378
Remove e.preventDefault from handleTouchEnd #102
Merged
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a9172ad
Remove e.preventDefault from handleTouchEnd
danbovey 25dc953
Touch handled for mobile, Mobile view on examples
danbovey 53b529e
Tested with and without
danbovey c790b46
Remove static from touchHandled
danbovey 5ef5d11
Move inside lambda function
danbovey d05b680
Expand setTimeout
danbovey 8644a29
Update ContextMenuTrigger.js
danbovey c3ea52a
Set touchHandled = false
danbovey cf12311
Remove trailing spaces
danbovey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"> | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ export default class ContextMenuTrigger extends Component { | |
renderTag: 'div' | ||
}; | ||
|
||
static touchHandled = false; | ||
|
||
handleMouseDown = (event) => { | ||
if (this.props.holdToDisplay >= 0 && event.button === 0) { | ||
|
@@ -50,6 +51,8 @@ export default class ContextMenuTrigger extends Component { | |
if (this.props.holdToDisplay >= 0) { | ||
event.persist(); | ||
|
||
this.touchHandled = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -58,7 +61,9 @@ export default class ContextMenuTrigger extends Component { | |
} | ||
|
||
handleTouchEnd = (event) => { | ||
event.preventDefault(); | ||
if (this.touchHandled) { | ||
event.preventDefault(); | ||
} | ||
clearTimeout(this.touchstartTimeoutId); | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 thestatic
keyword and all is fine.