Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

MUL-9052 fix(theme): check rail item contrast in modes without frame rules (#10380)

Jiayuan Zhangcfb2e7c87e6a
diff --git a/docs/theming.md b/docs/theming.md
index 1f499d3fc1..20a4696bb3 100644
--- a/docs/theming.md
+++ b/docs/theming.md
@@ -316,6 +316,16 @@ names the value it comes from, for example
(`color`, `variable-select`, `number`, `slider`, `text`, `font`) are measured
at their defaults only, so check the other values you offer yourself.
+Rail items are measured the way the rail paints them: `--rail-item-color`
+on `--app-shell` at rest, and `--rail-item-active-color` on
+`--rail-item-active-background` (the current space) and on
+`--rail-item-hover-background`, each with the fallback in the
+[reference](#variable-reference) when it is not set. The default hover fill
+is `--sidebar-accent` at 60% over `--app-shell`, and it is measured that way.
+When a mode has frame rules, the rail takes the frame's colours and a failure
+reads `Contrast, dark mode (frame): …`; without them it takes the page's
+colours and reads `Contrast, light mode: …`, like the other page pairs.
+
Contrast covers the page, the frame, and two places a theme reaches only
indirectly:
diff --git a/packages/core/appearance/theme-check.test.ts b/packages/core/appearance/theme-check.test.ts
index 73555ce9d7..651e125034 100644
--- a/packages/core/appearance/theme-check.test.ts
+++ b/packages/core/appearance/theme-check.test.ts
@@ -377,6 +377,34 @@ describe("theme check", () => {
expect.stringMatching(/^Contrast, light mode \(frame, Frame = Ink\): --rail-item-active-color is below 4\.5:1/),
]);
});
+
+ describe("without frame rules", () => {
+ // MS-DOS 1.2.0, light: white on a blue active item, but the default hover is a pale --sidebar-accent wash.
+ const dos = ".theme-light { --rail-item-active-background: #0000aa; --rail-item-active-color: #ffffff; }";
+
+ it("measures the rail on the page's colours", () => {
+ expect(errors(dos)).toEqual([
+ expect.stringMatching(/^Contrast, light mode: --rail-item-active-color is below 4\.5:1 on --rail-item-hover-background \(1\.\d\d:1\)\.$/),
+ ]);
+ expect(check(`${dos}\n.theme-light { --rail-item-hover-background: #0000aa; }`)).toMatchObject({ ok: true, issues: [] });
+ const rail = check(dos).contrast.filter((c) => c.mode === "light" && c.foreground === "--rail-item-active-color");
+ expect(rail.map((c) => [c.area, c.background])).toEqual([
+ ["page", "--rail-item-active-background"],
+ ["page", "--rail-item-hover-background"],
+ ]);
+ });
+
+ it("falls back to --sidebar-accent-foreground on --sidebar-accent", () => {
+ expect(errors(".theme-dark { --sidebar-accent-foreground: #333333; }")).toEqual([
+ expect.stringMatching(
+ /^Contrast, dark mode: --sidebar-accent-foreground is below 4\.5:1 on --sidebar-accent \(1\.\d\d:1\) and --rail-item-hover-background \(1\.\d\d:1\)\.$/,
+ ),
+ ]);
+ expect(errors(".theme-light { --rail-item-color: #dddddd; }")).toEqual([
+ expect.stringMatching(/^Contrast, light mode: --rail-item-color is below 4\.5:1 on --app-shell/),
+ ]);
+ });
+ });
});
it("warns instead of guessing when a colour cannot be read", () => {
diff --git a/packages/core/appearance/theme-check.ts b/packages/core/appearance/theme-check.ts
index b3405cd560..4a1c218ea3 100644
--- a/packages/core/appearance/theme-check.ts
+++ b/packages/core/appearance/theme-check.ts
@@ -517,6 +517,34 @@ function measureContrast(
});
}
};
+ // Rail items read their own variables, with the fallbacks in theme-variables.css:
+ // the label on the shell at rest, and the active colour on the active and hover fills.
+ const measureRail = (area: ContrastCheck["area"], p: Map<string, string>) => {
+ if (p.has("--rail-item-color")) measure(area, p, "--rail-item-color", ["--app-shell"], TEXT);
+ const railText = p.has("--rail-item-active-color") ? "--rail-item-active-color" : "--sidebar-accent-foreground";
+ const railSurfaces = [p.has("--rail-item-active-background") ? "--rail-item-active-background" : "--sidebar-accent"];
+ if (p.has("--rail-item-hover-background")) railSurfaces.push("--rail-item-hover-background");
+ else {
+ // The default hover is --sidebar-accent at 60% over the shell.
+ const accent = resolveColor(p, "--sidebar-accent");
+ const shell = resolveColor(p, "--app-shell");
+ if ("color" in accent && "color" in shell && shell.color.a === 1) {
+ const { r, g, b } = paintOver({ ...accent.color, a: accent.color.a * 0.6 }, shell.color);
+ p.set("--rail-item-hover-background", `rgb(${r} ${g} ${b})`);
+ railSurfaces.push("--rail-item-hover-background");
+ }
+ }
+ // The frame measures --sidebar-accent-foreground on --sidebar-accent for its other controls.
+ measure(
+ area,
+ p,
+ railText,
+ railSurfaces.filter(
+ (surface) => area !== "frame" || railText !== "--sidebar-accent-foreground" || surface !== "--sidebar-accent",
+ ),
+ TEXT,
+ );
+ };
const hasFrame = frame[m].length > 0;
const backgrounds = hasFrame ? BACKGROUNDS.filter((b) => b !== "--app-shell") : BACKGROUNDS;
measure("page", palette, "--foreground", backgrounds, TEXT);
@@ -535,31 +563,10 @@ function measureContrast(
measure("frame", framePalette, "--faint-foreground", FRAME_BACKGROUNDS, NON_TEXT);
// Toolbar and layout buttons paint --sidebar-accent-foreground on --sidebar-accent on hover.
measure("frame", framePalette, "--sidebar-accent-foreground", ["--sidebar-accent"], TEXT);
- // Rail items read their own variables, with the fallbacks in theme-variables.css:
- // the label on the shell at rest, and the active colour on the active and hover fills.
- if (framePalette.has("--rail-item-color")) measure("frame", framePalette, "--rail-item-color", ["--app-shell"], TEXT);
- const railText = framePalette.has("--rail-item-active-color") ? "--rail-item-active-color" : "--sidebar-accent-foreground";
- const railSurfaces = [
- framePalette.has("--rail-item-active-background") ? "--rail-item-active-background" : "--sidebar-accent",
- ];
- if (framePalette.has("--rail-item-hover-background")) railSurfaces.push("--rail-item-hover-background");
- else {
- // The default hover is --sidebar-accent at 60% over the shell.
- const accent = resolveColor(framePalette, "--sidebar-accent");
- const shell = resolveColor(framePalette, "--app-shell");
- if ("color" in accent && "color" in shell && shell.color.a === 1) {
- const { r, g, b } = paintOver({ ...accent.color, a: accent.color.a * 0.6 }, shell.color);
- framePalette.set("--rail-item-hover-background", `rgb(${r} ${g} ${b})`);
- railSurfaces.push("--rail-item-hover-background");
- }
- }
- measure(
- "frame",
- framePalette,
- railText,
- railSurfaces.filter((surface) => railText !== "--sidebar-accent-foreground" || surface !== "--sidebar-accent"),
- TEXT,
- );
+ measureRail("frame", framePalette);
+ } else {
+ // Without frame rules the rail sits on the page's own colours.
+ measureRail("page", new ReadTracker(read, palette));
}
// The tooltip is a `.dark` scope in both modes: its text takes the app's