Skip to content
Source
Sign inSign up
TanStack/charts

[Bug] Focus ring invisible when the chart has an x viewport: clip-path <defs> gets visibility="hidden" #264

OpenSpielerJ(GitHub profile, opens in a new tab) opened this issue 1 comment

Version: @tanstack/charts 1.2.0, still present in 1.4.0

What happens

With scales.x.viewport set, the default focus ring on a lineY mark doesn't show on hover. The crosshair and tooltip work. The ring's <circle> is in the DOM with visibility="visible", but nothing is drawn.

Cause

With a viewport, the focus layer gets a clip path. renderSvgClip (svg-renderer.js) writes its <defs data-ts-key="…:clip-defs"> as a keyed child of the layer:

<g class="ts-chart__focus-layer" data-ts-focus-layer="over" clip-path="url(#…)">
  <defs data-ts-key="default-focus:line-0:clip-defs" visibility="hidden">
    <clipPath id="…"><rect x="44" y="4" width="700" height="178"/></clipPath>
  </defs>
  <circle data-ts-key="line-0:…" visibility="visible" … />
</g>

paintMotionSvgFocus (motion.js) and the same loop in svg-surface.js set visibility on every [data-ts-key] descendant of the layer, by whether its key is focused. The <defs> is never focused, so it gets hidden. The <rect> inside the clipPath inherits that. Per the SVG spec, a clip path child that isn't visible doesn't contribute to the clip, so the clip region is empty and the whole layer is clipped away.

Repro

defineChart({
  marks: [lineY(data, { x: (d) => d.x, y: (d) => d.y }), crosshair({ x: true, y: false })],
  scales: { x: { scale: scaleUtc, viewport: { domain: [from, to] } }, y: { scale: scaleLinear } },
  focus: 'group-x',
})

Hover the plot: tooltip and crosshair appear, the ring doesn't. Remove viewport and the ring is back.

Suggested fix

Skip the clip definitions when painting focus visibility, e.g. leave out keys ending in :clip-defs or defs elements in the querySelectorAll("[data-ts-key]") loop. Alternatively, render the <defs> without a data-ts-key.

Workaround

[data-ts-focus-layer] > defs { visibility: visible; }

CSS outranks the presentation attribute.


Investigated with the help of an AI assistant; verified against the 1.2.0 and 1.4.0 dist.

  1. tannerlinsleycommented

    Thanks for the clear repro, @SpielerJ. The clip definitions need to stay out of focus filtering.

    AI review notes: Reproduced this on current main, 33ae6551197e0cab236cdac67256f7ed66c1c331, in both the static and motion SVG renderers. The focus circle is marked visible, but its clip definitions get hidden.

    The final local candidate skips defs in the two loops that hide unfocused nodes and avoids rewriting unchanged visibility attributes. It keeps clip keys and reconciliation intact. Regression tests fail before the change and pass afterward, and native raster checks in Chromium, Firefox and WebKit confirm that the ring is painted, clears with focus, and returns when focused again.

    This is verified locally and has not landed yet. The issue remains open while the remaining delivery checks and exact bundle limits are resolved.

Sign in to join this conversation.