Skip to content

Commit 0e5183f

Browse files
authored
fix(tooltip): fix for off (#1045)
1 parent d177f47 commit 0e5183f

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/components/tooltip/tooltip.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const Tooltip = props => {
4646
}, [toggle]);
4747

4848
const isControlled = !isNil(props.isOpen);
49-
const tooltipIsOpen = (isControlled ? props.isOpen : isOpen) && !props.off;
49+
const tooltipIsOpen = isControlled ? props.isOpen : isOpen;
5050
const id = useFieldId(props.id, sequentialId);
5151

5252
const { onClose } = props;
@@ -121,6 +121,20 @@ const Tooltip = props => {
121121
[closeAfter, onBlur, onMouseLeave, handleClose]
122122
);
123123

124+
React.useEffect(() => {
125+
// if tooltip was open, and then component
126+
// updated to be off, we should close the tooltip
127+
if (isOpen && props.off) {
128+
if (closeAfter) {
129+
leaveTimer.current = setTimeout(() => {
130+
handleClose();
131+
}, closeAfter);
132+
} else {
133+
handleClose();
134+
}
135+
}
136+
}, [props.off, closeAfter, handleClose, toggle, isOpen]);
137+
124138
const childrenProps = {
125139
'aria-describedby': tooltipIsOpen ? id : null,
126140
// for seo and accessibility, we add the tooltip's title

src/components/tooltip/tooltip.story.js

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ storiesOf('Components|Tooltips', module)
7474
>
7575
<p>With ui kit button</p>
7676
<Tooltip
77+
off={boolean('off', false)}
7778
title={label}
7879
closeAfter={closeAfter}
7980
placement={placement}

0 commit comments

Comments
 (0)