Fix illegible text on hovered Spotlight results in high-contrast theme (#34465)

* Fix illegible text on hovered Spotlight results in high-contrast theme

* Update Spotlight tests to use Axe for accessibility checks instead of custom contrast ratio calculations

* Refactor Spotlight accessibility tests to cover all themes and improve legibility checks across various UI elements

* Remove high-contrast theme from Spotlight legibility tests to streamline accessibility checks

* Fix invalid CSS comment breaking Oxfmt and scope out unrelated axe violation

_SpotlightDialog.pcss used // line comments, which are not valid CSS and
crashed the Oxfmt parser, causing spurious failures in Oxfmt and the
Static Analysis gate. Switched to a block comment.

The new Spotlight legibility test's broad axe scans also caught a
pre-existing nested-interactive violation (endAdornment buttons nested
inside clickable option rows), unrelated to the colour-contrast fix.
Scoped it out with axe.disableRules("nested-interactive") to keep the
contrast checks active without failing on the unrelated issue.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* Update Room Directory screenshot baseline for Spotlight hover-color fix

The high-contrast legibility fix changes hover/selected text color in
Spotlight results, which is reflected in the Room Directory dialog
screenshot test.

* Use CI-rendered baseline for the Room Directory screenshot

The previous baseline still had the pre-fix colours for
.mx_SpotlightDialog_result_publicRoomAlias and
.mx_SpotlightDialog_result_publicRoomDescription, so the Linux CI run
reported a 418px diff on filtered-one-result.png. Replace it with the
image the Linux CI runner actually produced with the fix applied.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* Retrigger CI (transient Electron install failure in Vitest job)

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Prince Panchani
2026-08-13 14:27:35 +00:00
committed by GitHub
parent 366dd99b4d
commit 8df56706b5
4 changed files with 83 additions and 12 deletions
@@ -13,6 +13,7 @@ import { Bot } from "../../pages/bot";
import type { Locator, Page } from "@playwright/test";
import type { ElementAppPage } from "../../pages/ElementAppPage";
import { isDendrite } from "../../plugins/homeserver/dendrite";
import { SettingLevel } from "../../../src/settings/SettingLevel";
function roomHeaderName(page: Page): Locator {
return page.locator(".mx_RoomHeader_heading");
@@ -399,4 +400,65 @@ test.describe("Spotlight", () => {
await expect(resultLocator.first()).toHaveAttribute("aria-selected", "true");
await expect(resultLocator.last()).toHaveAttribute("aria-selected", "false");
});
for (const theme of ["light", "dark", "light-high-contrast"]) {
test.describe(`${theme} theme legibility`, () => {
// Regression tests for https://github.com/element-hq/element-web/issues/34213
// Hovered/selected Spotlight results must not render light text on a light
// background (or vice versa) in any theme, not just high contrast ones.
test.beforeEach(async ({ app }) => {
await app.settings.setValue("use_system_theme", null, SettingLevel.DEVICE, false);
await app.settings.setValue("theme", null, SettingLevel.ACCOUNT, theme);
});
test("should have legible text across Spotlight surfaces", async ({ page, app, room1, axe }) => {
// room1 is already open (see room1 fixture); navigate away from it so it
// shows up in the "recently viewed" section (the current room is excluded from it).
await page.goto("/#/home");
await expect(page.locator(".mx_RoomSublist_skeletonUI")).not.toBeAttached();
const spotlight = await app.openSpotlight();
// Wait for the dialog to settle: the search box is only focused once the
// open animation has finished and results have had a chance to render.
await expect(spotlight.searchBox.getByRole("textbox", { name: "Search" })).toBeFocused();
// #mx_SpotlightDialog_keyboardPrompt is a sibling of the [role=dialog] element,
// not a descendant, so it must be located from the page rather than spotlight.dialog.
const kbdHint = page.locator("#mx_SpotlightDialog_keyboardPrompt kbd").first();
await expect(kbdHint).toBeAttached();
const recentlyViewed = spotlight.dialog.locator(
".mx_SpotlightDialog_recentlyViewed .mx_SpotlightDialog_option",
);
await expect(recentlyViewed.first()).toBeAttached();
await recentlyViewed.first().hover();
axe.include("#mx_SpotlightDialog_keyboardPrompt");
axe.include(".mx_SpotlightDialog_recentlyViewed .mx_SpotlightDialog_option");
// XXX: Result rows nest a focusable endAdornment (here, RoomResultContextMenus) inside
// the option row itself, which is a pre-existing structural issue unrelated to the
// colour-contrast regression under test here.
axe.disableRules("nested-interactive");
await expect(axe).toHaveNoViolations();
await spotlight.filter(Filter.PublicRooms);
await spotlight.search(room1.name);
const filterChip = spotlight.dialog.locator(".mx_SpotlightDialog_filter");
await expect(filterChip).toHaveText("Public rooms");
const resultLocator = spotlight.results;
await expect(resultLocator).toHaveCount(1);
await resultLocator.first().hover();
axe.include(".mx_SpotlightDialog_filter");
axe.include(".mx_SpotlightDialog_option");
// XXX: same nested-interactive issue as above; here the endAdornment is the
// View/Join button rather than RoomResultContextMenus.
axe.disableRules("nested-interactive");
await expect(axe).toHaveNoViolations();
});
});
}
});
Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 35 KiB

