Skip to content

[TooltipContext] Tooltip locked from onclick loses its data on touch, and the lock can't be released #922

Closed

Description

@ntainy

Hi!

Repro here (open the repro as separate page and open devtools for it or open on the actual phone - even better)

tl;dr:

  • Expected behaviour: first tap pins the tooltip, second tap unpins it.
  • Actual: the tooltip vanishes right after the first tap, locked: true stays, next taps do nothing.

--

When locked is switched on from the tooltip's onclick (tap to pin), on a touch device the tooltip disappears right after the tap, locked stays true, and no further tap reaches onclick. The chart is stuck without a tooltip until it is remounted. With a mouse it works fine tho.

On touch, a tap dispatches pointerup → pointerleave → click. pointerleave calls hideTooltip(), which returns early only if locked is already true and otherwise schedules the clear:

hideTimeoutId = setTimeout(() => {
  if (!tooltipState.isHoveringTooltipArea && !tooltipState.isHoveringTooltipContent) {
    tooltipState.data = null;
    // ...

The click that follows sets locked = true, but the callback never re-checks locked, and the timeout is cleared only on the next show. So it clears tooltipState.data under the lock. After that every tap is ignored: showing is refused while locked, and the root onclick is only forwarded when tooltipState.data != null, so locked can't be set back to false.

Re-checking locked inside the timeout fixes it (checked against the repro above):

     hideTimeoutId = setTimeout(() => {
+      // The tooltip may have been locked since this hide was scheduled (e.g. tap to pin)
+      if (locked) return;
       if (!tooltipState.isHoveringTooltipArea && !tooltipState.isHoveringTooltipContent) {

Clearing hideTimeoutId when locked becomes true would work too.

For now I work around it by calling context.tooltip.show(e, data) in onclick right before locking, which cancels the pending hide.

layerchart 2.5.0 (same code on main at ddceba2), svelte 5.55.5, Chromium 147 (Playwright), touch emulation.

Will be happy to open a PR for it.

Thank you!

Activity

  1. techniq commented on Oct 1, 2026

    @techniq
    Owner

    Hey @ntainy, thank you for the detailed description and concise reproduction! Very much appreciated 🫶.

    The fix is also straight forward and would appreciate a PR if you have time.

    I also ran this by an agent to see if it had any additional feedback and it's callout about the tooltip staying visible (but unlocked) looks like something we'd want to validate and address as well. Also adding some tests would be great to have coverage.

    Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions