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

Commit

Permalink
Fixes #105: properly call mousedown, mouseup, touchstart, touchend, m…
Browse files Browse the repository at this point in the history
…ouseout and contextmenu event handlers if they're specified.
  • Loading branch information
julienw committed May 11, 2017
1 parent a45963e commit 3db73bd
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/ContextMenuTrigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,21 @@ export default class ContextMenuTrigger extends Component {
this.props.holdToDisplay
);
}
callIfExists(this.props.attributes.onMouseDown, event);
}

handleMouseUp = (event) => {
if (event.button === 0) {
clearTimeout(this.mouseDownTimeoutId);
}
callIfExists(this.props.attributes.onMouseUp, event);
}

handleMouseOut = (event) => {
if (event.button === 0) {
clearTimeout(this.mouseDownTimeoutId);
}
callIfExists(this.props.attributes.onMouseOut, event);
}

handleTouchstart = (event) => {
Expand All @@ -61,13 +70,20 @@ export default class ContextMenuTrigger extends Component {
this.props.holdToDisplay
);
}
callIfExists(this.props.attributes.onTouchStart, event);
}

handleTouchEnd = (event) => {
if (this.touchHandled) {
event.preventDefault();
}
clearTimeout(this.touchstartTimeoutId);
callIfExists(this.props.attributes.onTouchEnd, event);
}

handleContextMenu = (event) => {
this.handleContextClick(event);
callIfExists(this.props.attributes.onContextMenu, event);
}

handleContextClick = (event) => {
Expand Down Expand Up @@ -97,12 +113,12 @@ export default class ContextMenuTrigger extends Component {
const { renderTag, attributes, children } = this.props;
const newAttrs = assign({}, attributes, {
className: cx(cssClasses.menuWrapper, attributes.className),
onContextMenu: this.handleContextClick,
onContextMenu: this.handleContextMenu,
onMouseDown: this.handleMouseDown,
onMouseUp: this.handleMouseUp,
onTouchStart: this.handleTouchstart,
onTouchEnd: this.handleTouchEnd,
onMouseOut: this.handleMouseUp,
onMouseOut: this.handleMouseOut,
ref: this.elemRef
});

Expand Down

0 comments on commit 3db73bd

Please sign in to comment.