Skip to content

Commit 6c48584

Browse files
fix(ui): calm composer focus treatment (#122232)
1 parent 7a1d5a8 commit 6c48584

2 files changed

Lines changed: 90 additions & 2 deletions

File tree

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { expect, it } from "vitest";
2+
import { installMockGateway } from "../test-helpers/control-ui-e2e.ts";
3+
import { createControlUiE2eSuite } from "./control-ui-e2e-suite.test-support.ts";
4+
5+
const suite = createControlUiE2eSuite({
6+
name: "Control UI chat composer focus",
7+
});
8+
9+
suite.define(() => {
10+
it("uses a visible neutral focus treatment in dark and light themes", async () => {
11+
await suite.withPage({ viewport: { width: 1440, height: 900 } }, async ({ page }) => {
12+
const gateway = await installMockGateway(page);
13+
await page.goto(`${suite.server.baseUrl}chat`);
14+
await gateway.waitForRequest("chat.startup");
15+
16+
const composer = page.locator(".agent-chat__input");
17+
const textarea = composer.locator("textarea");
18+
await composer.waitFor({ state: "visible" });
19+
20+
for (const theme of ["dark", "light"] as const) {
21+
await page.evaluate((nextTheme) => {
22+
document.documentElement.dataset.theme = "claw";
23+
document.documentElement.dataset.themeMode = nextTheme;
24+
}, theme);
25+
await textarea.evaluate((element) => element.blur());
26+
await page.waitForTimeout(150);
27+
const unfocused = await composer.evaluate((element) => {
28+
const style = getComputedStyle(element);
29+
return { borderColor: style.borderColor, boxShadow: style.boxShadow };
30+
});
31+
32+
await textarea.focus();
33+
await page.waitForTimeout(150);
34+
const focused = await composer.evaluate((element) => {
35+
const style = getComputedStyle(element);
36+
const parseRgb = (color: string): [number, number, number] => {
37+
const values = color
38+
.match(/[\d.]+/g)
39+
?.slice(0, 3)
40+
.map(Number);
41+
if (!values || values.length !== 3) {
42+
throw new Error(`expected an RGB color, received ${color}`);
43+
}
44+
return (
45+
color.startsWith("color(srgb") ? values.map((value) => value * 255) : values
46+
) as [number, number, number];
47+
};
48+
const luminance = (color: string): number => {
49+
const linearize = (channel: number) => {
50+
const normalized = channel / 255;
51+
return normalized <= 0.04045
52+
? normalized / 12.92
53+
: ((normalized + 0.055) / 1.055) ** 2.4;
54+
};
55+
const channels = parseRgb(color);
56+
return (
57+
0.2126 * linearize(channels[0]) +
58+
0.7152 * linearize(channels[1]) +
59+
0.0722 * linearize(channels[2])
60+
);
61+
};
62+
const borderLuminance = luminance(style.borderColor);
63+
const surfaceLuminance = luminance(style.backgroundColor);
64+
const borderChannels = parseRgb(style.borderColor);
65+
const contrast =
66+
(Math.max(borderLuminance, surfaceLuminance) + 0.05) /
67+
(Math.min(borderLuminance, surfaceLuminance) + 0.05);
68+
69+
return {
70+
borderColor: style.borderColor,
71+
boxShadow: style.boxShadow,
72+
contrast,
73+
neutralChannelSpread: Math.max(...borderChannels) - Math.min(...borderChannels),
74+
};
75+
});
76+
77+
expect(focused.borderColor).not.toBe(unfocused.borderColor);
78+
expect(focused.boxShadow).not.toBe(unfocused.boxShadow);
79+
expect(focused.neutralChannelSpread).toBeLessThanOrEqual(24);
80+
expect(focused.contrast).toBeGreaterThanOrEqual(3);
81+
}
82+
});
83+
});
84+
});

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2358,8 +2358,12 @@ openclaw-chat-video-player {
23582358
}
23592359

23602360
.agent-chat__input:focus-within {
2361-
border-color: color-mix(in srgb, var(--accent) 30%, var(--border));
2362-
box-shadow: 0 0 0 3px var(--accent-subtle);
2361+
/* Focus is a neutral state, not an accent/status signal. This mix clears 3:1
2362+
against the composer surface in both claw themes; the halo keeps it legible. */
2363+
border-color: color-mix(in srgb, var(--muted) 72%, var(--border));
2364+
box-shadow:
2365+
0 0 0 3px color-mix(in srgb, var(--muted) 14%, transparent),
2366+
var(--shadow-sm);
23632367
}
23642368

23652369
.agent-chat__input--prefill-attention {

0 commit comments

Comments
 (0)