fix(a11y): finish the tab, radio group and listbox patterns (U47, U48)

Health's tabs were three buttons with role="tab": three tab stops, no arrow
keys, no panel. They are one stop with Left/Right/Home/End, tied to a tabpanel.
Their accessible name was an aria-label reading "Dependencies, 3 findings" over
a tab that says "deptry 3", which fails WCAG 2.5.3; the name is the visible
text now, followed by what the tab is about.

A conflict's three choices were role="radio" with none of a radio group's
keyboard. They are one stop, and the arrows move between them. The arrows move
focus and choose nothing: checking what focus lands on would open Force
latest's destructive confirm from an arrow key.

The palette's highlight is an aria-activedescendant, not focus, so nothing
scrolled the list and the selection left the visible window. It is scrolled
into view.

The vulture whitelist link was told from the sentence around it by a colour
1.4:1 away and underlined only on hover. It is underlined at rest.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
poli0981andClaude Fable 5.2 committed 2026-11-10 20:01:03 +07:00
1 parent 567b0ae8fa
commit 6b70580b91
6 files changed
+202 -15

No files matched your search

+42 -1
View File
@@ -13,7 +13,7 @@
* `PdUninstallDialog.test.tsx` gives about `GuardReport`.
*/
import { render, screen, within } from '@testing-library/react'
import { fireEvent, render, screen, within } from '@testing-library/react'
import { describe, expect, it, vi } from 'vitest'
import { PdConflictRow } from '@/components/PdConflictRow'
@@ -71,6 +71,47 @@ describe('PdConflictRow', () => {
).toBeInTheDocument()
})
it('is one tab stop, with the arrows moving between its choices', () => {
// U47: three buttons with `role="radio"` and none of a radio group's keyboard — every choice
// of every conflict was its own tab stop, and the arrow keys did nothing.
const { onChoose } = setup(BLOCKERS)
const radios = within(screen.getByRole('radiogroup', { name: 'numpy' })).getAllByRole('radio')
const [keep, skip, force] = radios
if (keep === undefined || skip === undefined || force === undefined) {
throw new Error('three choices expected')
}
// The checked one is the stop: keep-compatible is the default.
expect(radios.map((r) => r.getAttribute('tabindex'))).toEqual(['0', '-1', '-1'])
keep.focus()
fireEvent.keyDown(keep, { key: 'ArrowRight' })
expect(skip).toHaveFocus()
fireEvent.keyDown(skip, { key: 'ArrowDown' })
expect(force).toHaveFocus()
fireEvent.keyDown(force, { key: 'ArrowRight' })
expect(keep).toHaveFocus()
fireEvent.keyDown(keep, { key: 'ArrowLeft' })
expect(force).toHaveFocus()
// **Focus moves; nothing is chosen.** A radio group normally checks what the arrows land on,
// and here that would open *Force latest*'s destructive confirm from an arrow key.
expect(onChoose).not.toHaveBeenCalled()
expect(screen.queryByRole('alertdialog')).toBeNull()
})
it('skips a choice that cannot be made', () => {
setup(BLOCKERS, true)
const [, skip, force] = within(screen.getByRole('radiogroup', { name: 'numpy' })).getAllByRole(
'radio',
)
if (skip === undefined || force === undefined) throw new Error('three choices expected')
force.focus()
fireEvent.keyDown(force, { key: 'ArrowRight' })
expect(skip).toHaveFocus()
})
it('refuses Keep compatible on an impossible row', () => {
// `default_decision(is_impossible = true, …)` returns Skip, so the control mirrors the core
// rather than offering a choice it would refuse to honour.
+27
View File
@@ -100,6 +100,32 @@ export function PdConflictRow({
role="radio"
aria-checked={selected}
disabled={disabled}
data-option={option}
// A radio group is one tab stop — the checked choice — with the arrows moving
// inside it (U47). These were three stops per conflict and no arrow keys.
//
// **The arrows move focus and choose nothing**, which is not what a radio group
// usually does. Checking whatever focus lands on would open *Force latest*'s
// destructive confirm from an arrow key; Space or Enter on the focused choice is
// the same click it always was.
tabIndex={selected ? 0 : -1}
onKeyDown={(e) => {
const step =
e.key === 'ArrowRight' || e.key === 'ArrowDown'
? 1
: e.key === 'ArrowLeft' || e.key === 'ArrowUp'
? -1
: 0
if (step === 0) return
e.preventDefault()
const choices = OPTIONS.filter((o) => !(impossible && o === 'keep-compatible'))
const at = choices.indexOf(option)
const next = choices[(at + step + choices.length) % choices.length]
if (next === undefined) return
e.currentTarget.parentElement
?.querySelector<HTMLElement>(`[data-option="${next}"]`)
?.focus()
}}
title={disabled ? t('plan.keepCompatibleImpossible') : undefined}
onClick={() => {
if (option === 'force-latest') {
@@ -146,6 +172,7 @@ export function PdConflictRow({
setConfirmingForce(false)
onChoose('force-latest')
}}
data-destructive
// Outlined, not filled: a fill inside the confirm's own danger tint read at 4.03:1.
className="rounded-pd border border-danger px-2 py-0.5 text-data text-danger"
>
+48 -4
View File
@@ -49,13 +49,46 @@ function setup(
describe('tabs', () => {
it('labels each tab with the tool that produced it and its count', () => {
setup()
// The visible label is the tool's own name — data, never translated (I18N §2).
const tabs = screen.getAllByRole('tab')
// Visible text first, so the accessible name *contains* what is on screen (WCAG 2.5.3). The
// old name was "Dependencies, 2 findings" over a tab reading "deptry 2", and "click deptry"
// found nothing.
expect(tabs.map((t) => t.textContent)).toEqual([
`deptry${REPORT.deptry.length}`,
`vulture${REPORT.vulture.length}`,
`ruff${REPORT.ruff.findings.length}`,
`deptry ${String(REPORT.deptry.length)}, Dependencies`,
`vulture ${String(REPORT.vulture.length)}, Dead code`,
`ruff ${String(REPORT.ruff.findings.length)}, Lint`,
])
for (const tab of tabs) expect(tab).not.toHaveAttribute('aria-label')
})
it('ties the tabs to one panel, named by the tab that is showing', () => {
setup(REPORT, 'vulture')
const panel = screen.getByRole('tabpanel')
const selected = screen.getByRole('tab', { selected: true })
expect(selected).toHaveAttribute('aria-controls', panel.id)
expect(panel).toHaveAttribute('aria-labelledby', selected.id)
})
it('makes the selected tab the only tab stop', () => {
setup(REPORT, 'vulture')
const stops = screen.getAllByRole('tab').map((t) => t.getAttribute('tabindex'))
expect(stops).toEqual(['-1', '0', '-1'])
})
it('moves between tabs with the arrow keys, Home and End, wrapping at both ends', () => {
const { onTab } = setup(REPORT, 'deptry')
const [deptry, , ruff] = screen.getAllByRole('tab')
if (deptry === undefined || ruff === undefined) throw new Error('three tabs expected')
fireEvent.keyDown(deptry, { key: 'ArrowRight' })
expect(onTab).toHaveBeenLastCalledWith('vulture')
fireEvent.keyDown(deptry, { key: 'ArrowLeft' })
expect(onTab).toHaveBeenLastCalledWith('ruff')
fireEvent.keyDown(deptry, { key: 'End' })
expect(onTab).toHaveBeenLastCalledWith('ruff')
fireEvent.keyDown(ruff, { key: 'Home' })
expect(onTab).toHaveBeenLastCalledWith('deptry')
})
it('takes its counts from the report rather than recomputing them', () => {
@@ -194,3 +227,14 @@ describe('the footer', () => {
expect(screen.getByText(/requirements-dev\.txt, requirements\.txt/)).toBeInTheDocument()
})
})
describe('the vulture whitelist link', () => {
it('is underlined at rest, not only on hover', () => {
// WCAG 1.4.1: a link inside a paragraph told from the words around it by colour alone. The
// two colours are 1.4:1 apart, and the underline appeared only under a pointer.
setup(REPORT, 'vulture')
const link = screen.getByRole('button', { name: /whitelist/ })
expect(link).toHaveClass('underline')
expect(link.className).not.toContain('hover:underline')
})
})
+61 -10
View File
@@ -34,6 +34,9 @@ export const RUFF_ROWS_SHOWN = 500
/** vulture's own guidance on suppressing a false positive (CODE-HEALTH-SPEC §6). */
const VULTURE_WHITELIST = 'https://github.com/jendrikseipp/vulture#handling-false-positives'
/** The one panel the three tabs control. One id, because only one report is ever on screen. */
const PANEL_ID = 'health-panel'
interface PdHealthReportProps {
report: HealthReport
/** ruff grouped by file, from the store. Never regrouped here — see `groupRuff`. */
@@ -154,7 +157,7 @@ function RuffRow({ finding }: { finding: RuffFinding }) {
) : (
<button
type="button"
className="font-mono text-data text-accent-dim underline-offset-2 hover:underline"
className="font-mono text-data text-accent-dim underline underline-offset-2"
onClick={() => {
// The URL is ruff's own — constructed ones 404, because the rule page is keyed by name
// and not by code. It is also the **only** URL in the application that comes out of a
@@ -217,16 +220,46 @@ export function PdHealthReport({
<div className="flex min-h-0 flex-1 flex-col">
<p className="shrink-0 text-data text-text-dim">{declared}</p>
<div role="tablist" className="mt-3 flex shrink-0 gap-1 border-b border-border">
{HEALTH_TABS.map((key) => (
<div
role="tablist"
aria-label={t('health.tabs')}
className="mt-3 flex shrink-0 gap-1 border-b border-border"
>
{HEALTH_TABS.map((key, index) => (
<button
key={key}
id={`health-tab-${key}`}
role="tab"
type="button"
aria-selected={tab === key}
// The visible label is the tool's own name — data, never translated (I18N §2). The
// accessible name is what says which question the tab answers, and the count with it.
aria-label={t(`health.tabLabel.${key}`, { count: found[key] })}
aria-controls={PANEL_ID}
// The tabs pattern: one tab stop, the selected one, and the arrows move between them
// (U47). Three buttons with `role="tab"` were three tab stops and no arrow keys.
tabIndex={tab === key ? 0 : -1}
onKeyDown={(e) => {
const last = HEALTH_TABS.length - 1
const to =
e.key === 'ArrowRight'
? index === last
? 0
: index + 1
: e.key === 'ArrowLeft'
? index === 0
? last
: index - 1
: e.key === 'Home'
? 0
: e.key === 'End'
? last
: undefined
const next = to === undefined ? undefined : HEALTH_TABS[to]
if (next === undefined) return
e.preventDefault()
onTab(next)
// The buttons are keyed by tool and outlive the change, so the one that is about to
// be selected is already in the document to take focus.
document.getElementById(`health-tab-${next}`)?.focus()
}}
className={`rounded-t-pd px-3 py-1.5 font-mono text-data ${
tab === key
? 'border-b-2 border-accent text-text'
@@ -236,15 +269,30 @@ export function PdHealthReport({
onTab(key)
}}
>
{key}
{/* **The accessible name is this content, in this order** — the tool's own name
(data, never translated: I18N §2), its count, then which question the tab answers.
It was an `aria-label` reading "Dependencies, 3 findings" over a tab that says
"deptry 3": a name that does not contain what is on screen fails WCAG 2.5.3, and
"click deptry" found nothing. The spaces are literal because inline spans are
joined without any. */}
{key}{' '}
{/* The count comes off the report. A tab that recomputed it could disagree with the
CLI over the same run, which is the one difference nobody would think to check. */}
<span className="ml-2 text-text-dim">{found[key]}</span>
<span className="ml-1 text-text-dim">{found[key]}</span>
<span className="sr-only">{`, ${t(`health.tabTopic.${key}`)}`}</span>
</button>
))}
</div>
<div className="mt-3 min-h-0 flex-1 overflow-auto">
<div
id={PANEL_ID}
role="tabpanel"
aria-labelledby={`health-tab-${tab}`}
// A stop of its own: a panel whose findings hold no control would otherwise be skipped by
// Tab, and it scrolls.
tabIndex={0}
className="mt-3 min-h-0 flex-1 overflow-auto"
>
{state === 'notRun' ? (
<PdEmptyState message={t('health.notRun')} hint={t('health.notRunHint')} />
) : null}
@@ -280,7 +328,9 @@ export function PdHealthReport({
{t('health.vultureHint')}{' '}
<button
type="button"
className="text-accent-dim underline-offset-2 hover:underline"
// Underlined at rest. Inside a sentence, colour was the only thing telling this
// from the words around it, and the two colours are 1.4:1 apart (WCAG 1.4.1).
className="text-accent-dim underline underline-offset-2"
onClick={() => {
open(VULTURE_WHITELIST)
}}
@@ -309,6 +359,7 @@ export function PdHealthReport({
<button
type="button"
data-action="fix"
data-destructive
className="mb-3 rounded-pd bg-danger px-3 py-1 text-data text-bg"
onClick={onFix}
>
+14
View File
@@ -62,6 +62,20 @@ describe('PdPalette', () => {
expect(options()[0]).toHaveAttribute('aria-selected', 'true')
})
it('scrolls the highlighted action into view as the arrows move it', () => {
// U48: the list is `max-h-80 overflow-auto`, and nothing scrolled it — so past the ninth
// action the highlight left the visible window and Enter ran something off screen.
const scrolled = vi.fn()
Element.prototype.scrollIntoView = scrolled
const { input } = open()
scrolled.mockClear()
fireEvent.keyDown(input, { key: 'ArrowDown' })
expect(scrolled).toHaveBeenCalledWith({ block: 'nearest' })
expect(scrolled.mock.contexts.at(-1)).toBe(options()[1])
})
it('will not run off either end of the list', () => {
const { input } = open()
fireEvent.keyDown(input, { key: 'ArrowUp' })
+10
View File
@@ -170,6 +170,16 @@ export function PdPalette({ onClose }: { onClose: () => void }) {
}
}, [])
// U48: keep the highlight on screen. The list is `max-h-80 overflow-auto` and the selection is
// an `aria-activedescendant`, not focus — so nothing scrolled, and past the ninth action the
// highlight left the visible window while Enter still ran it. `nearest`, so a selection that is
// already visible does not move the list at all.
const activeId = shown[active]?.id
useEffect(() => {
if (activeId === undefined) return
document.getElementById(`palette-${activeId}`)?.scrollIntoView({ block: 'nearest' })
}, [activeId])
const dispatch = (action: Action | undefined) => {
if (action === undefined) return
// Closed *before* running, so an action that changes `nav` does not fight the dialog for