@@ -352,6 +352,15 @@ Please see LICENSE files in the repository root for full details.
.mx_SpotlightDialog_option--notifications {
display: block;
}
/* $secondary-content/$tertiary-content do not have enough contrast against
the hover background ($quinary-content) to meet WCAG AA (4.5:1). */
.mx_SpotlightDialog_result_publicRoomDetails {
.mx_SpotlightDialog_result_publicRoomHeader .mx_SpotlightDialog_result_publicRoomAlias,
.mx_SpotlightDialog_result_publicRoomDescription {
color: $primary-content;
}
}
}
&[aria-selected="true"] .mx_SpotlightDialog_enterPrompt {
@@ -118,7 +118,7 @@ $accent-1400: var(--cpd-color-green-1400);
.mx_SpotlightDialog_wrapper .mx_Dialog {
#mx_SpotlightDialog_keyboardPrompt {
kbd {
color: $background !important;
color: $primary-content !important;
}
}
}
@@ -126,7 +126,7 @@ $accent-1400: var(--cpd-color-green-1400);
.mx_SpotlightDialog {
.mx_SpotlightDialog_searchBox {
> .mx_SpotlightDialog_filter {
color: $background !important;
color: $primary-content !important;
&::before {
background-color: $background !important;
}
@@ -137,7 +137,7 @@ $accent-1400: var(--cpd-color-green-1400);
.mx_SpotlightDialog_option {
&:hover,
&[aria-selected="true"] {
color: $background !important;
color: $primary-content !important;
.mx_DecoratedRoomAvatar_icon::before {
background-color: $background !important;
@@ -153,10 +153,10 @@ $accent-1400: var(--cpd-color-green-1400);
&:hover,
&[aria-selected="true"] {
background-color: $quinary-content !important;
color: $background !important;
color: $primary-content !important;
svg {
color: $background !important;
color: $primary-content !important;
}
.mx_DecoratedRoomAvatar_icon::before {
@@ -166,14 +166,14 @@ $accent-1400: var(--cpd-color-green-1400);
.mx_SpotlightDialog_result_publicRoomDetails {
.mx_SpotlightDialog_result_publicRoomHeader {
.mx_SpotlightDialog_result_publicRoomName {
color: $background;
color: $primary-content;
}
.mx_SpotlightDialog_result_publicRoomAlias {
color: $background;
color: $primary-content;
}
}
.mx_SpotlightDialog_result_publicRoomDescription {
color: $background;
color: $primary-content;
}
}
@@ -182,7 +182,7 @@ $accent-1400: var(--cpd-color-green-1400);
}
.mx_SpotlightDialog_result_details {
color: $background !important;
color: $primary-content !important;
}
}
}
@@ -195,7 +195,7 @@ $accent-1400: var(--cpd-color-green-1400);
.mx_GenericDropdownMenu_button:hover,
.mx_GenericDropdownMenu_button[aria-expanded="true"] {
color: $background !important;
color: $primary-content !important;
}
.mx_ContextualMenu_wrapper.mx_GenericDropdownMenu_wrapper {
@@ -203,7 +203,7 @@ $accent-1400: var(--cpd-color-green-1400);
&.mx_GenericDropdownMenu_Option--item {
&:hover {
background-color: $quinary-content !important;
color: $background !important;
color: $primary-content !important;
&[aria-checked="true"]::before {
background-color: $background !important;
@@ -211,7 +211,7 @@ $accent-1400: var(--cpd-color-green-1400);
> .mx_GenericDropdownMenu_Option--label {
span:first-child {
color: $background !important;
color: $primary-content !important;
}
}
}