[Bug] Focus ownership: Escape does not clear keyboard focus, a pointer pass loses it, and controlled focus survives pointer leave
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- Nửa ngày
- Mức phù hợp với người mới
- 55/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- d3, typescript
- Lĩnh vực
- accessibility, data-visualization
Hướng nghiên cứu
Start by running packages/charts-core/test-repro/04-keyboard-focus-min.test.ts from the repo root; both cases A and B fail on the current commit. For A, look at the Escape branch in handleKeyDown in packages/charts-core/src/renderer.ts and at dismissTooltip, then at the Escape handling in interaction.ts. For B, follow focusOwner through the pointer-move and mouseleave handlers and setControlledFocus in renderer.ts, and the ChartFocusSource type in dom-types.ts and types.ts. Done when both tests pass without breaking the existing focus tests.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Version: @tanstack/charts 1.1.0 (57774e1).
The renderer tracks who owns focus (focusOwner: pointer, keyboard, controlled), but three transitions are wrong. With keyboard focus on the chart SVG (Tab), Escape does nothing (A), and a pointer passing over the chart drops the keyboard position, so the next arrow restarts at index 0 (B). Focus set through the controller from a pointer resolution is never cleared when the pointer leaves (C). All three are in the same ownership logic in renderer.ts.
A. Escape does not dismiss keyboard focus
handleKeyDownhandles Escape only for a cursor session or a pinned tooltip (renderer.ts:882-890).- For plain keyboard focus the navigation helper returns
undefinedfor Escape (interaction.ts:155-156) andhandleKeyDownreturns (renderer.ts:926). dismissTooltipalready clears focus but is not reached (renderer.ts:584-592).
Expected: Escape clears focus (tooltip, guides, onFocusChange(null)), DOM focus stays on the SVG, and the next arrow resumes navigation. Escape is also missing from the key list in tooltips-and-focus.md:654.
B. A pointer pass loses keyboard focus
- Pointer move sets
focusOwner = 'pointer'(renderer.ts:748-749). Mouseleave then clears focus (renderer.ts:764-768), so the next ArrowRight lands on index 0. - A controller cannot hand focus back as keyboard focus:
sourceis'pointer' | 'programmatic'(dom-types.ts:74) andsetControlledFocusalways setsfocusOwner = 'controlled'(renderer.ts:666-668).
Expected: keyboard focus survives a pointer pass and the next arrow continues from it.
C. Controlled focus from a pointer resolution survives pointer leave (from this comment)
mouseleaveandpointercancelrunclearPointerFocus, which acts only whenfocusOwner === 'pointer'(renderer.ts:764-781, bound at renderer.ts:964-965).ChartControlledFocusOptions.sourceonly labels the focus for marks and tooltips (dom-types.ts:72-77, renderer.ts:688-690); it does not hand ownership to the pointer.- Example: after a drill-down zoom no pointer event fires, so the app re-resolves focus for the still pointer with
interaction.setControlledFocus(interaction.resolvePointer(x, y)). When the pointer then leaves, focus, tooltip and dimming stay. Read from source, not run.
Expected: focus set from a pointer resolution is cleared on pointer leave, like pointer focus.
Repro (A and B)
Save as packages/charts-core/src/repro.test.ts, run pnpm vitest run packages/charts-core/src/repro.test.ts. The tests assert the expected behaviour.
import { expect, it, vi } from 'vitest'
import { scaleLinear } from 'd3-scale'
import { dot } from './dot'
import { mountChartRenderer } from './renderer'
import { defineChart } from './scene'
const data = [0, 1, 2].map((x) => ({ x }))
const definition = defineChart({
marks: [dot(data, { x: 'x', y: 'x', key: (d) => String(d.x) })],
scales: { x: { scale: scaleLinear().domain([0, 2]) }, y: { scale: scaleLinear().domain([0, 2]) } },
guides: false,
})
function setup() {
const el = document.createElement('div')
const surface: any = { element: el, render: () => { el.tabIndex = 0 }, paintFocus() {}, destroy() {},
clientToScene: (s: any) => ({ x: s.points[0].x, y: s.points[0].y }) }
const renderer: any = { id: 't', prerender: () => '', mount: (c: HTMLElement) => (c.append(el), surface) }
const onFocusChange = vi.fn()
const root = document.body.appendChild(document.createElement('div'))
mountChartRenderer(root, { definition, renderer, width: 400, height: 300, ariaLabel: 'g', onFocusChange })
const fire = (e: Event) => el.dispatchEvent(e)
fire(new FocusEvent('focusin', { bubbles: true })) // Tab into the SVG
return {
fire, root,
key: (key: string) => fire(new KeyboardEvent('keydown', { bubbles: true, key })),
last: () => onFocusChange.mock.calls.at(-1)?.[0]?.datum ?? null,
}
}
it('A: Escape clears keyboard focus', () => {
const t = setup(); expect(t.last()).toEqual({ x: 0 })
t.key('Escape'); expect(t.last()).toBeNull()
})
it('B: keyboard focus survives a pointer pass', () => {
const t = setup(); t.key('ArrowRight') // x=1
t.fire(new MouseEvent('pointermove', { bubbles: true, clientX: 5, clientY: 5 }))
t.root.dispatchEvent(new MouseEvent('mouseleave'))
t.key('ArrowRight'); expect(t.last()).toEqual({ x: 2 }) // continues, not restart
})
Output on 57774e1 (vitest 4.1.10): both fail.
A: AssertionError: expected { x: +0 } to be null
B: AssertionError: expected { x: +0 } to deeply equal { x: 2 }
Proposed fix
- A: handle Escape for plain keyboard focus through the existing
dismissTooltippath. - B and C: let
setControlledFocustake ownership from itssource: acceptsource: 'keyboard'(already inChartFocusSource, types.ts:1736-1737) and setfocusOwner = 'keyboard'for it, and setfocusOwner = 'pointer'forsource: 'pointer'or a pointer resolution, so the usual leave handling clears it. Alternative for C: document a "re-resolve at the last pointer position" call that keeps pointer ownership.
Impact (bklit migration, Chrome): B is worked around by re-applying the last point with setControlledFocus on pointer leave, passing source: 'keyboard' through a type cast; C needs our own mouseleave listener. There is no workaround for A.
Related: PR #164 "feat(focus): two-dimensional grid focus for heatmaps" (open), #203 (early pointer input hits the same ownership rule).
- Ngôn ngữ chính
- TypeScript
- Star
- 870
- Fork
- 57
- Merge trung bình
- 11 giờ 58 phút
- Pull request đã merge (30 ngày)
- 18
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của TanStack/charts
-
[Perf] Canvas layer composition is quadratic: splitRenderLayers re-copies the node array per nodeĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug] Focus guides: `url(#id)` paints ignore `idPrefix`Có thể đã có người làm @getdownandcode đã nhận 37 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
TanStack/charts#211 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Add reverse options to waffleY and waffleXCó thể đã có người làm @tannerlinsley đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 25/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của TanStack/charts
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
fb55/htmlparser2#2579 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug good first issue needs-review
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 83/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Add Module DB RulesĐang mởdocumentation public
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 68/100
midnightntwrk/umbradb#65 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
area/channels kind/bug priority/medium
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
nanocoai/nanoclaw#4501 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Docker images: plain X.Y.Z tag (e.g. 7.2.3) is never updated after the initial release buildĐang mởneeds verification
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 13 ngày