fix(a11y): mark destructive controls by attribute for high contrast (U45)
Forced-colors drops every tint, so a danger-treated primary is drawn exactly like the Cancel beside it. The stylesheet gave five data-action values a border and had missed Remove, Allow, Clear, the Force-latest confirm and a forced plan's Confirm for as long as the list existed. The mark is one attribute, data-destructive, and destructive.test.ts reads the source to hold both halves: every button drawn in the danger colour carries it, and the stylesheet draws it. The active sidebar tab carries aria-current="page" and the outline rule matched 'true', so high contrast drew it like every other tab. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
f1bab20306
commit
a5fc204de8
10 files changed
+115
-7
No files matched your search
@@ -160,6 +160,7 @@ export function PdCacheUsage() {
|
||||
void doClear(confirming)
|
||||
}}
|
||||
data-action="confirm-clear-cache"
|
||||
data-destructive
|
||||
className="rounded-pd border border-danger px-3 py-1 text-data text-danger disabled:opacity-40"
|
||||
>
|
||||
{t('cache.clear')}
|
||||
|
||||
@@ -113,6 +113,7 @@ export function PdSummarySheet({ outcome, onDone, onRollback }: PdSummarySheetPr
|
||||
onRollback(snapshot.id)
|
||||
}}
|
||||
data-action="rollback"
|
||||
data-destructive
|
||||
className="rounded-pd border border-danger px-2 py-0.5 text-data text-danger"
|
||||
>
|
||||
{t('snapshots.rollbackThis')}
|
||||
|
||||
@@ -64,6 +64,7 @@ export function PdUninstallDialog({
|
||||
onConfirm(false)
|
||||
}}
|
||||
data-action="remove"
|
||||
data-destructive
|
||||
className="rounded-pd border border-danger px-3 py-1 text-data text-danger disabled:opacity-40"
|
||||
>
|
||||
{t('uninstall.remove', { count: report.removing.length })}
|
||||
@@ -88,6 +89,7 @@ export function PdUninstallDialog({
|
||||
onConfirm(true)
|
||||
}}
|
||||
data-action="force"
|
||||
data-destructive
|
||||
className="rounded-pd border border-danger bg-danger/15 px-3 py-1 text-data text-danger disabled:opacity-40"
|
||||
>
|
||||
{t('uninstall.force', { count: report.removing.length })}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* Every destructive control says so in an attribute, and high contrast draws it — UI-SPEC §7.
|
||||
*
|
||||
* Forced-colors drops every tint, so a danger-treated primary is drawn exactly like the Cancel
|
||||
* beside it unless something that survives the mode marks it. The stylesheet used to do that with
|
||||
* a hand-kept list of five `data-action` values, and the list was wrong for as long as it existed:
|
||||
* *Remove*, *Allow*, *Clear*, the *Force latest* confirm and a forced plan's *Confirm* were never
|
||||
* on it (audit backlog U45). A list of names beside a list of buttons is two lists.
|
||||
*
|
||||
* So the mark is one attribute, `data-destructive`, and this reads the source to hold both halves:
|
||||
* every button drawn in the danger colour carries it, and the stylesheet draws it. jsdom applies
|
||||
* no stylesheet and has no forced-colors, so there is nothing to render — the source is the only
|
||||
* place either fact exists before the hand pass.
|
||||
*/
|
||||
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { resolve } from 'node:path'
|
||||
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
const sources = import.meta.glob<string>(['./**/*.tsx', '!./**/*.test.tsx'], {
|
||||
query: '?raw',
|
||||
import: 'default',
|
||||
eager: true,
|
||||
})
|
||||
// Read from disk: vitest hands a test an empty string for any `.css` import, `?raw` included.
|
||||
// From the working directory, which `vite.config.ts` pins to the repository root — under jsdom
|
||||
// `import.meta.url` is not a `file:` URL to resolve against.
|
||||
const styles = readFileSync(resolve(process.cwd(), 'ui/src/styles.css'), 'utf8')
|
||||
|
||||
/** The opening tag of every `<button>` in a file, as written. */
|
||||
function buttonTags(source: string): string[] {
|
||||
const lines = source.split('\n')
|
||||
const tags: string[] = []
|
||||
for (let i = 0; i < lines.length; i += 1) {
|
||||
if (!/<button\b/.test(lines[i] ?? '')) continue
|
||||
const tag: string[] = []
|
||||
// The formatter closes a multi-line opening tag with `>` on a line of its own, which is the
|
||||
// one `>` in a JSX tag that cannot be an arrow function or a comparison.
|
||||
for (let j = i; j < lines.length; j += 1) {
|
||||
const line = lines[j] ?? ''
|
||||
tag.push(line)
|
||||
if (line.trim() === '>' || (j === i && /<button\b[^{]*>/.test(line))) break
|
||||
}
|
||||
tags.push(tag.join('\n'))
|
||||
}
|
||||
return tags
|
||||
}
|
||||
|
||||
/** Actions that are destructive whatever colour their button is drawn in. */
|
||||
const DESTRUCTIVE_ACTIONS =
|
||||
/data-action="(force|uninstall|rollback|upgrade-pip|fix|remove|allow-override|confirm-clear-cache)"/
|
||||
|
||||
describe('destructive controls', () => {
|
||||
const tags = Object.entries(sources).flatMap(([file, source]) =>
|
||||
buttonTags(source).map((tag) => ({ file, tag })),
|
||||
)
|
||||
|
||||
it('finds the buttons it is meant to be reading', () => {
|
||||
// A scan that matches nothing passes everything.
|
||||
expect(tags.length).toBeGreaterThan(40)
|
||||
expect(tags.filter(({ tag }) => /(border|bg)-danger/.test(tag)).length).toBeGreaterThan(8)
|
||||
})
|
||||
|
||||
it('marks every button drawn in the danger colour', () => {
|
||||
const unmarked = tags
|
||||
.filter(({ tag }) => /(border|bg)-danger/.test(tag) && !tag.includes('data-destructive'))
|
||||
.map(({ file, tag }) => `${file}: ${tag.trim().split('\n').slice(0, 3).join(' ')}`)
|
||||
expect(unmarked).toEqual([])
|
||||
})
|
||||
|
||||
it('marks every action that removes, forces, rolls back or rewrites', () => {
|
||||
const unmarked = tags
|
||||
.filter(({ tag }) => DESTRUCTIVE_ACTIONS.test(tag) && !tag.includes('data-destructive'))
|
||||
.map(({ file, tag }) => `${file}: ${tag.trim().split('\n').slice(0, 3).join(' ')}`)
|
||||
expect(unmarked).toEqual([])
|
||||
})
|
||||
|
||||
it('is drawn by the stylesheet under forced-colors, by the attribute and not by a list', () => {
|
||||
const forced = styles.slice(styles.indexOf('@media (forced-colors: active)'))
|
||||
expect(forced).toContain('button[data-destructive]')
|
||||
expect(forced).not.toMatch(/button\[data-action=/)
|
||||
})
|
||||
|
||||
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.
|
||||
const forced = styles.slice(styles.indexOf('@media (forced-colors: active)'))
|
||||
expect(forced).toContain("[aria-current='page']")
|
||||
})
|
||||
})
|
||||
@@ -127,6 +127,7 @@ export function PdEnvDetail() {
|
||||
void rollback(env, selectedSnapshot)
|
||||
}}
|
||||
data-action="rollback"
|
||||
data-destructive
|
||||
className="mt-4 rounded-pd border border-danger px-3 py-1 text-data text-danger"
|
||||
>
|
||||
{t('snapshots.rollback')}
|
||||
|
||||
@@ -125,6 +125,7 @@ function Row({ row }: { row: EnvRow }) {
|
||||
}}
|
||||
disabled={upgrading}
|
||||
data-action="upgrade-pip"
|
||||
data-destructive
|
||||
className="rounded-pd border border-warn px-3 py-1 text-data text-warn disabled:opacity-40"
|
||||
>
|
||||
{upgrading ? t('env.pipUpgrading') : t('env.pipUpgrade')}
|
||||
@@ -150,6 +151,7 @@ function Row({ row }: { row: EnvRow }) {
|
||||
void upgradePip(row.interpreter)
|
||||
}}
|
||||
data-action="upgrade-pip"
|
||||
data-destructive
|
||||
className="rounded-pd border border-warn px-3 py-1 text-data text-warn"
|
||||
>
|
||||
{t('env.pipUpgradeConfirm')}
|
||||
|
||||
@@ -253,6 +253,7 @@ export function PdHealth() {
|
||||
<button
|
||||
type="button"
|
||||
data-action="fix"
|
||||
data-destructive
|
||||
className="rounded-pd bg-danger px-3 py-1 text-data text-bg disabled:opacity-50"
|
||||
disabled={fixBusy}
|
||||
onClick={() => {
|
||||
|
||||
@@ -232,6 +232,7 @@ export function PdPlanPanel({ onFinished }: PdPlanPanelProps) {
|
||||
void cancel()
|
||||
}}
|
||||
disabled={cancelling}
|
||||
data-destructive
|
||||
className="rounded-pd border border-danger px-3 py-1 text-data text-danger disabled:opacity-40"
|
||||
>
|
||||
{cancelling ? t('plan.stopping') : t('plan.stop')}
|
||||
@@ -278,6 +279,9 @@ export function PdPlanPanel({ onFinished }: PdPlanPanelProps) {
|
||||
void execute()
|
||||
}}
|
||||
disabled={phase === 'resolving' || !confirmable}
|
||||
// Under the same condition as the danger treatment below, so high contrast — which
|
||||
// drops the colour — still tells this Confirm from an ordinary one (U45).
|
||||
data-destructive={isRollback || forced.length > 0 ? true : undefined}
|
||||
className={`rounded-pd border px-3 py-1 text-data disabled:border-border disabled:text-text-dim disabled:opacity-40 ${
|
||||
// A restore removes things and a forced plan breaks them. Both get the danger
|
||||
// treatment an ordinary update does not.
|
||||
|
||||
@@ -194,6 +194,7 @@ export function PdSettings() {
|
||||
void save({ allowExternallyManaged: true })
|
||||
}}
|
||||
data-action="allow-override"
|
||||
data-destructive
|
||||
className="rounded-pd border border-danger px-3 py-1 text-data text-danger"
|
||||
>
|
||||
{t('settings.overrideConfirm')}
|
||||
|
||||
+11
-7
@@ -151,17 +151,21 @@
|
||||
outline-offset: -2px;
|
||||
}
|
||||
|
||||
/* `page` is the sidebar's active tab. The rule matched `'true'` alone, so the one thing that
|
||||
* said which screen is showing was drawn like every other tab. */
|
||||
[aria-selected='true'],
|
||||
[aria-current='true'] {
|
||||
[aria-current='true'],
|
||||
[aria-current='page'] {
|
||||
outline: 1px solid Highlight;
|
||||
}
|
||||
|
||||
/* Destructive controls, which are otherwise indistinguishable once their tint is dropped. */
|
||||
button[data-action='force'],
|
||||
button[data-action='uninstall'],
|
||||
button[data-action='rollback'],
|
||||
button[data-action='upgrade-pip'],
|
||||
button[data-action='fix'] {
|
||||
/* 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user