Skip to content

Commit

Permalink
Check tooltip clicks to see if a, button tag for closeOnClick
Browse files Browse the repository at this point in the history
  • Loading branch information
kylesuss committed Jun 18, 2019
1 parent 53e807a commit e003439
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/components/tooltip/WithTooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ const TargetSvgContainer = styled.g`
cursor: ${props => (props.mode === 'hover' ? 'default' : 'pointer')};
`;

const isDescendantOfAction = element => {
const { parentElement } = element;

if (parentElement.tagName === 'BODY') {
return false;
}

if (parentElement.tagName === 'A' || parentElement.tagName === 'BUTTON') {
return true;
}

return isDescendantOfAction(parentElement);
};

function WithTooltip({
svg,
trigger,
Expand All @@ -30,8 +44,8 @@ function WithTooltip({
const Container = svg ? TargetSvgContainer : TargetContainer;
const [isTooltipShown, setTooltipShown] = useState(startOpen);
const toggleTooltipShown = () => setTooltipShown(!isTooltipShown);
const closeTooltipOnClick = () => {
if (!closeOnClick) {
const closeTooltipOnClick = event => {
if (!closeOnClick || !isDescendantOfAction(event.target)) {
return;
}

Expand Down

0 comments on commit e003439

Please sign in to comment.