diff --git a/apps/web/playwright/e2e/spotlight/spotlight.spec.ts b/apps/web/playwright/e2e/spotlight/spotlight.spec.ts index df865bc067..98bcfa62f7 100644 --- a/apps/web/playwright/e2e/spotlight/spotlight.spec.ts +++ b/apps/web/playwright/e2e/spotlight/spotlight.spec.ts @@ -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(); + }); + }); + } }); diff --git a/apps/web/playwright/snapshots/room-directory/room-directory.spec.ts/filtered-one-result-linux.png b/apps/web/playwright/snapshots/room-directory/room-directory.spec.ts/filtered-one-result-linux.png index 41d21f856a..20d1a87759 100644 Binary files a/apps/web/playwright/snapshots/room-directory/room-directory.spec.ts/filtered-one-result-linux.png and b/apps/web/playwright/snapshots/room-directory/room-directory.spec.ts/filtered-one-result-linux.png differ diff --git a/apps/web/res/css/views/dialogs/_SpotlightDialog.pcss b/apps/web/res/css/views/dialogs/_SpotlightDialog.pcss index 2a64e84a29..eef2679b3f 100644 --- a/apps/web/res/css/views/dialogs/_SpotlightDialog.pcss +++ b/apps/web/res/css/views/dialogs/_SpotlightDialog.pcss @@ -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 { diff --git a/apps/web/res/themes/light-high-contrast/css/_light-high-contrast.pcss b/apps/web/res/themes/light-high-contrast/css/_light-high-contrast.pcss index df91482923..a53d9d4d21 100644 --- a/apps/web/res/themes/light-high-contrast/css/_light-high-contrast.pcss +++ b/apps/web/res/themes/light-high-contrast/css/_light-high-contrast.pcss @@ -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; } } }