Skip to content

Commit 54dbcd1

Browse files
committed
fix(TooltipContext): Fix touch scrolling on mobile. Fixes #255
1 parent b3e203c commit 54dbcd1

2 files changed

Lines changed: 31 additions & 18 deletions

File tree

.changeset/clear-points-care.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'layerchart': patch
3+
---
4+
5+
fix(TooltipContext): Fix touch scrolling on mobile. Fixes #255

packages/layerchart/src/lib/components/tooltip/TooltipContext.svelte

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@
270270
}
271271
}
272272
273-
function showTooltip(e: PointerEvent, tooltipData?: any) {
273+
function showTooltip(e: PointerEvent | MouseEvent | TouchEvent, tooltipData?: any) {
274274
// Cancel hiding tooltip if from previous event loop
275275
if (hideTimeoutId) {
276276
clearTimeout(hideTimeoutId);
@@ -511,6 +511,24 @@
511511
const triggerPointerEvents = $derived(
512512
['bisect-x', 'bisect-y', 'bisect-band', 'quadtree'].includes(mode)
513513
);
514+
515+
function onPointerEnter(e: PointerEvent | MouseEvent | TouchEvent) {
516+
isHoveringTooltipArea = true;
517+
if (triggerPointerEvents) {
518+
showTooltip(e);
519+
}
520+
}
521+
522+
function onPointerMove(e: PointerEvent | MouseEvent | TouchEvent) {
523+
if (triggerPointerEvents) {
524+
showTooltip(e);
525+
}
526+
}
527+
528+
function onPointerLeave(e: PointerEvent | MouseEvent | TouchEvent) {
529+
isHoveringTooltipArea = false;
530+
hideTooltip();
531+
}
514532
</script>
515533

516534
<!-- svelte-ignore a11y_no_static_element_interactions -->
@@ -521,25 +539,15 @@
521539
style:height="{ctx.height}px"
522540
class={cls(
523541
layerClass('tooltip-context'),
524-
'absolute touch-none',
542+
'absolute',
525543
debug && triggerPointerEvents && 'bg-danger/10 outline outline-danger'
526544
)}
527-
onpointerenter={(e) => {
528-
isHoveringTooltipArea = true;
529-
if (triggerPointerEvents) {
530-
showTooltip(e);
531-
}
532-
}}
533-
onpointermove={(e) => {
534-
if (triggerPointerEvents) {
535-
showTooltip(e);
536-
}
537-
}}
538-
onpointerleave={(e) => {
539-
isHoveringTooltipArea = false;
540-
541-
hideTooltip();
542-
}}
545+
onmouseenter={onPointerEnter}
546+
ontouchstart={onPointerEnter}
547+
onmousemove={onPointerMove}
548+
ontouchmove={onPointerMove}
549+
onmouseleave={onPointerLeave}
550+
ontouchend={onPointerLeave}
543551
onclick={(e) => {
544552
// Ignore clicks without data (triggered from Legend clicks, for example)
545553
if (triggerPointerEvents && tooltipContext.data != null) {

0 commit comments

Comments
 (0)