Skip to content

Commit a010ffe

Browse files
authored
improve(ui): clarify picker selection and keyboard focus (#132018)
* improve(ui): clarify picker selection and keyboard focus * test(ui): observe renewed dashboard frame before sampling colors
1 parent cd19ee2 commit a010ffe

7 files changed

Lines changed: 170 additions & 39 deletions

‎ui/src/app/app-shell-chrome.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,8 @@ export class ShellChromeOwner {
499499
this.requestLazyElement(KEYBOARD_SHORTCUTS_ELEMENT, descriptor);
500500
};
501501

502-
/** Open overlays and editable controls own Escape before settings can exit. */
502+
// Open controls own Escape. Slotted options hide their listbox in shadow DOM,
503+
// so recognize the open select host before Settings can consume the key.
503504
shouldIgnoreSettingsEscape(event: KeyboardEvent): boolean {
504505
const host = this.host;
505506
const overlaySnapshot = host.context?.overlays.snapshot;
@@ -517,7 +518,7 @@ export class ShellChromeOwner {
517518
return (
518519
target instanceof Element &&
519520
target.closest(
520-
"input, textarea, select, [contenteditable], dialog, [role='dialog'], [role='menu'], [role='listbox']",
521+
"input, textarea, select, wa-select[open], [contenteditable], dialog, [role='dialog'], [role='menu'], [role='listbox']",
521522
) !== null
522523
);
523524
}

‎ui/src/e2e/board-mcp-app.e2e.test.ts‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,16 @@ describeControlUiE2e("Control UI dashboard MCP Apps", () => {
243243
await openDashboard(page);
244244
await expect
245245
.poll(async () => (await gateway.getRequests("board.widget.appView")).length, {
246-
timeout: 10_000,
246+
timeout: 15_000,
247247
})
248-
.toBeGreaterThan(0);
248+
.toBe(2);
249+
// Renewal replaces the iframe. The new-binding request follows teardown,
250+
// so wait for it before sampling the replacement's rendered background.
251+
await expect
252+
.poll(async () =>
253+
(await gateway.getRequests("mcp.app.view")).map((request) => request.params),
254+
)
255+
.toContainEqual({ sessionKey, viewId: "renewed-view" });
249256
await waitForMountedApp(page);
250257
const widgetBackgrounds = await page.evaluate(() => {
251258
const widgetElement = document.querySelector<HTMLElement>('[data-test-id="board-widget"]');
@@ -262,11 +269,6 @@ describeControlUiE2e("Control UI dashboard MCP Apps", () => {
262269
});
263270
expect(widgetBackgrounds.frame).toBe(widgetBackgrounds.widget);
264271
expect(widgetBackgrounds.frame).not.toBe("rgba(0, 0, 0, 0)");
265-
await expect
266-
.poll(async () => (await gateway.getRequests("board.widget.appView")).length, {
267-
timeout: 15_000,
268-
})
269-
.toBe(2);
270272
expect((await gateway.getRequests("board.widget.appView"))[0]?.params).toEqual({
271273
sessionKey,
272274
name: "app-0",

‎ui/src/e2e/channel-wizard-option-contrast.e2e.test.ts‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const proofDirectory = path.join(
2020
);
2121

2222
suite.define(() => {
23-
it("keeps active option subtext as legible as its label", async () => {
23+
it("keeps option subtext legible and keyboard focus visible in forced colors", async () => {
2424
await suite.withPage(
2525
{
2626
colorScheme: "dark",
@@ -29,7 +29,7 @@ suite.define(() => {
2929
viewport: { height: 900, width: 1280 },
3030
},
3131
async ({ page }) => {
32-
await installMockGateway(page, {
32+
const gateway = await installMockGateway(page, {
3333
featureMethods: ["channels.status", "channels.pairing.list", "wizard.start"],
3434
methodResponses: {
3535
"channels.status": {
@@ -114,6 +114,23 @@ suite.define(() => {
114114
}
115115

116116
expect(colors.description).toBe(colors.label);
117+
118+
await page.emulateMedia({ forcedColors: "active" });
119+
await page.keyboard.press("ArrowDown");
120+
const nextOption = picker.getByRole("option", { name: "Add another iMessage account" });
121+
await expect
122+
.poll(() => nextOption.evaluate((option) => option.matches(":focus-visible")))
123+
.toBe(true);
124+
expect(
125+
await nextOption.evaluate((option) => {
126+
const style = getComputedStyle(option);
127+
return style.outlineStyle !== "none" && Number.parseFloat(style.outlineWidth) >= 2;
128+
}),
129+
).toBe(true);
130+
expect(await activeOption.getAttribute("aria-selected")).toBe("true");
131+
await page.keyboard.press("Enter");
132+
const answer = await gateway.waitForRequest("wizard.next");
133+
expect(answer.params).toMatchObject({ answer: { value: "another" } });
117134
},
118135
);
119136
});

‎ui/src/e2e/sidebar-settings.e2e.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,40 @@ import {
1212
const suite = createSidebarCustomizationSuite("Control UI sidebar settings mocked Gateway E2E");
1313

1414
suite.define(() => {
15+
it("dismisses an open font picker before exiting Settings with Escape", async () => {
16+
const context = await suite.newBrowserContext({
17+
locale: "en-US",
18+
serviceWorkers: "block",
19+
viewport: { height: 900, width: 1440 },
20+
});
21+
const page = await context.newPage();
22+
await installMockGateway(page);
23+
try {
24+
await page.goto(`${suite.server.baseUrl}new`);
25+
await page.locator(".new-session-page__message").waitFor({ state: "visible" });
26+
await page.keyboard.press("Control+Shift+,");
27+
const { sidebar } = await waitForControlUiSettingsTakeover(page);
28+
const picker = page.locator("#settings-font-chat");
29+
await picker.click();
30+
const selected = picker.locator("wa-option:state(selected)");
31+
await selected.waitFor({ state: "visible" });
32+
const selectedValue = await selected.getAttribute("value");
33+
await page.keyboard.press("ArrowDown");
34+
await page.keyboard.press("Escape");
35+
await expect.poll(() => new URL(page.url()).pathname).toBe("/settings/appearance");
36+
await expect.poll(() => picker.getAttribute("open")).toBeNull();
37+
expect(await selected.getAttribute("value")).toBe(selectedValue);
38+
expect(
39+
await picker.locator('input[role="combobox"]').evaluate((input) => input.matches(":focus")),
40+
).toBe(true);
41+
await sidebar.locator(".settings-sidebar__item").first().focus();
42+
await page.keyboard.press("Escape");
43+
await expect.poll(() => new URL(page.url()).pathname).toBe("/new");
44+
} finally {
45+
await suite.closeBrowserContext(context);
46+
}
47+
});
48+
1549
it.each([
1650
{ state: "ready", pending: false, focusSearch: false },
1751
{ state: "pending with trigger focus", pending: true, focusSearch: false },

‎ui/src/e2e/theme-muted-contrast.e2e.test.ts‎

Lines changed: 89 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { mkdir, writeFile } from "node:fs/promises";
22
import path from "node:path";
33
import { expect, it } from "vitest";
4+
import { finishElementAnimations } from "../test-helpers/animations.ts";
45
import { controlUiBundledGatewayUrl, installMockGateway } from "../test-helpers/control-ui-e2e.ts";
56
import { createControlUiE2eSuite } from "./control-ui-e2e-suite.test-support.ts";
67

@@ -41,9 +42,10 @@ const surfaceTokens = ["--bg", "--bg-elevated", "--bg-muted", "--card", "--panel
4142
function themeConfigResponse(
4243
family: "claw" | "knot" | "dash" | "absolutely" | "tide" | "beacon" | "phosphor",
4344
mode: "dark" | "light",
45+
accent?: string,
4446
) {
4547
const config = {
46-
ui: { prefs: { ...(family === "claw" ? {} : { theme: family }), themeMode: mode } },
48+
ui: { prefs: { ...(family === "claw" ? {} : { theme: family }), themeMode: mode, accent } },
4749
};
4850
const hash = `theme-contrast-${family}-${mode}`;
4951
return {
@@ -82,9 +84,15 @@ function parseRenderedColor(color: string): RenderedColor {
8284
/^rgba?\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)(?:\s*,\s*(\d*\.?\d+))?\s*\)$/u.exec(
8385
trimmed,
8486
);
85-
if (rgb) {
86-
const [red, green, blue] = rgb.slice(1, 4).map(Number);
87-
const alpha = rgb[4] === undefined ? 1 : Number(rgb[4]);
87+
const srgb = /^color\(srgb\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)(?:\s*\/\s*([\d.]+))?\s*\)$/u.exec(
88+
trimmed,
89+
);
90+
const rendered = rgb ?? srgb;
91+
if (rendered) {
92+
const [red, green, blue] = rendered
93+
.slice(1, 4)
94+
.map((value) => Number(value) * (srgb ? 255 : 1));
95+
const alpha = rendered[4] === undefined ? 1 : Number(rendered[4]);
8896
if (
8997
red !== undefined &&
9098
green !== undefined &&
@@ -144,9 +152,18 @@ const suite = createControlUiE2eSuite({
144152
});
145153

146154
suite.define(() => {
147-
it.each(themeCases)(
148-
"keeps the real $resolved appearance selection at WCAG AA",
149-
async ({ family, mode, resolved }) => {
155+
it.each(
156+
themeCases.flatMap(({ family, mode, resolved }) =>
157+
(family === "claw" ? [undefined, "#000000", "#ffffff"] : [undefined]).map((accent) => ({
158+
family,
159+
mode,
160+
resolved,
161+
accent,
162+
})),
163+
),
164+
)(
165+
"keeps $resolved appearance and picker states legible (accent $accent)",
166+
async ({ family, mode, resolved, accent }) => {
150167
const context = await suite.newBrowserContext({
151168
colorScheme: mode,
152169
locale: "en-US",
@@ -171,7 +188,7 @@ suite.define(() => {
171188
const page = await context.newPage();
172189
const gateway = await installMockGateway(page, {
173190
methodResponses: {
174-
"config.get": themeConfigResponse(initialFamily, mode),
191+
"config.get": themeConfigResponse(initialFamily, mode, accent),
175192
},
176193
});
177194

@@ -183,7 +200,7 @@ suite.define(() => {
183200
await selectedCard.waitFor({ state: "visible" });
184201
await gateway.waitForRequest("config.get");
185202
const initialConfigGets = (await gateway.getRequests("config.get")).length;
186-
const committed = themeConfigResponse(family, mode);
203+
const committed = themeConfigResponse(family, mode, accent);
187204
await gateway.deferNext("config.patch");
188205
await selectedCard.click();
189206
const patch = await gateway.waitForRequest("config.patch");
@@ -290,17 +307,78 @@ suite.define(() => {
290307
`${resolved}: actual rendered muted Appearance description, including ancestor backgrounds and opacity`,
291308
).toBeGreaterThanOrEqual(4.5);
292309

310+
const picker = page.locator("#settings-font-chat");
311+
await picker.click();
312+
const selected = picker.locator("wa-option:state(selected)");
313+
await selected.waitFor({ state: "visible" });
314+
const optionPaint = async (option: typeof selected) => {
315+
await option.evaluate(finishElementAnimations);
316+
return option.evaluate((element) => {
317+
const style = getComputedStyle(element);
318+
return {
319+
background: style.backgroundColor,
320+
label: getComputedStyle(element.querySelector(".picker-select__label")!).color,
321+
description: getComputedStyle(element.querySelector(".picker-select__description")!)
322+
.color,
323+
outline: style.outlineStyle,
324+
outlineWidth: Number.parseFloat(style.outlineWidth),
325+
outlineColor: style.outlineColor,
326+
};
327+
});
328+
};
329+
// Options are slotted into a shadow listbox: light-DOM ancestors miss its painted surface.
330+
const listboxBackground = await picker
331+
.locator('[part="listbox"]')
332+
.evaluate((element) => getComputedStyle(element).backgroundColor);
333+
const assertOptionContrast = async (option: typeof selected) => {
334+
const paint = await optionPaint(option);
335+
const background = compositeColor(
336+
parseRenderedColor(paint.background),
337+
parseRenderedColor(listboxBackground),
338+
);
339+
for (const text of [paint.label, paint.description]) {
340+
expect(
341+
contrastRatio(text, background),
342+
`${resolved} picker text`,
343+
).toBeGreaterThanOrEqual(4.5);
344+
}
345+
return { paint, background };
346+
};
347+
const selectedValue = await selected.getAttribute("value");
348+
const initialPaint = await optionPaint(selected);
349+
await page.keyboard.press("ArrowDown");
350+
const current = picker.locator("wa-option:state(current)");
351+
await expect.poll(() => current.getAttribute("value")).not.toBe(selectedValue);
352+
expect(await selected.getAttribute("value")).toBe(selectedValue);
353+
await expect
354+
.poll(async () => (await optionPaint(selected)).background)
355+
.toBe(initialPaint.background);
356+
await assertOptionContrast(selected);
357+
const focused = await assertOptionContrast(current);
358+
expect(focused.paint.outline).not.toBe("none");
359+
expect(focused.paint.outlineWidth).toBeGreaterThanOrEqual(2);
360+
expect(
361+
contrastRatio(focused.paint.outlineColor, focused.background),
362+
).toBeGreaterThanOrEqual(3);
363+
await picker.locator('wa-option[value="system"]').hover();
364+
await assertOptionContrast(picker.locator('wa-option[value="system"]'));
365+
await page.keyboard.press("Escape");
366+
expect(new URL(page.url()).pathname).toBe("/settings/appearance");
367+
expect(await selected.getAttribute("value")).toBe(selectedValue);
368+
293369
if (captureUiProof) {
294370
await mkdir(proofDirectory, { recursive: true });
371+
const proofName = accent ? `${resolved}-${accent.slice(1)}` : resolved;
295372
await page.screenshot({
296373
animations: "disabled",
297374
fullPage: true,
298-
path: path.join(proofDirectory, `${resolved}.png`),
375+
path: path.join(proofDirectory, `${proofName}.png`),
299376
});
300377
await writeFile(
301-
path.join(proofDirectory, `${resolved}.json`),
378+
path.join(proofDirectory, `${proofName}.json`),
302379
`${JSON.stringify(
303380
{
381+
accent,
304382
description: {
305383
background: descriptionBackground,
306384
contrast: Number(descriptionContrast.toFixed(3)),

‎ui/src/styles/select-picker.css‎

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
wa-select.settings-select {
2-
--wa-form-control-activated-color: var(--primary);
3-
}
4-
51
wa-select.settings-select::part(combobox) {
62
min-height: var(--settings-control-height);
73
padding-inline: 10px;
@@ -42,25 +38,30 @@ wa-select.settings-select::part(listbox) {
4238
}
4339

4440
wa-select.settings-select wa-option {
41+
--wa-form-control-activated-color: var(--bg-hover);
42+
--wa-color-neutral-fill-normal: var(--bg-hover);
43+
4544
padding: 6px 8px;
4645
border-radius: calc(var(--radius-md) - 4px);
4746
font-size: var(--control-ui-text-md);
4847
color: var(--text);
4948
cursor: var(--cursor-action);
5049
}
5150

52-
/* The roving "current" option already carries the accent fill; the global
53-
:focus-visible accent outline on top of it is pure noise. */
51+
/* Selection stays visible while keyboard focus moves. Text-backed focus ink
52+
also remains visible with black/white custom accents. */
5453
wa-select.settings-select wa-option:focus-visible {
55-
outline: none;
54+
outline: 2px solid var(--text);
55+
outline-offset: -2px;
5656
}
5757

58-
wa-select.settings-select wa-option:state(current) {
59-
color: var(--primary-foreground);
58+
wa-select.settings-select wa-option:state(selected) {
59+
background: color-mix(in srgb, var(--accent) 12%, var(--bg-elevated));
60+
box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 60%, transparent);
6061
}
6162

62-
.picker-select__option {
63-
color: var(--text);
63+
wa-select.settings-select wa-option::part(checked-icon) {
64+
color: color-mix(in srgb, var(--text) 80%, var(--accent));
6465
}
6566

6667
.picker-select [slot="start"] {
@@ -85,14 +86,14 @@ wa-select.settings-select wa-option:state(current) {
8586
.picker-select__description {
8687
min-width: 0;
8788
overflow: hidden;
88-
color: var(--muted);
89+
color: color-mix(in srgb, var(--muted) 80%, var(--text));
8990
font-size: 0.75rem;
9091
line-height: 1.2;
9192
text-overflow: ellipsis;
9293
white-space: normal;
9394
}
9495

95-
.picker-select__option:state(current) .picker-select__description {
96+
.picker-select__option:is(:state(current), :state(selected)) .picker-select__description {
9697
color: inherit;
9798
}
9899

@@ -117,8 +118,7 @@ wa-select.settings-select wa-option:state(current) {
117118
display: none;
118119
}
119120

120-
/* Forced colors suppresses the box-shadow ring and accent fill that stand in
121-
for the outlines removed above, so restore system-color outlines there. */
121+
/* System colors replace decorative fills/shadows; keep keyboard focus explicit. */
122122
@media (forced-colors: active) {
123123
wa-select.settings-select[open]::part(combobox),
124124
wa-select.settings-select:focus-within::part(combobox) {
@@ -128,6 +128,5 @@ wa-select.settings-select wa-option:state(current) {
128128

129129
wa-select.settings-select wa-option:focus-visible {
130130
outline: 2px solid SelectedItem;
131-
outline-offset: 2px;
132131
}
133132
}

‎ui/src/styles/settings.css‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* One structural pattern for every settings surface:
44
* .settings-page > .settings-section > .settings-group > .settings-row
55
*
6-
* Rules (see ui/docs/settings-design.md):
6+
* Rules (see ui/docs/design-system/settings-design.md):
77
* - Sections are typography (heading outside any surface), not chrome.
88
* - Exactly one level of elevation: the group. Never nest a card in a group.
99
* - Status is a dot + plain text, never a colored pill.

0 commit comments

Comments
 (0)