Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/components/Tooltip/use-tooltip-events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,11 @@ const useTooltipEvents = ({
debouncedHandleShowTooltip(resolveAnchorElementRef.current(event.target))
})
}
if (actualOpenEvents.mouseenter || actualOpenEvents.mouseover || actualOpenEvents.focus) {
addDelegatedListener('touchstart', (event) => {
debouncedHandleShowTooltip(resolveAnchorElementRef.current(event.target))
})
}
if (actualCloseEvents.blur) {
addDelegatedListener('focusout', (event) => {
const targetAnchor = resolveAnchorElementRef.current(event.target)
Expand Down Expand Up @@ -470,6 +475,7 @@ const useTooltipEvents = ({
useEffect(() => {
const handleScrollResize = () => {
handleShowRef.current(false)
clearTimeoutRef(tooltipShowDelayTimerRef)
}

const tooltipScrollParent = tooltipScrollParentRef.current
Expand Down
26 changes: 26 additions & 0 deletions src/test/tooltip-anchor-selection.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,32 @@ describe('tooltip anchor selection', () => {
await waitForTooltipToClose('scroll-resize-test')
})

test('reopens on touch after closing from scroll', async () => {
render(
<>
<span data-tooltip-id="touch-scroll-test">Tap Me</span>
<TooltipController
id="touch-scroll-test"
content="Touch Scroll Test"
globalCloseEvents={{ scroll: true }}
/>
</>,
)

const anchor = screen.getByText('Tap Me')

fireEvent.touchStart(anchor)
await waitForTooltip('touch-scroll-test')
Comment thread
danielbarion marked this conversation as resolved.

fireEvent.scroll(window)
await waitForTooltipToStopShowing('touch-scroll-test')

fireEvent.touchStart(anchor)
await waitFor(() => {
expect(document.getElementById('touch-scroll-test')).not.toHaveClass('react-tooltip__closing')
})
})

test('unmounts cleanly after opening and closing', async () => {
const { unmount } = render(
<>
Expand Down