fix(a11y): five defects found by driving the installed build

Every one of these was in code whose tests were green. They were found by
installing the bundle, opening WebView2's debugging port, and pressing real
keys while reading document.activeElement and the accessibility tree.

- The high-contrast border on destructive buttons had never been drawn. The
  rule sat in @layer base; every button carries Tailwind's border utility, a
  later layer wins whatever the selectors say, and border: 2px lost to
  border-width: 1px. It is outside every layer, and a double border, because
  2px beside 1px is not a difference anyone sees.
- Accepting the legal gate left focus on nothing: the gate is rendered instead
  of the shell, so the screen was replaced with the tab unchanged.
- A button that disabled itself when pressed dropped focus to <body>, because
  a browser takes focus from a control that becomes disabled and jsdom does
  not. Use, Rescan, Run, Run audit, Add, Download the index, Stop and the two
  requirements buttons are aria-disabled while busy and ignore a second press.
- A dialog's name read "Remove packages : certifi": a browser puts a space
  before visually-hidden text. The second half of the name is an aria-label.
- The Updates tab's name read "Updates(5)".

Zoom hotkeys were tried and are not in this commit: at 200% in the default
window the package-name column collapsed to zero width.

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 4732f05197
commit 5aa4da87f4
15 files changed
+174 -46

No files matched your search

