Skip to content

Commit 53d5553

Browse files
committed
fix(control-ui): use Beacon's destructive foreground in chat confirmations
The chat confirmation button paints from --danger under --media-foreground, a theme-invariant white, and each dark palette opts out of that pairing through a selector list in chat/grouped.css. Beacon defines a deliberately light --danger (#ffabab, chosen so status labels clear AAA) but was missing from that list, so its confirm button rendered white on pale pink at 1.80:1 — on the theme whose entire promise is contrast. Adds Beacon to the list, which routes it to --destructive over --destructive-foreground at 11.67:1. Also adds a guardrail for the bug class, since the selector list has to be extended by hand for every new dark theme and I have now missed it once. The test reads membership back out of grouped.css rather than restating it, resolves each theme's effective (background, color) pair, and holds it to that theme's floor. It reproduces this defect at 1.80:1 against the pre-fix stylesheet. Reported by ClawSweeper review on #130232.
1 parent c53cbdd commit 53d5553

2 files changed

Lines changed: 72 additions & 2 deletions

File tree

‎ui/src/styles/base-theme-contrast.node.test.ts‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ const AA_NORMAL_TEXT_MIN = 4.5;
3838
* own floor is asserted separately.
3939
*/
4040
const AAA_NORMAL_TEXT_MIN = 7;
41+
42+
/*
43+
* The chat confirmation button defaults to --danger under --media-foreground,
44+
* which is a theme-invariant white, and every dark palette opts out of that
45+
* pairing through a selector list in chat/grouped.css. A theme with a light
46+
* --danger that is missing from the list therefore renders white on pale:
47+
* Beacon shipped that way at 1.80:1 until review caught it. Membership is read
48+
* back out of the stylesheet rather than restated here, so the list and the
49+
* palettes cannot drift apart again.
50+
*/
51+
const CONFIRM_BUTTON_RULE = ".chat-confirm-popover__yes";
4152
const AAA_THEMES = new Set(["beacon", "beacon-light"]);
4253

4354
/*
@@ -311,6 +322,41 @@ function readCodeChipTokens(chatTextCss: string): { surface: string; border: str
311322
return { surface, border };
312323
}
313324

325+
type ConfirmButtonPaint = { background: string; color: string };
326+
327+
function readConfirmButtonPaint(groupedCss: string): {
328+
base: ConfirmButtonPaint;
329+
overrides: Map<string, ConfirmButtonPaint>;
330+
} {
331+
const pattern = /([^{}]*\.chat-confirm-popover__yes(?![\w-])[^{}]*)\{([^}]*)\}/gu;
332+
let base: ConfirmButtonPaint | undefined;
333+
const overrides = new Map<string, ConfirmButtonPaint>();
334+
for (const match of groupedCss.matchAll(pattern)) {
335+
const selector = (match[1] ?? "").trim();
336+
const body = match[2] ?? "";
337+
if (selector.includes(":hover")) {
338+
continue;
339+
}
340+
const background = body.match(/background:\s*var\((--[\w-]+)\)/u)?.[1];
341+
const color = body.match(/color:\s*var\((--[\w-]+)\)/u)?.[1];
342+
if (!background || !color) {
343+
continue;
344+
}
345+
const themes = [...selector.matchAll(/\[data-theme="([^"]+)"\]/gu)].map((m) => m[1] ?? "");
346+
if (themes.length === 0) {
347+
base = { background, color };
348+
continue;
349+
}
350+
for (const theme of themes) {
351+
overrides.set(theme, { background, color });
352+
}
353+
}
354+
if (!base) {
355+
throw new Error(`could not read the base "${CONFIRM_BUTTON_RULE}" paint`);
356+
}
357+
return { base, overrides };
358+
}
359+
314360
function readRuleBody(css: string, selector: string): string {
315361
const body = css.split(`${selector} {`)[1]?.split("}")[0];
316362
if (body === undefined) {
@@ -416,6 +462,28 @@ describe("Control UI theme contrast", () => {
416462
expect(failures).toEqual([]);
417463
});
418464

465+
it("keeps the chat confirmation button legible on every theme", () => {
466+
const groupedCss = fs.readFileSync(path.join(stylesDir, "chat", "grouped.css"), "utf8");
467+
const { base, overrides } = readConfirmButtonPaint(groupedCss);
468+
const failures: string[] = [];
469+
for (const [themeName, tokens] of themes) {
470+
const paint = overrides.get(themeName) ?? base;
471+
const background = tokens.get(paint.background);
472+
const color = tokens.get(paint.color);
473+
if (!background?.startsWith("#") || !color?.startsWith("#")) {
474+
continue;
475+
}
476+
const ratio = contrastRatio(parseHex(color), parseHex(background));
477+
const floor = AAA_THEMES.has(themeName) ? AAA_NORMAL_TEXT_MIN : AA_NORMAL_TEXT_MIN;
478+
if (ratio < floor) {
479+
failures.push(
480+
`${themeName}: ${paint.color} ${color} on ${paint.background} ${background} = ${ratio.toFixed(2)}:1 (< ${floor}:1)`,
481+
);
482+
}
483+
}
484+
expect(failures).toEqual([]);
485+
});
486+
419487
it("keeps highlighted diff lines at WCAG AA on every code surface", () => {
420488
const componentsCss = fs.readFileSync(path.join(stylesDir, "components.css"), "utf8");
421489
const diffStyles = DIFF_SELECTORS.map((selector) => {

‎ui/src/styles/chat/grouped.css‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,7 +1181,8 @@ details.msg-meta:not([open]) .msg-meta__details {
11811181
:root[data-theme="dash"] .chat-confirm-popover__yes,
11821182
:root[data-theme="absolutely"] .chat-confirm-popover__yes,
11831183
:root[data-theme="tide"] .chat-confirm-popover__yes,
1184-
:root[data-theme="phosphor"] .chat-confirm-popover__yes {
1184+
:root[data-theme="phosphor"] .chat-confirm-popover__yes,
1185+
:root[data-theme="beacon"] .chat-confirm-popover__yes {
11851186
background: var(--destructive);
11861187
color: var(--destructive-foreground);
11871188
}
@@ -1198,7 +1199,8 @@ details.msg-meta:not([open]) .msg-meta__details {
11981199
:root[data-theme="dash"] .chat-confirm-popover__yes:hover,
11991200
:root[data-theme="absolutely"] .chat-confirm-popover__yes:hover,
12001201
:root[data-theme="tide"] .chat-confirm-popover__yes:hover,
1201-
:root[data-theme="phosphor"] .chat-confirm-popover__yes:hover {
1202+
:root[data-theme="phosphor"] .chat-confirm-popover__yes:hover,
1203+
:root[data-theme="beacon"] .chat-confirm-popover__yes:hover {
12021204
background: var(--destructive-hover);
12031205
}
12041206

0 commit comments

Comments
 (0)