Skip to content

Commit e003439

Browse files
committed
Check tooltip clicks to see if a, button tag for closeOnClick
1 parent 53e807a commit e003439

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

src/components/tooltip/WithTooltip.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ const TargetSvgContainer = styled.g`
1515
cursor: ${props => (props.mode === 'hover' ? 'default' : 'pointer')};
1616
`;
1717

18+
const isDescendantOfAction = element => {
19+
const { parentElement } = element;
20+
21+
if (parentElement.tagName === 'BODY') {
22+
return false;
23+
}
24+
25+
if (parentElement.tagName === 'A' || parentElement.tagName === 'BUTTON') {
26+
return true;
27+
}
28+
29+
return isDescendantOfAction(parentElement);
30+
};
31+
1832
function WithTooltip({
1933
svg,
2034
trigger,
@@ -30,8 +44,8 @@ function WithTooltip({
3044
const Container = svg ? TargetSvgContainer : TargetContainer;
3145
const [isTooltipShown, setTooltipShown] = useState(startOpen);
3246
const toggleTooltipShown = () => setTooltipShown(!isTooltipShown);
33-
const closeTooltipOnClick = () => {
34-
if (!closeOnClick) {
47+
const closeTooltipOnClick = event => {
48+
if (!closeOnClick || !isDescendantOfAction(event.target)) {
3549
return;
3650
}
3751

0 commit comments

Comments
 (0)