+20
View File
@@ -264,6 +264,26 @@ describe('where focus goes when the screen is replaced', () => {
})
})
it('lands on the first screen when the legal gate is accepted', async () => {
// Found in the installed build: *Continue* is unmounted with the gate, the shell appears
// behind it, and the tab has not changed — so the very first screen of a first run had focus
// on nothing.
legalConsentGet.mockResolvedValue({ current: false, docsHash: 'a1b2c3d4e5f60718' })
useLegalStore.setState({ accepted: false, review: false })
render(<App />)
const accept = await screen.findByRole('button', { name: 'Continue' })
accept.focus()
act(() => {
useLegalStore.setState({ accepted: true })
})
await waitFor(() => {
expect(heading()).toHaveFocus()
})
expect(heading()).toHaveTextContent('Installed')
})
it('does not take focus from a control that is still there', async () => {
// The rule is "focus was lost", not "the phase changed": moving it on every phase would pull
// a keyboard user off *Console* each time a run advanced.
+4 -1
View File
@@ -154,7 +154,10 @@ export function App() {
if (target === null || target === undefined) return
if (target.tagName === 'H1') target.setAttribute('tabindex', '-1')
target.focus()
}, [panelPhase, depsOpen, envOpen])
// `accepted` and `review`: the legal gate is rendered *instead of* the shell, so accepting it
// or closing a review is a fifth way the screen is replaced with `nav` unchanged — and the
// first screen of a first run had focus on nothing. Found in the installed build.
}, [panelPhase, depsOpen, envOpen, accepted, review])
// UI-SPEC §8: Ctrl+1..9 select tabs, positionally over NAV_KEYS.
useEffect(() => {
+8 -4
View File
@@ -81,9 +81,14 @@ export function PdDialog({
return (
<dialog
ref={ref}
// Named by its visible heading and described by its body, so opening it says what is being
// asked and what it will do — not only which button has focus.
aria-labelledby={titleId}
// Named by its visible heading — then what it is about — and described by its body, so
// opening it says what is being asked and what it will do, not only which button has focus.
// The second half is an `aria-label` rather than hidden text inside the heading, because a
// browser puts a space before visually-hidden text and the name read "Remove packages :
// numpy" in the installed build.
{...(label === title
? { 'aria-labelledby': titleId }
: { 'aria-label': `${title}: ${label}` })}
aria-describedby={bodyId}
// Esc reaches this rather than closing the element behind our back, so cancelling always
// goes through the same path as the button.
@@ -98,7 +103,6 @@ export function PdDialog({
>
<h2 id={titleId} className="text-accent">
{title}
{label === title ? null : <span className="sr-only">{`: ${label}`}</span>}
</h2>
<div id={bodyId} className="mt-3 text-data">
{children}
+10 -6
View File
@@ -83,23 +83,27 @@ export function PdRequirements({ env }: { env?: PyEnv | undefined }) {
<div className="mt-2 flex flex-wrap gap-2">
<button
type="button"
disabled={!usable || busy}
disabled={!usable}
// Unavailable is `disabled`; busy is `aria-disabled`, so the pressed button keeps focus
// while the picker is open (UI-SPEC §8).
aria-disabled={busy}
onClick={() => {
void doExport()
if (!busy) void doExport()
}}
data-action="export-requirements"
className="rounded-pd border border-border px-3 py-1 text-data disabled:opacity-40"
className="rounded-pd border border-border px-3 py-1 text-data disabled:opacity-40 aria-disabled:opacity-40"
>
{t('requirements.export')}
</button>
<button
type="button"
disabled={!usable || busy}
disabled={!usable}
aria-disabled={busy}
onClick={() => {
void doRead()
if (!busy) void doRead()
}}
data-action="import-requirements"
className="rounded-pd border border-border px-3 py-1 text-data disabled:opacity-40"
className="rounded-pd border border-border px-3 py-1 text-data disabled:opacity-40 aria-disabled:opacity-40"
>
{t('requirements.import')}
</button>
+4 -1
View File
@@ -60,8 +60,11 @@ export function PdSidebar() {
>
<span>
{t(`nav.${key}`)}
{/* A real space, not only a margin: inline spans are joined without one, and
the tab's accessible name read "Updates(5)". */}
{key === 'updates' && updatesCount > 0 ? ' ' : null}
{key === 'updates' && updatesCount > 0 ? (
<span className="ml-1 font-mono text-data text-warn">
<span className="font-mono text-data text-warn">
{`(${String(updatesCount)})`}
</span>
) : null}
+1 -2
View File
@@ -50,9 +50,8 @@ describe('PdUninstallDialog', () => {
// about follows, and the body is its description.
setup(BREAKING)
expect(dialog()).toHaveAccessibleName(/^This removal breaks other packages.*numpy/)
expect(dialog()).toHaveAccessibleName('This removal breaks other packages: numpy')
expect(dialog()).toHaveAccessibleDescription(/pandas 2\.1\.4 requires numpy/)
expect(dialog()).not.toHaveAttribute('aria-label')
})
it('focuses Cancel, and renders it first', () => {
+17
View File
@@ -82,6 +82,23 @@ describe('destructive controls', () => {
expect(forced).not.toMatch(/button\[data-action=/)
})
it('is drawn outside every cascade layer, where a utility cannot undo it', () => {
// **The rule existed for a year and drew nothing.** It sat inside `@layer base`, and every
// button also carries Tailwind's `border` utility, which lives in a later layer — and a later
// layer wins whatever the selectors say. So `border: 2px` lost to `border-width: 1px`, and in
// high contrast a destructive button was drawn exactly like the Cancel beside it: for the five
// actions the old list named, as well as the five it had missed. Seen by emulating
// forced-colors in the installed build and looking; nothing here renders a stylesheet.
//
// An unlayered rule beats every layered one. Depth 1 is "inside the media query and nothing
// else".
const at = styles.lastIndexOf('button[data-destructive]')
const before = styles.slice(0, at).replace(/\/\*[\s\S]*?\*\//g, '')
const depth = before.split('{').length - before.split('}').length
expect(depth).toBe(1)
expect(styles.slice(styles.lastIndexOf('@media', at), at)).toContain('forced-colors: active')
})
it('outlines the sidebar tab that is showing', () => {
// The tab carries `aria-current="page"`; the rule matched `'true'`, so in high contrast the
// active tab looked like every other.
+9 -6
View File
@@ -95,10 +95,13 @@ function Row({ row }: { row: EnvRow }) {
<button
type="button"
onClick={() => {
select(row.interpreter)
if (!isSelected) select(row.interpreter)
}}
disabled={isSelected}
className="rounded-pd border border-border px-3 py-1 text-data disabled:opacity-40"
// Busy is `aria-disabled`, not `disabled`: a browser takes focus from a control that
// becomes disabled, so one that disables itself when pressed drops focus to <body>
// (UI-SPEC §8).
aria-disabled={isSelected}
className="rounded-pd border border-border px-3 py-1 text-data aria-disabled:opacity-40"
>
{t('actions.use')}
</button>
@@ -212,10 +215,10 @@ export function PdEnvironments() {
<button
type="button"
onClick={() => {
void scan()
if (!scanning) void scan()
}}
disabled={scanning}
className="rounded-pd border border-border px-3 py-1 text-data disabled:opacity-40"
aria-disabled={scanning}
className="rounded-pd border border-border px-3 py-1 text-data aria-disabled:opacity-40"
>
{t('actions.rescan')}
</button>
+6 -3
View File
@@ -134,10 +134,13 @@ export function PdHealth() {
<button
type="button"
data-action="run-health"
className="rounded-pd bg-accent px-3 py-1 text-data text-bg disabled:opacity-50"
disabled={running || folder === null || env === undefined}
className="rounded-pd bg-accent px-3 py-1 text-data text-bg disabled:opacity-50 aria-disabled:opacity-50"
disabled={folder === null || env === undefined}
// Unavailable is `disabled`; busy is `aria-disabled`, so the button that was just
// pressed keeps focus while its run goes (UI-SPEC §8).
aria-disabled={running}
onClick={() => {
if (env !== undefined) void run(env, row.envHash)
if (env !== undefined && !running) void run(env, row.envHash)
}}
>
{running ? t('health.running') : t('health.run')}
+6 -3
View File
@@ -229,11 +229,14 @@ export function PdPlanPanel({ onFinished }: PdPlanPanelProps) {
<button
type="button"
onClick={() => {
void cancel()
if (!cancelling) void cancel()
}}
disabled={cancelling}
// Busy is `aria-disabled`, not `disabled`: a browser takes focus from a control that
// becomes disabled, so one that disables itself when pressed drops focus to <body>
// (UI-SPEC §8).
aria-disabled={cancelling}
data-destructive
className="rounded-pd border border-danger px-3 py-1 text-data text-danger disabled:opacity-40"
className="rounded-pd border border-danger px-3 py-1 text-data text-danger aria-disabled:opacity-40"
>
{cancelling ? t('plan.stopping') : t('plan.stop')}
</button>
+46 -1
View File
@@ -1,4 +1,4 @@
import { render, screen, within } from '@testing-library/react'
import { fireEvent, render, screen, within } from '@testing-library/react'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import type { Hit } from '@/ipc'
@@ -59,6 +59,51 @@ describe('what Search says without being looked at', () => {
expect(within(screen.getByRole('status')).getByText(/nothing matches/)).toHaveClass('sr-only')
})
it('keeps a button focusable after it has been pressed', () => {
// **Found in the installed build, not here.** *Add* and *Download the index* disabled
// themselves the moment they were pressed, and a browser takes focus away from a control that
// becomes `disabled` — so pressing either dropped focus to <body>. jsdom does not do that,
// which is why no test could see it; what a test can hold is the contract that avoids it:
// busy is `aria-disabled`, which greys the button and keeps it where focus is.
useIndexStore.setState({
query: 'num',
hits: HITS,
queue: [{ name: 'numpy', version: '' }],
unavailable: 'missing',
refreshing: true,
})
render(<PdSearch />)
const queued = screen.getByRole('button', { name: 'Queued' })
expect(queued).toHaveAttribute('aria-disabled', 'true')
expect(queued).not.toBeDisabled()
const refresh = screen.getByRole('button', { name: 'Downloading…' })
expect(refresh).toHaveAttribute('aria-disabled', 'true')
expect(refresh).not.toBeDisabled()
})
it('does nothing when a busy button is pressed again', () => {
const refreshIndex = vi.fn()
const enqueue = vi.fn()
useIndexStore.setState({
query: 'num',
hits: HITS,
queue: [{ name: 'numpy', version: '' }],
unavailable: 'missing',
refreshing: true,
refreshIndex,
enqueue,
})
render(<PdSearch />)
fireEvent.click(screen.getByRole('button', { name: 'Queued' }))
fireEvent.click(screen.getByRole('button', { name: 'Downloading…' }))
expect(enqueue).not.toHaveBeenCalled()
expect(refreshIndex).not.toHaveBeenCalled()
})
it('marks the result whose details are showing', () => {
// Selection was a background colour and nothing else, which forced-colors erases.
useIndexStore.setState({ query: 'num', hits: HITS, selected: 'numpydoc' })
+9 -6
View File
@@ -129,10 +129,13 @@ export function PdSearch() {
<button
type="button"
onClick={() => {
void refreshIndex()
if (!refreshing) void refreshIndex()
}}
disabled={refreshing}
className="mt-2 rounded-pd border border-border px-3 py-1 text-data disabled:opacity-40"
// Busy is `aria-disabled`, not `disabled`: a browser takes focus from a control that
// becomes disabled, so one that disables itself when pressed drops focus to <body>
// (UI-SPEC §8).
aria-disabled={refreshing}
className="mt-2 rounded-pd border border-border px-3 py-1 text-data aria-disabled:opacity-40"
>
{refreshing ? t('search.refreshing') : t('search.refreshIndex')}
</button>
@@ -200,10 +203,10 @@ export function PdSearch() {
<button
type="button"
onClick={() => {
enqueue(hit.name)
if (!queued) enqueue(hit.name)
}}
disabled={queued}
className="shrink-0 rounded-pd border border-border px-2 py-0.5 text-data disabled:opacity-40"
aria-disabled={queued}
className="shrink-0 rounded-pd border border-border px-2 py-0.5 text-data aria-disabled:opacity-40"
>
{queued ? t('search.queued') : t('search.add')}
</button>
+5 -1
View File
@@ -75,7 +75,11 @@ describe('PdSecurity', () => {
expect(screen.queryByText(/No audit has run/)).toBeNull()
expect(screen.getByRole('button', { name: 'Cancel' })).toBeInTheDocument()
expect(screen.getByRole('button', { name: 'Run audit' })).toBeDisabled()
// Busy, and still focusable: a control that goes `disabled` under the user's finger drops
// focus to <body> in a real browser (see PdSearch.test.tsx).
const run = screen.getByRole('button', { name: 'Run audit' })
expect(run).toHaveAttribute('aria-disabled', 'true')
expect(run).not.toBeDisabled()
})
it('shows the report only for the environment it belongs to', () => {
+6 -3
View File
@@ -74,11 +74,14 @@ export function PdSecurity() {
<button
type="button"
data-action="run-audit"
disabled={running || env === undefined}
disabled={env === undefined}
// Unavailable is `disabled`; busy is `aria-disabled`, so the button that was just
// pressed keeps focus while the audit runs (UI-SPEC §8).
aria-disabled={running}
onClick={() => {
if (env !== undefined && row !== undefined) void run(env, row.envHash)
if (env !== undefined && row !== undefined && !running) void run(env, row.envHash)
}}
className="rounded-pd bg-surface-2 px-3 py-1.5 text-accent disabled:opacity-40"
className="rounded-pd bg-surface-2 px-3 py-1.5 text-accent disabled:opacity-40 aria-disabled:opacity-40"
>
{t('security.run')}
</button>
+23 -9
View File
@@ -167,14 +167,28 @@
outline: 1px solid Highlight;
}
/* Destructive controls, which are otherwise indistinguishable once their tint is dropped.
*
* One attribute, not a list of `data-action` values. The list was five names long and missed
* Remove, Allow, Clear, the Force-latest confirm and a forced plan's Confirm for as long as it
* existed (U45) — a list of names beside a list of buttons is two lists. `destructive.test.ts`
* holds the other half: every button drawn in the danger colour carries the attribute. */
button[data-destructive] {
border: 2px solid CanvasText;
}
}
}
/* Destructive controls, which are otherwise indistinguishable once their tint is dropped.
*
* **Outside every `@layer`, and that is the whole fix.** This rule lived in the base layer above
* for as long as it existed, and drew nothing: every button also carries Tailwind's `border`
* utility, the utilities layer comes later, and a later layer wins whatever the selectors say — so
* `border: 2px` lost to `border-width: 1px`, and in high contrast *Remove anyway* was drawn exactly
* like the Cancel beside it. Found by emulating forced-colors in the installed build and looking.
* An unlayered rule beats every layered one.
*
* **A double line, not a thicker one.** Told apart from 1px, 2px is a difference nobody sees at a
* glance; a double border is a different shape, and it is not the focus ring, which is an outline
* in `Highlight`.
*
* One attribute, not a list of `data-action` values. The list was five names long and missed
* Remove, Allow, Clear, the Force-latest confirm and a forced plan's Confirm (U45) — a list of
* names beside a list of buttons is two lists. `destructive.test.ts` holds the other half: every
* button drawn in the danger colour carries the attribute, and this rule is in no layer. */
@media (forced-colors: active) {
button[data-destructive] {
border: 3px double CanvasText;
}
}