Skip to content
TypeScript

fix(web): keep theme placeholder text dimmer than entered text (#9104)

oliverd0b4acbd13b2
diff --git a/apps/web/src/themePalette.test.ts b/apps/web/src/themePalette.test.ts
index 6c0718e2f1a..562ebc26376 100644
--- a/apps/web/src/themePalette.test.ts
+++ b/apps/web/src/themePalette.test.ts
@@ -157,6 +157,9 @@ describe("theme files", () => {
expect(contrastRatio(colors.textMuted, colors.canvas)).toBeLessThan(5.5);
expect(contrastRatio(colors.mutedForeground, colors.muted)).toBeGreaterThanOrEqual(4.5);
expect(contrastRatio(colors.placeholder, colors.surfaceRaised)).toBeGreaterThanOrEqual(4.5);
+ expect(contrastRatio(colors.placeholder, colors.surfaceRaised)).toBeLessThan(
+ contrastRatio(colors.text, colors.surfaceRaised),
+ );
expect(colors.secondaryLabel).toBe(colors.textMuted);
expect(contrastRatio(colors.accentForeground, colors.accent)).toBeGreaterThanOrEqual(4.5);
expect(
diff --git a/apps/web/src/themePalette.ts b/apps/web/src/themePalette.ts
index 289082efef0..458d4539e27 100644
--- a/apps/web/src/themePalette.ts
+++ b/apps/web/src/themePalette.ts
@@ -917,7 +917,7 @@ export function createVividThemeColors(
solveOklchLightness(textBase, surfaceRgb, 4.6, dark ? "lighter" : "darker"),
);
const mutedForeground = foregroundOn(mutedRgb);
- const placeholder = foregroundOn(surfaceRaisedRgb);
+ const placeholder = themeRgbToThemeColor(readableThemeText(surfaceRaisedRgb, textRgb, 1, 4.6));
const actionHover: ThemeOklch = { ...action, L: action.L + (dark ? 0.06 : -0.06) };
diff --git a/apps/web/src/vscodeThemeImport.test.ts b/apps/web/src/vscodeThemeImport.test.ts
index e4fcdb907ab..59f732bf4a1 100644
--- a/apps/web/src/vscodeThemeImport.test.ts
+++ b/apps/web/src/vscodeThemeImport.test.ts
@@ -90,6 +90,28 @@ describe("VS Code theme import", () => {
expect(theme.colors.sidebarRowSelected).not.toBe(theme.colors.sidebar);
});
+ it("keeps a fallback placeholder dimmer than entered text", () => {
+ const theme = parseVsCodeThemeFile({
+ name: "Dark placeholder fallback",
+ type: "dark",
+ colors: {
+ "editor.background": "#1e1e2e",
+ "editor.foreground": "#cdd6f4",
+ "input.placeholderForeground": "#cdd6f473",
+ },
+ });
+
+ expect(
+ contrastRatio(theme.colors.placeholder, theme.colors.surfaceRaised),
+ ).toBeGreaterThanOrEqual(4.5);
+ expect(contrastRatio(theme.colors.placeholder, theme.colors.canvas)).toBeGreaterThanOrEqual(
+ 4.5,
+ );
+ expect(contrastRatio(theme.colors.placeholder, theme.colors.canvas)).toBeLessThan(
+ contrastRatio(theme.colors.text, theme.colors.canvas),
+ );
+ });
+
it("fills every role the file omits with a readable derived value", () => {
const theme = parseVsCodeThemeFile(VSCODE_DARK);
const colors = getThemeColorsForMode(theme, "dark")!;