Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

Commit 539c032

Browse files
danielkaxistripleWdotcomvictoringvarsson
authored andcommitted
fix(tooltip): use pointerdown event for touch
Using pointerdown event instead of click and toggle only if pointerType is not `mouse` Co-authored-by: Mauricio Espinoza <Mauricio.Espinoza@axis.com> Co-authored-by: Victor Ingvarsson <Victor.Ingvarsson@axis.com>
1 parent 38c7d2d commit 539c032

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

packages/core/src/Tooltip/index.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,18 @@ export const Tooltip: FC<TooltipProps | ExpandedTooltipProps> = ({
265265
// If tooltip should be shown
266266
const visible = visibleByClick || debouncedVisible
267267

268-
const toggle = useCallback(() => {
269-
// When using touch instead of mouse, we have to toggle the tooltip
270-
// on "click" instead of "pointerover" and "pointerout"
271-
showByClick(v => !v)
272-
}, [showByClick])
268+
const toggle = useCallback(
269+
(event: PointerEvent) => {
270+
// When using touch instead of mouse, we have to toggle the tooltip
271+
// on "pointerdown" instead of "pointerover" and "pointerout"
272+
if (event.pointerType === 'mouse') {
273+
return
274+
}
275+
276+
showByClick(v => !v)
277+
},
278+
[showByClick]
279+
)
273280

274281
useEffect(() => {
275282
const delayVisible = () => setDebouncedVisible(visibleDelayed)
@@ -287,11 +294,11 @@ export const Tooltip: FC<TooltipProps | ExpandedTooltipProps> = ({
287294
anchorEl.addEventListener('pointerover', showDelayed)
288295
anchorEl.addEventListener('pointerout', hideDelayed)
289296
// Event when using touch
290-
anchorEl.addEventListener('click', toggle)
297+
anchorEl.addEventListener('pointerdown', toggle)
291298
return () => {
292299
anchorEl.removeEventListener('pointerover', showDelayed)
293300
anchorEl.removeEventListener('pointerout', hideDelayed)
294-
anchorEl.removeEventListener('click', toggle)
301+
anchorEl.removeEventListener('pointerdown', toggle)
295302
}
296303
}, [anchorEl, hideDelayed, showDelayed, toggle])
297304

0 commit comments

Comments
 (0)