Skip to content

Commit

Permalink
fix(Tooltip): prevent right click from triggering tooltip (#7434)
Browse files Browse the repository at this point in the history
* fix(Tooltip): prevent right click from triggering interactive tooltip

* refactor(Tooltip): clean up conditional statement

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
emyarod and kodiakhq[bot] authored Dec 15, 2020
1 parent a376747 commit 68e2974
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions packages/react/src/components/Tooltip/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,20 +371,24 @@ class Tooltip extends Component {
click: 'click',
}[evt.type];
const hadContextMenu = this._hasContextMenu;
this._hasContextMenu = evt.type === 'contextmenu';
if (evt.type === 'click' || evt.type === 'contextmenu') {
this._hasContextMenu = evt.type === 'contextmenu';
}

if (this._hasContextMenu) {
this._handleUserInputOpenClose(evt, { open: false });
return;
}

if (state === 'click') {
evt.stopPropagation();
evt.preventDefault();
const shouldOpen = this.isControlled
? !this.props.open
: !this.state.open;
this._handleUserInputOpenClose(evt, { open: shouldOpen });
} else if (
state &&
(state !== 'out' || !hadContextMenu) &&
this._debouncedHandleFocus
) {
this._debouncedHandleFocus(state, evt);
} else if (state && (state !== 'out' || !hadContextMenu)) {
this?._debouncedHandleFocus(state, evt);
}
};

Expand Down Expand Up @@ -470,6 +474,7 @@ class Tooltip extends Component {
role: 'button',
tabIndex: tabIndex,
onClick: this.handleMouse,
onContextMenu: this.handleMouse,
onKeyDown: this.handleKeyPress,
onMouseOver: this.handleMouse,
onMouseOut: this.handleMouse,
Expand Down

0 comments on commit 68e2974

Please sign in to comment.