Skip to content

Commit 1dbcbb2

Browse files
steipeteampagent
andauthored
fix(ui): keep segmented selections visible in forced colors (#127165)
* test(ui): cover segmented controls in forced colors Amp-Thread-ID: https://ampcode.com/threads/T-01a021f4-b547-7788-a916-d4a94cbd3e3b * fix(ui): preserve segmented selection in forced colors Amp-Thread-ID: https://ampcode.com/threads/T-01a021f4-b547-7788-a916-d4a94cbd3e3b * fix(ui): separate forced-color selection and focus Amp-Thread-ID: https://ampcode.com/threads/T-01a021f4-b547-7788-a916-d4a94cbd3e3b --------- Co-authored-by: Amp <[email protected]>
1 parent cb563bb commit 1dbcbb2

2 files changed

Lines changed: 120 additions & 0 deletions

File tree

‎ui/src/e2e/config-controls-visual.e2e.test.ts‎

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,114 @@ async function captureBrowserSettingProof(
108108
}
109109

110110
suite.define(() => {
111+
it("keeps selected segmented options distinct in forced colors", async () => {
112+
const cases = [
113+
{
114+
colorScheme: "dark" as const,
115+
config: { ui: { prefs: { themeMode: "dark" } } },
116+
featureMethods: undefined,
117+
route: "settings/appearance",
118+
selected: "Dark",
119+
unselected: "Light",
120+
},
121+
{
122+
colorScheme: "light" as const,
123+
config: { update: { auto: { enabled: true }, channel: "beta" } },
124+
featureMethods: ["config.get", "config.set", "config.apply", "update.run"],
125+
route: "settings/updates",
126+
selected: "Beta",
127+
unselected: "Stable",
128+
},
129+
];
130+
131+
for (const scenario of cases) {
132+
await suite.withPage(
133+
{
134+
colorScheme: scenario.colorScheme,
135+
forcedColors: "active",
136+
locale: "en-US",
137+
serviceWorkers: "block",
138+
viewport: { height: 900, width: 1280 },
139+
},
140+
async ({ page }) => {
141+
await installMockGateway(page, {
142+
featureMethods: scenario.featureMethods,
143+
methodResponses: {
144+
"config.get": {
145+
config: scenario.config,
146+
hash: `forced-colors-${scenario.route}`,
147+
issues: [],
148+
raw: JSON.stringify(scenario.config),
149+
runtimeConfig: scenario.config,
150+
valid: true,
151+
},
152+
},
153+
operatorScopes: ["operator.read", "operator.admin"],
154+
});
155+
156+
const response = await page.goto(`${suite.server.baseUrl}${scenario.route}`);
157+
expect(response?.status()).toBe(200);
158+
expect(await page.evaluate(() => matchMedia("(forced-colors: active)").matches)).toBe(
159+
true,
160+
);
161+
162+
const selected = page.getByRole("radio", { name: scenario.selected, exact: true });
163+
const unselected = page.getByRole("radio", { name: scenario.unselected, exact: true });
164+
await selected.waitFor();
165+
expect(await selected.getAttribute("aria-checked")).toBe("true");
166+
expect(await unselected.getAttribute("aria-checked")).toBe("false");
167+
if (captureUiProofEnabled) {
168+
await mkdir(uiProofArtifactDir, { recursive: true });
169+
await selected
170+
.locator(
171+
"xpath=ancestor::div[contains(concat(' ', normalize-space(@class), ' '), ' settings-row ')][1]",
172+
)
173+
.screenshot({
174+
animations: "disabled",
175+
path: path.join(
176+
uiProofArtifactDir,
177+
`segmented-forced-colors-${scenario.colorScheme}.png`,
178+
),
179+
});
180+
}
181+
expect(
182+
await selected.evaluate((element) => {
183+
const style = getComputedStyle(element);
184+
return {
185+
textDecorationLine: style.textDecorationLine,
186+
textDecorationThickness: style.textDecorationThickness,
187+
};
188+
}),
189+
).toEqual({ textDecorationLine: "underline", textDecorationThickness: "2px" });
190+
expect(
191+
await unselected.evaluate((element) => getComputedStyle(element).textDecorationLine),
192+
).toBe("none");
193+
194+
await selected.focus();
195+
expect(await selected.evaluate((element) => element.matches(":focus-visible"))).toBe(
196+
true,
197+
);
198+
expect(
199+
await selected.evaluate((element) => {
200+
const style = getComputedStyle(element);
201+
return {
202+
outlineOffset: style.outlineOffset,
203+
outlineStyle: style.outlineStyle,
204+
outlineWidth: style.outlineWidth,
205+
textDecorationLine: style.textDecorationLine,
206+
};
207+
}),
208+
).toEqual({
209+
outlineOffset: "2px",
210+
outlineStyle: "solid",
211+
outlineWidth: "2px",
212+
textDecorationLine: "underline",
213+
});
214+
},
215+
);
216+
}
217+
});
218+
111219
it("keeps checked switches on the scene accent on the security page", async () => {
112220
await suite.withPage(
113221
{

‎ui/src/styles/settings-controls.css‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@ wa-radio-group.settings-segmented::part(radios) {
9090
cursor: not-allowed;
9191
}
9292

93+
@media (forced-colors: active) {
94+
.settings-segmented__btn--active {
95+
text-decoration: underline 2px;
96+
text-underline-offset: 3px;
97+
}
98+
99+
.settings-segmented__btn:focus-visible {
100+
outline: 2px solid Highlight;
101+
outline-offset: 2px;
102+
}
103+
}
104+
93105
input.settings-input,
94106
select.settings-select:not([multiple]) {
95107
height: var(--settings-control-height);

0 commit comments

Comments
 (0)