Skip to content

Commit 4225197

Browse files
authored
Merge pull request #1269 from janpaepke/fix/clickable-mouseover-listener-not-attached
fix: keep clickable tooltips open while pointer moves to body
2 parents c519e94 + 65f0451 commit 4225197

3 files changed

Lines changed: 11 additions & 2 deletions

File tree

src/components/Tooltip/Tooltip.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ const Tooltip = ({
452452
lastFloatPosition,
453453
openEvents,
454454
openOnClick,
455+
rendered,
455456
setActiveAnchor,
456457
show,
457458
tooltipHideDelayTimerRef,

src/components/Tooltip/use-tooltip-events.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const useTooltipEvents = ({
3636
lastFloatPosition,
3737
openEvents,
3838
openOnClick,
39+
rendered,
3940
setActiveAnchor,
4041
show,
4142
tooltipHideDelayTimerRef,
@@ -62,6 +63,7 @@ const useTooltipEvents = ({
6263
lastFloatPosition: RefObject<IPosition | null>
6364
openEvents?: AnchorOpenEvents
6465
openOnClick: boolean
66+
rendered: boolean
6567
setActiveAnchor: (anchor: HTMLElement | null) => void
6668
show: boolean
6769
tooltipHideDelayTimerRef: RefObject<NodeJS.Timeout | null>
@@ -447,8 +449,10 @@ const useTooltipEvents = ({
447449
debouncedShow.cancel()
448450
debouncedHide.cancel()
449451
}
452+
// `rendered` needs to be a dependency because `tooltipRef` becomes stale when the
453+
// tooltip is removed from / added to the DOM.
450454
// eslint-disable-next-line react-hooks/exhaustive-deps
451-
}, [actualOpenEvents, actualCloseEvents, float, clickable])
455+
}, [actualOpenEvents, actualCloseEvents, float, clickable, rendered])
452456

453457
// --- Effect 2: Global close events + auto-update ---
454458
// Re-runs when the global close config changes, or when the active anchor changes

src/test/tooltip-interaction-behavior.spec.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,12 @@ describe('tooltip interaction behavior', () => {
124124

125125
unhoverAnchor(anchor, 0)
126126
fireEvent.mouseEnter(tooltip)
127+
advanceTimers(150) // past clickable's 100ms hide-delay so the close timer fires
127128
await flushMicrotasks()
128-
expect(screen.getByRole('tooltip')).toBeInTheDocument()
129+
130+
const elem = screen.getByRole('tooltip')
131+
expect(elem).toBeInTheDocument()
132+
expect(elem).toHaveClass('react-tooltip__show')
129133

130134
fireEvent.mouseLeave(tooltip)
131135
await flushMicrotasks()

0 commit comments

Comments
 (0)