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

Commit

Permalink
Improve click behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
HaNdTriX committed Nov 15, 2016
1 parent 73fef7b commit 347a9ae
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/ContextMenuTrigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,37 @@ export default class ContextMenuTrigger extends Component {
};


mouseDown = false;

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

this.mouseDown = true;
setTimeout(() => {
if (this.mouseDown) this.handleContextClick(event);
}, this.props.holdToDisplay);
this.mouseDownTimeoutId = setTimeout(
() => this.handleContextClick(event),
this.props.holdToDisplay
);
}
}

handleMouseUp = (event) => {
if (event.button === 0) {
this.mouseDown = false;
clearTimeout(this.mouseDownTimeoutId)
}
}

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

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

handleTouchEnd = (event) => {
event.preventDefault();
this.mouseDown = false;
clearTimeout(this.touchstartTimeoutId)
}

handleContextClick = (event) => {
Expand Down

0 comments on commit 347a9ae

Please sign in to comment.