From 464aba7280225c28f47a12c900f21ff9dc866bc6 Mon Sep 17 00:00:00 2001 From: Cindy Zhang Date: Sun, 29 Nov 2026 02:16:38 -0800 Subject: [PATCH 1/7] fix(SelectableCard): a selected card rings in Highlight under forced colors Forced colors drop the selection ring's inset shadow and repaint the border, and palette variants draw no border, so a selected card painted the same as an unselected one in Windows High Contrast. Under @media (forced-colors: active) the selected card's ::after layer now draws a 2px ring in the system Highlight color inside its edge (a disabled card gets its own layer). Layout does not move and the focus outline stays its own; normal color modes are unchanged. --- .../selectable-card-forced-colors-selected.md | 7 + .../SelectableCard/SelectableCard.spec.md | 39 ++--- .../SelectableCard/SelectableCard.test.tsx | 17 ++ .../src/SelectableCard/SelectableCard.tsx | 30 ++++ ...ableCardForcedColors.a11y.chromium.spec.ts | 151 ++++++++++++++++++ 5 files changed, 225 insertions(+), 19 deletions(-) create mode 100644 .changeset/selectable-card-forced-colors-selected.md create mode 100644 packages/core/src/SelectableCard/__tests__/SelectableCardForcedColors.a11y.chromium.spec.ts diff --git a/.changeset/selectable-card-forced-colors-selected.md b/.changeset/selectable-card-forced-colors-selected.md new file mode 100644 index 0000000000000..2f39bf7d7c23b --- /dev/null +++ b/.changeset/selectable-card-forced-colors-selected.md @@ -0,0 +1,7 @@ +--- +'@astryxdesign/core': patch +--- + +[fix] SelectableCard: in forced colors (Windows High Contrast), a selected card now draws a 2px ring in the system Highlight color inside its edge, so the selection stays visible. Before, a selected card painted the same as an unselected one. Normal color modes are unchanged. + +@cixzhang diff --git a/docs/specs/components/SelectableCard/SelectableCard.spec.md b/docs/specs/components/SelectableCard/SelectableCard.spec.md index c3455eb9e5041..621a9eae143e4 100644 --- a/docs/specs/components/SelectableCard/SelectableCard.spec.md +++ b/docs/specs/components/SelectableCard/SelectableCard.spec.md @@ -148,7 +148,7 @@ Consumer migration instructions belong in consumer docs and release notes. | --- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------ | | FR1 | SelectableCard renders `component:Card` with the given `variant`, `elevation`, `padding`, and sizing. The root also carries the `selectable-card` target reflecting `variant` and `selected`, and the first child is a visually hidden native `input type="checkbox"` named by `label` with `checked` equal to `isSelected`. | Current source and tests | | FR2 | While enabled, a click on the card surface, a click or Space on the checkbox, or Enter on the checkbox calls `onChange(!isSelected)` exactly once. A click that belongs to nested interactive content, an open Tooltip or HoverCard surface (`component:Tooltip` FR11), or selected text does not toggle. A caller `onClick` runs after the toggle for a surface click, before it for a click or Space on the checkbox, and not at all for Enter; it also runs for clicks that do not toggle, including a click inside an open Tooltip or HoverCard surface. At the next minor, staged as `[breaking]`, a click inside an open layer stops at the layer root and the caller `onClick` no longer receives it (`architecture:layer-runtime` INV17); implementation gap: the current source still delivers that click to `onClick`. A caller `onMouseUp` runs after the card's own handling. | Current source and tests | -| FR3 | Selection adds a 2px inset ring through Card's ring variable, so layout does not move, and composes with any elevation shadow. `default`, `transparent`, and `muted` ring in `--color-accent`; each palette variant rings in its `--color-border-`; a theme-added variant rings in `--selectable-card-ring-color`. Selection also colors the border in the ring color where Card draws one, which is only the `default` variant. | Current source and tests | +| FR3 | Selection adds a 2px inset ring through Card's ring variable, so layout does not move, and composes with any elevation shadow. `default`, `transparent`, and `muted` ring in `--color-accent`; each palette variant rings in its `--color-border-`; a theme-added variant rings in `--selectable-card-ring-color`. Selection also colors the border in the ring color where Card draws one, which is only the `default` variant. Under forced colors, which drop the ring's shadow and repaint the border, a selected card, enabled or disabled, draws a 2px ring in the system `Highlight` color inside its edge instead, so the selection stays visible; an unselected card draws none. | Current source and tests | | FR4 | While enabled, the surface paints the shared hover overlay under a hover-capable pointer and the pressed overlay for mouse and touch presses; a press from any pointer that starts on a nested interactive element shows no pressed paint on the card, since it does not activate the card (`architecture:press-feedback` INV7). A touch press shows at once. Under the touch presentation, its release fades on the theme's exit motion tokens (`--duration-exit`, `--ease-exit`), per `spec:AST-094` FR5; a mouse press keeps the card's desktop press styling. Keyboard focus on the hidden checkbox shows one indicator on the card root (`architecture:interaction-modality` INV3). | Current source and tests | | FR5 | `isDisabled` dims the card to half opacity, removes the card's own click and mouseup handling and the caller's `onClick` and `onMouseUp` (other caller event props still reach the root) and the hover and pressed overlays (`spec:AST-085` FR6), and keeps the checkbox focusable with `aria-disabled="true"`; no click, Space, or Enter calls `onChange`. The disabled state is reflected on the owning target (`architecture:component-theming-surface` INV6). Implementation gap: the `selectable-card` target reflects `variant` and `selected` but not the disabled state (Current-state impact). | Current source and tests | | FR6 | `ref` reaches the Card root. Supported DOM, ARIA, data, and event props reach the root; `xstyle`, `className`, and `style` merge after the component's interactive styles. | Current source and tests | @@ -162,13 +162,13 @@ Consumer migration instructions belong in consumer docs and release notes. ### Representative states -| State | Required invariant | Allowed variation | -| -------------- | ------------------------------------------------------------------------------------------------- | ----------------- | -| Unselected | Unchecked named checkbox; no ring. | Variant. | -| Selected | Checked; inset ring in the variant's color, and a matching border on `default`; layout unchanged. | Elevation. | -| Keyboard focus | Focus outline on the card root. | — | -| Disabled | Focusable checkbox with `aria-disabled`; no toggle; half opacity. | Selection. | -| Nested control | Activating the nested control does not toggle the card. | Control type. | +| State | Required invariant | Allowed variation | +| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | ----------------- | +| Unselected | Unchecked named checkbox; no ring. | Variant. | +| Selected | Checked; inset ring in the variant's color, and a matching border on `default`; a `Highlight` ring under forced colors; layout unchanged. | Elevation. | +| Keyboard focus | Focus outline on the card root. | — | +| Disabled | Focusable checkbox with `aria-disabled`; no toggle; half opacity. | Selection. | +| Nested control | Activating the nested control does not toggle the card. | Control type. | ### Transformation and precedence order @@ -242,17 +242,18 @@ Consumer migration instructions belong in consumer docs and release notes. ## Verification map -| Contract | Verification | Representative states | Mutation or failure expectation | Audit section | -| ------------------- | -------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------- | -| FR1, FR2 | `SelectableCard.test.tsx` surface, checkbox, Enter, and Space tests | Unselected, selected | A missed toggle, a wrong `onChange` value, or a doubled toggle from Space fails. Target-reflection and handler-order tests fail on a lost target, variant, or selection reflection, or a changed order of `onChange` and a caller `onClick`. Gap: no test asserts the order of an enabled caller `onMouseUp`. | `audit:SelectableCard/behavior` | -| FR3 | `SelectableCard.test.tsx` elevation tests; stable visual baseline `core-selectablecard--single-select`; `SelectableCard.stories.tsx` | Selected with elevation; one selected default card beside unselected ones | A lost elevation while selected fails; a changed default ring or border comes back changed for review. Gap: palette and theme-added ring colors have no automated check. | `audit:SelectableCard/theming` | -| FR4 | `SelectableCard.test.tsx` touch-press test; `CardPress.a11y.chromium.spec.ts` on `core-selectablecard--single-select` | Rest; desktop hover and mouse press; touch press | A hover that does not paint over rest, a mouse press that does not paint over hover, or a touch press that does not match the desktop press or fade fails. `FocusRingOwner.a11y.chromium.spec.ts` fails if a focused nested button shows other than exactly one ring. | `audit:SelectableCard/design` | -| FR5, AR3 | `SelectableCard.test.tsx` disabled tests; `Checkbox.a11y.chromium.spec.ts` `card-disabled` state | Disabled click, Enter, Space | A toggle while disabled, or a disabled card that leaves keyboard reach, fails. `SelectableCardAudit.a11y.chromium.spec.ts` fails on a lost half opacity or a hover overlay on a disabled card. Gap: no test asserts the absent pressed overlay on a disabled card, and the target carries no disabled reflection to test (Current-state impact). | `audit:SelectableCard/a11y` | -| FR2 (nested) | `SelectableCard.test.tsx` nested-button test; `SelectableCardAudit.a11y.chromium.spec.ts` on `core-selectablecard--with-nested-button` | Card with a nested control or selected text | A click on a nested button that toggles the card fails. Gap: no test covers selected-text suppression. | `audit:SelectableCard/behavior` | -| Theming anatomy map | `scripts/check-knowledge.mjs` | Consumer anatomy and current target | Missing, extra, or stale mappings fail repository validation. | `audit:SelectableCard/theming` | -| AR1, AR2, AR4 | `SelectableCard.test.tsx` checkbox tests; `Checkbox.a11y.test.tsx` and `Checkbox.a11y.chromium.spec.ts` SelectableCard states | Unchecked, checked, disabled (`card-unchecked`, `card-checked`, `card-disabled`) | A lost checkbox role or name, a wrong checked state, or a disabled card that is not exposed as unavailable or not reachable fails, including at the accessibility tree. The passthrough test fails if the root gains a role or tab stop; `SelectableCardAudit.a11y.chromium.spec.ts` fails on a missing root focus outline or a ring that changes under hover. | `audit:SelectableCard/a11y` | -| FR6, PR1 | `SelectableCard.test.tsx` passthrough test; source review | Ref; caller props | A `ref`, `data-*`, `className`, or `style` that stops reaching the root fails. Gap: no test asserts `xstyle` or the merge order of the styling inputs, or fails if SelectableCard adds its own listener or timer. | `audit:SelectableCard/behavior` | -| AR5 | `Checkbox.a11y.chromium.spec.ts` aborted-press check on the SelectableCard states | Press that slides off the card before the lift | A toggle after a slide-off lift fails. | `audit:SelectableCard/a11y` | +| Contract | Verification | Representative states | Mutation or failure expectation | Audit section | +| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------- | +| FR1, FR2 | `SelectableCard.test.tsx` surface, checkbox, Enter, and Space tests | Unselected, selected | A missed toggle, a wrong `onChange` value, or a doubled toggle from Space fails. Target-reflection and handler-order tests fail on a lost target, variant, or selection reflection, or a changed order of `onChange` and a caller `onClick`. Gap: no test asserts the order of an enabled caller `onMouseUp`. | `audit:SelectableCard/behavior` | +| FR3 | `SelectableCard.test.tsx` elevation tests; stable visual baseline `core-selectablecard--single-select`; `SelectableCard.stories.tsx` | Selected with elevation; one selected default card beside unselected ones | A lost elevation while selected fails; a changed default ring or border comes back changed for review. Gap: palette and theme-added ring colors have no automated check. | `audit:SelectableCard/theming` | +| FR3 (forced colors) | `SelectableCard.test.tsx` forced-colors test; `SelectableCardForcedColors.a11y.chromium.spec.ts` on the multi-select, color-variants and disabled stories | Selected and unselected cards under forced colors; the same cards outside forced colors | A selected card without a 2px `Highlight` ring inside its edge under forced colors, an unselected card with one, or a ring outside forced colors fails. | `audit:SelectableCard/a11y` | +| FR4 | `SelectableCard.test.tsx` touch-press test; `CardPress.a11y.chromium.spec.ts` on `core-selectablecard--single-select` | Rest; desktop hover and mouse press; touch press | A hover that does not paint over rest, a mouse press that does not paint over hover, or a touch press that does not match the desktop press or fade fails. `FocusRingOwner.a11y.chromium.spec.ts` fails if a focused nested button shows other than exactly one ring. | `audit:SelectableCard/design` | +| FR5, AR3 | `SelectableCard.test.tsx` disabled tests; `Checkbox.a11y.chromium.spec.ts` `card-disabled` state | Disabled click, Enter, Space | A toggle while disabled, or a disabled card that leaves keyboard reach, fails. `SelectableCardAudit.a11y.chromium.spec.ts` fails on a lost half opacity or a hover overlay on a disabled card. Gap: no test asserts the absent pressed overlay on a disabled card, and the target carries no disabled reflection to test (Current-state impact). | `audit:SelectableCard/a11y` | +| FR2 (nested) | `SelectableCard.test.tsx` nested-button test; `SelectableCardAudit.a11y.chromium.spec.ts` on `core-selectablecard--with-nested-button` | Card with a nested control or selected text | A click on a nested button that toggles the card fails. Gap: no test covers selected-text suppression. | `audit:SelectableCard/behavior` | +| Theming anatomy map | `scripts/check-knowledge.mjs` | Consumer anatomy and current target | Missing, extra, or stale mappings fail repository validation. | `audit:SelectableCard/theming` | +| AR1, AR2, AR4 | `SelectableCard.test.tsx` checkbox tests; `Checkbox.a11y.test.tsx` and `Checkbox.a11y.chromium.spec.ts` SelectableCard states | Unchecked, checked, disabled (`card-unchecked`, `card-checked`, `card-disabled`) | A lost checkbox role or name, a wrong checked state, or a disabled card that is not exposed as unavailable or not reachable fails, including at the accessibility tree. The passthrough test fails if the root gains a role or tab stop; `SelectableCardAudit.a11y.chromium.spec.ts` fails on a missing root focus outline or a ring that changes under hover. | `audit:SelectableCard/a11y` | +| FR6, PR1 | `SelectableCard.test.tsx` passthrough test; source review | Ref; caller props | A `ref`, `data-*`, `className`, or `style` that stops reaching the root fails. Gap: no test asserts `xstyle` or the merge order of the styling inputs, or fails if SelectableCard adds its own listener or timer. | `audit:SelectableCard/behavior` | +| AR5 | `Checkbox.a11y.chromium.spec.ts` aborted-press check on the SelectableCard states | Press that slides off the card before the lift | A toggle after a slide-off lift fails. | `audit:SelectableCard/a11y` | ## Decision log diff --git a/packages/core/src/SelectableCard/SelectableCard.test.tsx b/packages/core/src/SelectableCard/SelectableCard.test.tsx index 08a1bf985fae4..0d31ec8923841 100644 --- a/packages/core/src/SelectableCard/SelectableCard.test.tsx +++ b/packages/core/src/SelectableCard/SelectableCard.test.tsx @@ -11,6 +11,7 @@ import {describe, it, expect, vi} from 'vitest'; import {render, screen, fireEvent} from '@testing-library/react'; import {SelectableCard} from './SelectableCard'; +import {getForcedColorsRules} from '../__tests__/forcedColors'; import { afterPaintsPress, hasReleaseFade, @@ -346,3 +347,19 @@ describe('SelectableCard target, handler order and passthrough (FR1, FR2, FR5, F expect(root).not.toHaveAttribute('tabindex'); }); }); + +// jsdom cannot emulate forced-colors rendering, so this asserts that the +// compiled output holds the forced-colors ring; the browser spec +// SelectableCardForcedColors.a11y.chromium.spec.ts checks the paint. +describe('SelectableCard forced colors (FR3)', () => { + it('compiles a Highlight ring on the selected card for forced colors', () => { + render( + {}}> + React + , + ); + const css = getForcedColorsRules(); + expect(css).toMatch(/::after\s*\{[^}]*border-color: highlight/); + expect(css).toMatch(/::after\s*\{[^}]*border-width: 2px/); + }); +}); diff --git a/packages/core/src/SelectableCard/SelectableCard.tsx b/packages/core/src/SelectableCard/SelectableCard.tsx index e562304d5ba2b..d11759903a4c8 100644 --- a/packages/core/src/SelectableCard/SelectableCard.tsx +++ b/packages/core/src/SelectableCard/SelectableCard.tsx @@ -191,6 +191,34 @@ const styles = stylex.create({ }, }, }, + // Forced colors drop the inset ring's shadow and repaint the border, so a + // selected card would paint as an unselected one. The `::after` layer draws + // a 2px ring in the system `Highlight` color instead, inside the card, so + // layout does not move and the focus outline stays its own. + selectedForcedColors: { + '::after': { + borderWidth: {default: null, '@media (forced-colors: active)': '2px'}, + borderStyle: {default: null, '@media (forced-colors: active)': 'solid'}, + borderColor: { + default: null, + '@media (forced-colors: active)': 'Highlight', + }, + }, + }, + // A disabled card has no overlay layer, so the forced-colors ring brings + // its own. + selectedForcedColorsLayer: { + '::after': { + content: {default: null, '@media (forced-colors: active)': '""'}, + position: {default: null, '@media (forced-colors: active)': 'absolute'}, + inset: {default: null, '@media (forced-colors: active)': 0}, + borderRadius: { + default: null, + '@media (forced-colors: active)': 'inherit', + }, + pointerEvents: {default: null, '@media (forced-colors: active)': 'none'}, + }, + }, disabled: { cursor: 'default', opacity: 0.5, @@ -563,6 +591,8 @@ export function SelectableCard({ styles.interactive, isSelected && selectedStyleForVariant(variant), !isDisabled && styles.overlay, + isSelected && styles.selectedForcedColors, + isSelected && isDisabled && styles.selectedForcedColorsLayer, // The touch press's strength and release, on the element the // controller writes to; the `::after` above paints off it. !isDisabled && interactionOverlayStyles.pressedAlpha, diff --git a/packages/core/src/SelectableCard/__tests__/SelectableCardForcedColors.a11y.chromium.spec.ts b/packages/core/src/SelectableCard/__tests__/SelectableCardForcedColors.a11y.chromium.spec.ts new file mode 100644 index 0000000000000..85baf3a92d303 --- /dev/null +++ b/packages/core/src/SelectableCard/__tests__/SelectableCardForcedColors.a11y.chromium.spec.ts @@ -0,0 +1,151 @@ +// Copyright (c) Meta Platforms, Inc. and affiliates. +// @pr-a11y scope ^packages/core/src/(SelectableCard|Card)/ ^apps/storybook/stories/SelectableCard + +/** + * @file SelectableCardForcedColors.a11y.chromium.spec.ts + * @input The built SelectableCard multi-select, color-variants and disabled + * stories in real Chromium, with forced colors emulated and without + * @output Browser evidence that, in forced colors, a selected card paints a + * 2px ring in the system Highlight color inside its edge and an unselected + * card paints none; outside forced colors the layer paints no ring + * @position Regression proof for SelectableCard's forced-colors selection + * (Chromium only: Playwright's WebKit matches the forced-colors query but + * forces nothing) + */ + +// @ts-expect-error -- pngjs ships no declarations; runtime support is pinned. +import {PNG} from 'pngjs'; +import {expect, test, type Page} from '@astryxdesign/a11y-spec/playwright'; +import { + DEFAULT_STORYBOOK_DIR, + serveStorybook, + type StaticServer, +} from '@astryxdesign/a11y-spec/storybook'; + +let storybook: StaticServer; +test.beforeAll(async () => { + storybook = await serveStorybook( + process.env.ASTRYX_STORYBOOK_DIR ?? DEFAULT_STORYBOOK_DIR, + ); +}); +test.afterAll(async () => { + await storybook?.close(); +}); + +type Ring = { + label: string; + selected: boolean; + width: number; + style: string; + color: string; +}; + +/** Each card's `::after` border, and the system Highlight color. */ +async function readRings( + page: Page, + story: string, + forcedColors: 'active' | 'none', +): Promise<{rings: Ring[]; highlight: string}> { + await page.emulateMedia({forcedColors}); + await page.goto(`${storybook.origin}/iframe.html?id=${story}&viewMode=story`); + await page.locator('.astryx-selectable-card').first().waitFor(); + return page.evaluate(() => { + const probe = document.createElement('span'); + probe.style.color = 'Highlight'; + document.body.append(probe); + const highlight = getComputedStyle(probe).color; + probe.remove(); + const rings = [ + ...document.querySelectorAll('.astryx-selectable-card'), + ].map(card => { + const layer = getComputedStyle(card, '::after'); + const input = card.querySelector('input'); + return { + label: input?.getAttribute('aria-label') ?? '', + selected: card.getAttribute('data-selected') === 'true', + width: parseFloat(layer.borderTopWidth), + style: layer.borderTopStyle, + color: layer.borderTopColor, + }; + }); + return {rings, highlight}; + }); +} + +for (const story of [ + 'core-selectablecard--multi-select', + 'core-selectablecard--color-variants', + 'core-selectablecard--disabled', +]) { + test(`${story}: in forced colors a selected card rings in Highlight and an unselected card does not`, async ({ + page, + }) => { + const {rings, highlight} = await readRings(page, story, 'active'); + const selected = rings.filter(ring => ring.selected); + const unselected = rings.filter(ring => !ring.selected); + expect(selected.length).toBeGreaterThan(0); + expect(unselected.length).toBeGreaterThan(0); + for (const ring of selected) { + expect(ring, ring.label).toMatchObject({ + width: 2, + style: 'solid', + color: highlight, + }); + } + for (const ring of unselected) { + expect(ring.width, ring.label).toBe(0); + } + }); +} + +test('in forced colors the selected card paints Highlight inside its edge', async ({ + page, +}) => { + await readRings(page, 'core-selectablecard--multi-select', 'active'); + const pixel = async ( + clip: {x: number; y: number; width: number; height: number}, + x: number, + ) => { + const png = PNG.sync.read(await page.screenshot({clip})); + const i = (Math.floor(png.height / 2) * png.width + x) * 4; + return [png.data[i], png.data[i + 1], png.data[i + 2]]; + }; + // The system Highlight as it paints over the page: a swatch beside the cards. + await page.evaluate(() => { + const swatch = document.createElement('div'); + swatch.id = 'highlight-swatch'; + Object.assign(swatch.style, { + position: 'fixed', + right: '0', + bottom: '0', + width: '20px', + height: '20px', + backgroundColor: 'Highlight', + }); + document.body.append(swatch); + }); + const swatch = (await page.locator('#highlight-swatch').boundingBox())!; + const highlight = await pixel(swatch, 10); + const edge = async (selected: boolean) => { + const card = page + .locator(`.astryx-selectable-card[data-selected="${selected}"]`) + .first(); + // One pixel inside the card's own 1px edge, halfway down: on the ring. + return pixel((await card.boundingBox())!, 2); + }; + expect(await edge(true)).toEqual(highlight); + expect(await edge(false)).not.toEqual(highlight); +}); + +test('outside forced colors the layer paints no ring', async ({page}) => { + for (const story of [ + 'core-selectablecard--multi-select', + 'core-selectablecard--color-variants', + 'core-selectablecard--disabled', + ]) { + const {rings} = await readRings(page, story, 'none'); + for (const ring of rings) { + expect(ring.width, `${story} ${ring.label}`).toBe(0); + } + } +}); From e90dc2e390dbb39c95ad59772ff243a597475ef3 Mon Sep 17 00:00:00 2001 From: Cindy Zhang Date: Sun, 29 Nov 2026 05:32:33 -0800 Subject: [PATCH 2/7] fix(SelectableCard): draw the forced-colors ring on the card's own box The ring was a border on the absolutely positioned ::after layer, which scrolls with the content of a fixed-height card (Card makes it overflow: auto), so on a scrolled card the ring crossed the text and left the lower edge unmarked. Under forced colors a selected card now draws a 2px Highlight border on its own box, and its padding gives up the same 2px, so the content does not move. The styles are a separate class, so their unset defaults do not reset the card's border or padding in normal color modes. The disabled card no longer needs a layer of its own. Adds a scrolled fixed-height case to the browser spec. --- .../SelectableCard/SelectableCard.test.tsx | 5 +- .../src/SelectableCard/SelectableCard.tsx | 60 ++++++++------- ...ableCardForcedColors.a11y.chromium.spec.ts | 74 ++++++++++++++++--- 3 files changed, 99 insertions(+), 40 deletions(-) diff --git a/packages/core/src/SelectableCard/SelectableCard.test.tsx b/packages/core/src/SelectableCard/SelectableCard.test.tsx index 0d31ec8923841..830b3076308aa 100644 --- a/packages/core/src/SelectableCard/SelectableCard.test.tsx +++ b/packages/core/src/SelectableCard/SelectableCard.test.tsx @@ -359,7 +359,8 @@ describe('SelectableCard forced colors (FR3)', () => { , ); const css = getForcedColorsRules(); - expect(css).toMatch(/::after\s*\{[^}]*border-color: highlight/); - expect(css).toMatch(/::after\s*\{[^}]*border-width: 2px/); + expect(css).toContain('border-color: highlight'); + expect(css).toContain('border-width: 2px'); + expect(css).not.toMatch(/::after\s*\{[^}]*border-color: highlight/); }); }); diff --git a/packages/core/src/SelectableCard/SelectableCard.tsx b/packages/core/src/SelectableCard/SelectableCard.tsx index d11759903a4c8..0e2003cf3b5b1 100644 --- a/packages/core/src/SelectableCard/SelectableCard.tsx +++ b/packages/core/src/SelectableCard/SelectableCard.tsx @@ -191,32 +191,33 @@ const styles = stylex.create({ }, }, }, - // Forced colors drop the inset ring's shadow and repaint the border, so a - // selected card would paint as an unselected one. The `::after` layer draws - // a 2px ring in the system `Highlight` color instead, inside the card, so - // layout does not move and the focus outline stays its own. + // Forced colors drop the ring's shadow and repaint the border. A selected + // card draws a 2px `Highlight` border on its own box instead. The padding + // gives up the same 2px, so the content does not move. A border stays on the + // edge when a fixed-height card scrolls. The focus outline stays separate. selectedForcedColors: { - '::after': { - borderWidth: {default: null, '@media (forced-colors: active)': '2px'}, - borderStyle: {default: null, '@media (forced-colors: active)': 'solid'}, - borderColor: { - default: null, - '@media (forced-colors: active)': 'Highlight', - }, + borderWidth: {default: null, '@media (forced-colors: active)': '2px'}, + borderStyle: {default: null, '@media (forced-colors: active)': 'solid'}, + borderColor: {default: null, '@media (forced-colors: active)': 'Highlight'}, + paddingInlineStart: { + default: null, + '@media (forced-colors: active)': + 'calc(var(--container-padding-inline-start) - 2px)', }, - }, - // A disabled card has no overlay layer, so the forced-colors ring brings - // its own. - selectedForcedColorsLayer: { - '::after': { - content: {default: null, '@media (forced-colors: active)': '""'}, - position: {default: null, '@media (forced-colors: active)': 'absolute'}, - inset: {default: null, '@media (forced-colors: active)': 0}, - borderRadius: { - default: null, - '@media (forced-colors: active)': 'inherit', - }, - pointerEvents: {default: null, '@media (forced-colors: active)': 'none'}, + paddingInlineEnd: { + default: null, + '@media (forced-colors: active)': + 'calc(var(--container-padding-inline-end) - 2px)', + }, + paddingBlockStart: { + default: null, + '@media (forced-colors: active)': + 'calc(var(--container-padding-block-start) - 2px)', + }, + paddingBlockEnd: { + default: null, + '@media (forced-colors: active)': + 'calc(var(--container-padding-block-end) - 2px)', }, }, disabled: { @@ -581,8 +582,13 @@ export function SelectableCard({ selected: isSelected ? 'true' : 'false', }), // Rings for the card's own checkbox only; a control in its children - // rings itself. - stylex.props(focusWithinOwner), + // rings itself. The forced-colors ring is a class here, not in the + // merged styles: a `null` default there would unset the card's border + // and padding in every color mode. + stylex.props( + focusWithinOwner, + isSelected && styles.selectedForcedColors, + ), classNameProp, style, )} @@ -591,8 +597,6 @@ export function SelectableCard({ styles.interactive, isSelected && selectedStyleForVariant(variant), !isDisabled && styles.overlay, - isSelected && styles.selectedForcedColors, - isSelected && isDisabled && styles.selectedForcedColorsLayer, // The touch press's strength and release, on the element the // controller writes to; the `::after` above paints off it. !isDisabled && interactionOverlayStyles.pressedAlpha, diff --git a/packages/core/src/SelectableCard/__tests__/SelectableCardForcedColors.a11y.chromium.spec.ts b/packages/core/src/SelectableCard/__tests__/SelectableCardForcedColors.a11y.chromium.spec.ts index 85baf3a92d303..1a1f8d9cffc0c 100644 --- a/packages/core/src/SelectableCard/__tests__/SelectableCardForcedColors.a11y.chromium.spec.ts +++ b/packages/core/src/SelectableCard/__tests__/SelectableCardForcedColors.a11y.chromium.spec.ts @@ -5,9 +5,10 @@ * @file SelectableCardForcedColors.a11y.chromium.spec.ts * @input The built SelectableCard multi-select, color-variants and disabled * stories in real Chromium, with forced colors emulated and without - * @output Browser evidence that, in forced colors, a selected card paints a - * 2px ring in the system Highlight color inside its edge and an unselected - * card paints none; outside forced colors the layer paints no ring + * @output Browser evidence that, in forced colors, a selected card draws a 2px + * border in the system Highlight color on its own edge, also when a + * fixed-height card scrolls, and an unselected card draws none; outside + * forced colors no card draws it * @position Regression proof for SelectableCard's forced-colors selection * (Chromium only: Playwright's WebKit matches the forced-colors query but * forces nothing) @@ -40,7 +41,7 @@ type Ring = { color: string; }; -/** Each card's `::after` border, and the system Highlight color. */ +/** Each card's own border, and the system Highlight color. */ async function readRings( page: Page, story: string, @@ -58,7 +59,7 @@ async function readRings( const rings = [ ...document.querySelectorAll('.astryx-selectable-card'), ].map(card => { - const layer = getComputedStyle(card, '::after'); + const layer = getComputedStyle(card); const input = card.querySelector('input'); return { label: input?.getAttribute('aria-label') ?? '', @@ -93,7 +94,10 @@ for (const story of [ }); } for (const ring of unselected) { - expect(ring.width, ring.label).toBe(0); + expect( + ring.width === 2 && ring.color === highlight, + `${ring.label}: ${ring.width}px ${ring.color}`, + ).toBe(false); } }); } @@ -130,14 +134,64 @@ test('in forced colors the selected card paints Highlight inside its edge', asyn const card = page .locator(`.astryx-selectable-card[data-selected="${selected}"]`) .first(); - // One pixel inside the card's own 1px edge, halfway down: on the ring. - return pixel((await card.boundingBox())!, 2); + // The card's own 2px border, halfway down. + return pixel((await card.boundingBox())!, 1); }; expect(await edge(true)).toEqual(highlight); expect(await edge(false)).not.toEqual(highlight); }); -test('outside forced colors the layer paints no ring', async ({page}) => { +test('in forced colors a scrolled fixed-height card keeps the ring on its edge', async ({ + page, +}) => { + await readRings(page, 'core-selectablecard--multi-select', 'active'); + await page.evaluate(() => { + const swatch = document.createElement('div'); + swatch.id = 'highlight-swatch'; + Object.assign(swatch.style, { + position: 'fixed', + right: '0', + bottom: '0', + width: '20px', + height: '20px', + backgroundColor: 'Highlight', + }); + document.body.append(swatch); + // A selected card with a fixed height scrolls its content, as Card does + // for a `height`. Fill it past that height and scroll to the end. + const card = document.querySelector( + '.astryx-selectable-card[data-selected="true"]', + )!; + card.style.height = '64px'; + card.style.overflow = 'auto'; + const filler = document.createElement('div'); + filler.style.height = '300px'; + filler.textContent = 'Long content'; + card.append(filler); + card.scrollTop = card.scrollHeight; + }); + const read = async ( + clip: {x: number; y: number; width: number; height: number}, + x: number, + y: number, + ) => { + const png = PNG.sync.read(await page.screenshot({clip})); + const i = (y * png.width + x) * 4; + return [png.data[i], png.data[i + 1], png.data[i + 2]]; + }; + const swatch = (await page.locator('#highlight-swatch').boundingBox())!; + const highlight = await read(swatch, 10, 10); + const box = (await page + .locator('.astryx-selectable-card[data-selected="true"]') + .first() + .boundingBox())!; + const midX = Math.floor(box.width / 2); + // The top and bottom edges carry the ring after the scroll. + expect(await read(box, midX, 0)).toEqual(highlight); + expect(await read(box, midX, Math.floor(box.height) - 1)).toEqual(highlight); +}); + +test('outside forced colors no card draws the ring', async ({page}) => { for (const story of [ 'core-selectablecard--multi-select', 'core-selectablecard--color-variants', @@ -145,7 +199,7 @@ test('outside forced colors the layer paints no ring', async ({page}) => { ]) { const {rings} = await readRings(page, story, 'none'); for (const ring of rings) { - expect(ring.width, `${story} ${ring.label}`).toBe(0); + expect(ring.width, `${story} ${ring.label}`).not.toBe(2); } } }); From 70553059ff466eafda851bcb79780b10c64015fb Mon Sep 17 00:00:00 2001 From: Cindy Zhang Date: Sun, 29 Nov 2026 05:35:21 -0800 Subject: [PATCH 3/7] docs(SelectableCard): FR3 and the changeset name the forced-colors border on the card's edge The forced-colors ring is now the card's own border, so the record and the changeset say so, including the scrolled fixed-height case and its new verification. --- .../selectable-card-forced-colors-selected.md | 2 +- .../SelectableCard/SelectableCard.spec.md | 26 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.changeset/selectable-card-forced-colors-selected.md b/.changeset/selectable-card-forced-colors-selected.md index 2f39bf7d7c23b..021809696efa4 100644 --- a/.changeset/selectable-card-forced-colors-selected.md +++ b/.changeset/selectable-card-forced-colors-selected.md @@ -2,6 +2,6 @@ '@astryxdesign/core': patch --- -[fix] SelectableCard: in forced colors (Windows High Contrast), a selected card now draws a 2px ring in the system Highlight color inside its edge, so the selection stays visible. Before, a selected card painted the same as an unselected one. Normal color modes are unchanged. +[fix] SelectableCard: in forced colors (Windows High Contrast), a selected card now draws a 2px border in the system Highlight color on its own edge, so the selection stays visible, also when a fixed-height card scrolls. The content does not move. Before, a selected card painted the same as an unselected one. Normal color modes are unchanged. @cixzhang diff --git a/docs/specs/components/SelectableCard/SelectableCard.spec.md b/docs/specs/components/SelectableCard/SelectableCard.spec.md index 621a9eae143e4..4ad17b3b5baae 100644 --- a/docs/specs/components/SelectableCard/SelectableCard.spec.md +++ b/docs/specs/components/SelectableCard/SelectableCard.spec.md @@ -148,7 +148,7 @@ Consumer migration instructions belong in consumer docs and release notes. | --- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------ | | FR1 | SelectableCard renders `component:Card` with the given `variant`, `elevation`, `padding`, and sizing. The root also carries the `selectable-card` target reflecting `variant` and `selected`, and the first child is a visually hidden native `input type="checkbox"` named by `label` with `checked` equal to `isSelected`. | Current source and tests | | FR2 | While enabled, a click on the card surface, a click or Space on the checkbox, or Enter on the checkbox calls `onChange(!isSelected)` exactly once. A click that belongs to nested interactive content, an open Tooltip or HoverCard surface (`component:Tooltip` FR11), or selected text does not toggle. A caller `onClick` runs after the toggle for a surface click, before it for a click or Space on the checkbox, and not at all for Enter; it also runs for clicks that do not toggle, including a click inside an open Tooltip or HoverCard surface. At the next minor, staged as `[breaking]`, a click inside an open layer stops at the layer root and the caller `onClick` no longer receives it (`architecture:layer-runtime` INV17); implementation gap: the current source still delivers that click to `onClick`. A caller `onMouseUp` runs after the card's own handling. | Current source and tests | -| FR3 | Selection adds a 2px inset ring through Card's ring variable, so layout does not move, and composes with any elevation shadow. `default`, `transparent`, and `muted` ring in `--color-accent`; each palette variant rings in its `--color-border-`; a theme-added variant rings in `--selectable-card-ring-color`. Selection also colors the border in the ring color where Card draws one, which is only the `default` variant. Under forced colors, which drop the ring's shadow and repaint the border, a selected card, enabled or disabled, draws a 2px ring in the system `Highlight` color inside its edge instead, so the selection stays visible; an unselected card draws none. | Current source and tests | +| FR3 | Selection adds a 2px inset ring through Card's ring variable, so layout does not move, and composes with any elevation shadow. `default`, `transparent`, and `muted` ring in `--color-accent`; each palette variant rings in its `--color-border-`; a theme-added variant rings in `--selectable-card-ring-color`. Selection also colors the border in the ring color where Card draws one, which is only the `default` variant. Under forced colors, which drop the ring's shadow and repaint the border, a selected card, enabled or disabled, draws a 2px border in the system `Highlight` color on its own edge instead, and gives up the same 2px of padding, so the selection stays visible, layout does not move, and the ring stays on the edge when a fixed-height card scrolls; an unselected card draws none. | Current source and tests | | FR4 | While enabled, the surface paints the shared hover overlay under a hover-capable pointer and the pressed overlay for mouse and touch presses; a press from any pointer that starts on a nested interactive element shows no pressed paint on the card, since it does not activate the card (`architecture:press-feedback` INV7). A touch press shows at once. Under the touch presentation, its release fades on the theme's exit motion tokens (`--duration-exit`, `--ease-exit`), per `spec:AST-094` FR5; a mouse press keeps the card's desktop press styling. Keyboard focus on the hidden checkbox shows one indicator on the card root (`architecture:interaction-modality` INV3). | Current source and tests | | FR5 | `isDisabled` dims the card to half opacity, removes the card's own click and mouseup handling and the caller's `onClick` and `onMouseUp` (other caller event props still reach the root) and the hover and pressed overlays (`spec:AST-085` FR6), and keeps the checkbox focusable with `aria-disabled="true"`; no click, Space, or Enter calls `onChange`. The disabled state is reflected on the owning target (`architecture:component-theming-surface` INV6). Implementation gap: the `selectable-card` target reflects `variant` and `selected` but not the disabled state (Current-state impact). | Current source and tests | | FR6 | `ref` reaches the Card root. Supported DOM, ARIA, data, and event props reach the root; `xstyle`, `className`, and `style` merge after the component's interactive styles. | Current source and tests | @@ -242,18 +242,18 @@ Consumer migration instructions belong in consumer docs and release notes. ## Verification map -| Contract | Verification | Representative states | Mutation or failure expectation | Audit section | -| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------- | -| FR1, FR2 | `SelectableCard.test.tsx` surface, checkbox, Enter, and Space tests | Unselected, selected | A missed toggle, a wrong `onChange` value, or a doubled toggle from Space fails. Target-reflection and handler-order tests fail on a lost target, variant, or selection reflection, or a changed order of `onChange` and a caller `onClick`. Gap: no test asserts the order of an enabled caller `onMouseUp`. | `audit:SelectableCard/behavior` | -| FR3 | `SelectableCard.test.tsx` elevation tests; stable visual baseline `core-selectablecard--single-select`; `SelectableCard.stories.tsx` | Selected with elevation; one selected default card beside unselected ones | A lost elevation while selected fails; a changed default ring or border comes back changed for review. Gap: palette and theme-added ring colors have no automated check. | `audit:SelectableCard/theming` | -| FR3 (forced colors) | `SelectableCard.test.tsx` forced-colors test; `SelectableCardForcedColors.a11y.chromium.spec.ts` on the multi-select, color-variants and disabled stories | Selected and unselected cards under forced colors; the same cards outside forced colors | A selected card without a 2px `Highlight` ring inside its edge under forced colors, an unselected card with one, or a ring outside forced colors fails. | `audit:SelectableCard/a11y` | -| FR4 | `SelectableCard.test.tsx` touch-press test; `CardPress.a11y.chromium.spec.ts` on `core-selectablecard--single-select` | Rest; desktop hover and mouse press; touch press | A hover that does not paint over rest, a mouse press that does not paint over hover, or a touch press that does not match the desktop press or fade fails. `FocusRingOwner.a11y.chromium.spec.ts` fails if a focused nested button shows other than exactly one ring. | `audit:SelectableCard/design` | -| FR5, AR3 | `SelectableCard.test.tsx` disabled tests; `Checkbox.a11y.chromium.spec.ts` `card-disabled` state | Disabled click, Enter, Space | A toggle while disabled, or a disabled card that leaves keyboard reach, fails. `SelectableCardAudit.a11y.chromium.spec.ts` fails on a lost half opacity or a hover overlay on a disabled card. Gap: no test asserts the absent pressed overlay on a disabled card, and the target carries no disabled reflection to test (Current-state impact). | `audit:SelectableCard/a11y` | -| FR2 (nested) | `SelectableCard.test.tsx` nested-button test; `SelectableCardAudit.a11y.chromium.spec.ts` on `core-selectablecard--with-nested-button` | Card with a nested control or selected text | A click on a nested button that toggles the card fails. Gap: no test covers selected-text suppression. | `audit:SelectableCard/behavior` | -| Theming anatomy map | `scripts/check-knowledge.mjs` | Consumer anatomy and current target | Missing, extra, or stale mappings fail repository validation. | `audit:SelectableCard/theming` | -| AR1, AR2, AR4 | `SelectableCard.test.tsx` checkbox tests; `Checkbox.a11y.test.tsx` and `Checkbox.a11y.chromium.spec.ts` SelectableCard states | Unchecked, checked, disabled (`card-unchecked`, `card-checked`, `card-disabled`) | A lost checkbox role or name, a wrong checked state, or a disabled card that is not exposed as unavailable or not reachable fails, including at the accessibility tree. The passthrough test fails if the root gains a role or tab stop; `SelectableCardAudit.a11y.chromium.spec.ts` fails on a missing root focus outline or a ring that changes under hover. | `audit:SelectableCard/a11y` | -| FR6, PR1 | `SelectableCard.test.tsx` passthrough test; source review | Ref; caller props | A `ref`, `data-*`, `className`, or `style` that stops reaching the root fails. Gap: no test asserts `xstyle` or the merge order of the styling inputs, or fails if SelectableCard adds its own listener or timer. | `audit:SelectableCard/behavior` | -| AR5 | `Checkbox.a11y.chromium.spec.ts` aborted-press check on the SelectableCard states | Press that slides off the card before the lift | A toggle after a slide-off lift fails. | `audit:SelectableCard/a11y` | +| Contract | Verification | Representative states | Mutation or failure expectation | Audit section | +| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------- | +| FR1, FR2 | `SelectableCard.test.tsx` surface, checkbox, Enter, and Space tests | Unselected, selected | A missed toggle, a wrong `onChange` value, or a doubled toggle from Space fails. Target-reflection and handler-order tests fail on a lost target, variant, or selection reflection, or a changed order of `onChange` and a caller `onClick`. Gap: no test asserts the order of an enabled caller `onMouseUp`. | `audit:SelectableCard/behavior` | +| FR3 | `SelectableCard.test.tsx` elevation tests; stable visual baseline `core-selectablecard--single-select`; `SelectableCard.stories.tsx` | Selected with elevation; one selected default card beside unselected ones | A lost elevation while selected fails; a changed default ring or border comes back changed for review. Gap: palette and theme-added ring colors have no automated check. | `audit:SelectableCard/theming` | +| FR3 (forced colors) | `SelectableCard.test.tsx` forced-colors test; `SelectableCardForcedColors.a11y.chromium.spec.ts` on the multi-select, color-variants and disabled stories, and a scrolled fixed-height card | Selected and unselected cards under forced colors; a scrolled fixed-height selected card; the same cards outside forced colors | A selected card without a 2px `Highlight` border on its edge under forced colors, a scrolled card whose top or bottom edge loses it, an unselected card with one, or the border outside forced colors fails. | `audit:SelectableCard/a11y` | +| FR4 | `SelectableCard.test.tsx` touch-press test; `CardPress.a11y.chromium.spec.ts` on `core-selectablecard--single-select` | Rest; desktop hover and mouse press; touch press | A hover that does not paint over rest, a mouse press that does not paint over hover, or a touch press that does not match the desktop press or fade fails. `FocusRingOwner.a11y.chromium.spec.ts` fails if a focused nested button shows other than exactly one ring. | `audit:SelectableCard/design` | +| FR5, AR3 | `SelectableCard.test.tsx` disabled tests; `Checkbox.a11y.chromium.spec.ts` `card-disabled` state | Disabled click, Enter, Space | A toggle while disabled, or a disabled card that leaves keyboard reach, fails. `SelectableCardAudit.a11y.chromium.spec.ts` fails on a lost half opacity or a hover overlay on a disabled card. Gap: no test asserts the absent pressed overlay on a disabled card, and the target carries no disabled reflection to test (Current-state impact). | `audit:SelectableCard/a11y` | +| FR2 (nested) | `SelectableCard.test.tsx` nested-button test; `SelectableCardAudit.a11y.chromium.spec.ts` on `core-selectablecard--with-nested-button` | Card with a nested control or selected text | A click on a nested button that toggles the card fails. Gap: no test covers selected-text suppression. | `audit:SelectableCard/behavior` | +| Theming anatomy map | `scripts/check-knowledge.mjs` | Consumer anatomy and current target | Missing, extra, or stale mappings fail repository validation. | `audit:SelectableCard/theming` | +| AR1, AR2, AR4 | `SelectableCard.test.tsx` checkbox tests; `Checkbox.a11y.test.tsx` and `Checkbox.a11y.chromium.spec.ts` SelectableCard states | Unchecked, checked, disabled (`card-unchecked`, `card-checked`, `card-disabled`) | A lost checkbox role or name, a wrong checked state, or a disabled card that is not exposed as unavailable or not reachable fails, including at the accessibility tree. The passthrough test fails if the root gains a role or tab stop; `SelectableCardAudit.a11y.chromium.spec.ts` fails on a missing root focus outline or a ring that changes under hover. | `audit:SelectableCard/a11y` | +| FR6, PR1 | `SelectableCard.test.tsx` passthrough test; source review | Ref; caller props | A `ref`, `data-*`, `className`, or `style` that stops reaching the root fails. Gap: no test asserts `xstyle` or the merge order of the styling inputs, or fails if SelectableCard adds its own listener or timer. | `audit:SelectableCard/behavior` | +| AR5 | `Checkbox.a11y.chromium.spec.ts` aborted-press check on the SelectableCard states | Press that slides off the card before the lift | A toggle after a slide-off lift fails. | `audit:SelectableCard/a11y` | ## Decision log From ab0a2dc0e9d9505af2c5c660540f83458b9f0588 Mon Sep 17 00:00:00 2001 From: Cindy Zhang Date: Sun, 29 Nov 2026 06:35:36 -0800 Subject: [PATCH 4/7] fix(SelectableCard): state the zero-padding and themed-border cases of the forced-colors ring A card with zero padding has no padding to give up, so its content area loses the 2px border on each side. A theme that sets the border color on the selectable-card or card target owns that color under forced colors too, as it owns the border elsewhere. FR3, the changeset and the browser spec now cover both; the spec adds a zero-padding case. --- .../selectable-card-forced-colors-selected.md | 2 +- .../SelectableCard/SelectableCard.spec.md | 40 +++++++++---------- .../src/SelectableCard/SelectableCard.tsx | 14 ++++--- ...ableCardForcedColors.a11y.chromium.spec.ts | 37 ++++++++++++++++- 4 files changed, 64 insertions(+), 29 deletions(-) diff --git a/.changeset/selectable-card-forced-colors-selected.md b/.changeset/selectable-card-forced-colors-selected.md index 021809696efa4..9e46d5cf0fc65 100644 --- a/.changeset/selectable-card-forced-colors-selected.md +++ b/.changeset/selectable-card-forced-colors-selected.md @@ -2,6 +2,6 @@ '@astryxdesign/core': patch --- -[fix] SelectableCard: in forced colors (Windows High Contrast), a selected card now draws a 2px border in the system Highlight color on its own edge, so the selection stays visible, also when a fixed-height card scrolls. The content does not move. Before, a selected card painted the same as an unselected one. Normal color modes are unchanged. +[fix] SelectableCard: in forced colors (Windows High Contrast), a selected card now draws a 2px border in the system Highlight color on its own edge, so the selection stays visible, also when a fixed-height card scrolls. The padding gives up the same 2px, so the content does not move; a card with zero padding has none to give up, so its content area loses 2px on each side. A theme that sets the card's border color keeps owning it. Before, a selected card painted the same as an unselected one. Normal color modes are unchanged. @cixzhang diff --git a/docs/specs/components/SelectableCard/SelectableCard.spec.md b/docs/specs/components/SelectableCard/SelectableCard.spec.md index 4ad17b3b5baae..bd569f28d4c48 100644 --- a/docs/specs/components/SelectableCard/SelectableCard.spec.md +++ b/docs/specs/components/SelectableCard/SelectableCard.spec.md @@ -144,14 +144,14 @@ Consumer migration instructions belong in consumer docs and release notes. ## Behavioral and layout contract -| ID | Invariant | Basis | -| --- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------ | -| FR1 | SelectableCard renders `component:Card` with the given `variant`, `elevation`, `padding`, and sizing. The root also carries the `selectable-card` target reflecting `variant` and `selected`, and the first child is a visually hidden native `input type="checkbox"` named by `label` with `checked` equal to `isSelected`. | Current source and tests | -| FR2 | While enabled, a click on the card surface, a click or Space on the checkbox, or Enter on the checkbox calls `onChange(!isSelected)` exactly once. A click that belongs to nested interactive content, an open Tooltip or HoverCard surface (`component:Tooltip` FR11), or selected text does not toggle. A caller `onClick` runs after the toggle for a surface click, before it for a click or Space on the checkbox, and not at all for Enter; it also runs for clicks that do not toggle, including a click inside an open Tooltip or HoverCard surface. At the next minor, staged as `[breaking]`, a click inside an open layer stops at the layer root and the caller `onClick` no longer receives it (`architecture:layer-runtime` INV17); implementation gap: the current source still delivers that click to `onClick`. A caller `onMouseUp` runs after the card's own handling. | Current source and tests | -| FR3 | Selection adds a 2px inset ring through Card's ring variable, so layout does not move, and composes with any elevation shadow. `default`, `transparent`, and `muted` ring in `--color-accent`; each palette variant rings in its `--color-border-`; a theme-added variant rings in `--selectable-card-ring-color`. Selection also colors the border in the ring color where Card draws one, which is only the `default` variant. Under forced colors, which drop the ring's shadow and repaint the border, a selected card, enabled or disabled, draws a 2px border in the system `Highlight` color on its own edge instead, and gives up the same 2px of padding, so the selection stays visible, layout does not move, and the ring stays on the edge when a fixed-height card scrolls; an unselected card draws none. | Current source and tests | -| FR4 | While enabled, the surface paints the shared hover overlay under a hover-capable pointer and the pressed overlay for mouse and touch presses; a press from any pointer that starts on a nested interactive element shows no pressed paint on the card, since it does not activate the card (`architecture:press-feedback` INV7). A touch press shows at once. Under the touch presentation, its release fades on the theme's exit motion tokens (`--duration-exit`, `--ease-exit`), per `spec:AST-094` FR5; a mouse press keeps the card's desktop press styling. Keyboard focus on the hidden checkbox shows one indicator on the card root (`architecture:interaction-modality` INV3). | Current source and tests | -| FR5 | `isDisabled` dims the card to half opacity, removes the card's own click and mouseup handling and the caller's `onClick` and `onMouseUp` (other caller event props still reach the root) and the hover and pressed overlays (`spec:AST-085` FR6), and keeps the checkbox focusable with `aria-disabled="true"`; no click, Space, or Enter calls `onChange`. The disabled state is reflected on the owning target (`architecture:component-theming-surface` INV6). Implementation gap: the `selectable-card` target reflects `variant` and `selected` but not the disabled state (Current-state impact). | Current source and tests | -| FR6 | `ref` reaches the Card root. Supported DOM, ARIA, data, and event props reach the root; `xstyle`, `className`, and `style` merge after the component's interactive styles. | Current source and tests | +| ID | Invariant | Basis | +| --- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------ | +| FR1 | SelectableCard renders `component:Card` with the given `variant`, `elevation`, `padding`, and sizing. The root also carries the `selectable-card` target reflecting `variant` and `selected`, and the first child is a visually hidden native `input type="checkbox"` named by `label` with `checked` equal to `isSelected`. | Current source and tests | +| FR2 | While enabled, a click on the card surface, a click or Space on the checkbox, or Enter on the checkbox calls `onChange(!isSelected)` exactly once. A click that belongs to nested interactive content, an open Tooltip or HoverCard surface (`component:Tooltip` FR11), or selected text does not toggle. A caller `onClick` runs after the toggle for a surface click, before it for a click or Space on the checkbox, and not at all for Enter; it also runs for clicks that do not toggle, including a click inside an open Tooltip or HoverCard surface. At the next minor, staged as `[breaking]`, a click inside an open layer stops at the layer root and the caller `onClick` no longer receives it (`architecture:layer-runtime` INV17); implementation gap: the current source still delivers that click to `onClick`. A caller `onMouseUp` runs after the card's own handling. | Current source and tests | +| FR3 | Selection adds a 2px inset ring through Card's ring variable, so layout does not move, and composes with any elevation shadow. `default`, `transparent`, and `muted` ring in `--color-accent`; each palette variant rings in its `--color-border-`; a theme-added variant rings in `--selectable-card-ring-color`. Selection also colors the border in the ring color where Card draws one, which is only the `default` variant. Under forced colors, which drop the ring's shadow and repaint the border, a selected card, enabled or disabled, draws a 2px border in the system `Highlight` color on its own edge instead, and gives up the same 2px of padding, so the selection stays visible, the content does not move, and the ring stays on the edge when a fixed-height card scrolls; a card with zero padding has no padding to give up, so its content area loses the 2px on each side. An unselected card draws none. A theme that sets the border color on the `selectable-card` or `card` target owns that color under forced colors too, as it owns the border elsewhere. | Current source and tests | +| FR4 | While enabled, the surface paints the shared hover overlay under a hover-capable pointer and the pressed overlay for mouse and touch presses; a press from any pointer that starts on a nested interactive element shows no pressed paint on the card, since it does not activate the card (`architecture:press-feedback` INV7). A touch press shows at once. Under the touch presentation, its release fades on the theme's exit motion tokens (`--duration-exit`, `--ease-exit`), per `spec:AST-094` FR5; a mouse press keeps the card's desktop press styling. Keyboard focus on the hidden checkbox shows one indicator on the card root (`architecture:interaction-modality` INV3). | Current source and tests | +| FR5 | `isDisabled` dims the card to half opacity, removes the card's own click and mouseup handling and the caller's `onClick` and `onMouseUp` (other caller event props still reach the root) and the hover and pressed overlays (`spec:AST-085` FR6), and keeps the checkbox focusable with `aria-disabled="true"`; no click, Space, or Enter calls `onChange`. The disabled state is reflected on the owning target (`architecture:component-theming-surface` INV6). Implementation gap: the `selectable-card` target reflects `variant` and `selected` but not the disabled state (Current-state impact). | Current source and tests | +| FR6 | `ref` reaches the Card root. Supported DOM, ARIA, data, and event props reach the root; `xstyle`, `className`, and `style` merge after the component's interactive styles. | Current source and tests | ### Allowed variation @@ -242,18 +242,18 @@ Consumer migration instructions belong in consumer docs and release notes. ## Verification map -| Contract | Verification | Representative states | Mutation or failure expectation | Audit section | -| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------- | -| FR1, FR2 | `SelectableCard.test.tsx` surface, checkbox, Enter, and Space tests | Unselected, selected | A missed toggle, a wrong `onChange` value, or a doubled toggle from Space fails. Target-reflection and handler-order tests fail on a lost target, variant, or selection reflection, or a changed order of `onChange` and a caller `onClick`. Gap: no test asserts the order of an enabled caller `onMouseUp`. | `audit:SelectableCard/behavior` | -| FR3 | `SelectableCard.test.tsx` elevation tests; stable visual baseline `core-selectablecard--single-select`; `SelectableCard.stories.tsx` | Selected with elevation; one selected default card beside unselected ones | A lost elevation while selected fails; a changed default ring or border comes back changed for review. Gap: palette and theme-added ring colors have no automated check. | `audit:SelectableCard/theming` | -| FR3 (forced colors) | `SelectableCard.test.tsx` forced-colors test; `SelectableCardForcedColors.a11y.chromium.spec.ts` on the multi-select, color-variants and disabled stories, and a scrolled fixed-height card | Selected and unselected cards under forced colors; a scrolled fixed-height selected card; the same cards outside forced colors | A selected card without a 2px `Highlight` border on its edge under forced colors, a scrolled card whose top or bottom edge loses it, an unselected card with one, or the border outside forced colors fails. | `audit:SelectableCard/a11y` | -| FR4 | `SelectableCard.test.tsx` touch-press test; `CardPress.a11y.chromium.spec.ts` on `core-selectablecard--single-select` | Rest; desktop hover and mouse press; touch press | A hover that does not paint over rest, a mouse press that does not paint over hover, or a touch press that does not match the desktop press or fade fails. `FocusRingOwner.a11y.chromium.spec.ts` fails if a focused nested button shows other than exactly one ring. | `audit:SelectableCard/design` | -| FR5, AR3 | `SelectableCard.test.tsx` disabled tests; `Checkbox.a11y.chromium.spec.ts` `card-disabled` state | Disabled click, Enter, Space | A toggle while disabled, or a disabled card that leaves keyboard reach, fails. `SelectableCardAudit.a11y.chromium.spec.ts` fails on a lost half opacity or a hover overlay on a disabled card. Gap: no test asserts the absent pressed overlay on a disabled card, and the target carries no disabled reflection to test (Current-state impact). | `audit:SelectableCard/a11y` | -| FR2 (nested) | `SelectableCard.test.tsx` nested-button test; `SelectableCardAudit.a11y.chromium.spec.ts` on `core-selectablecard--with-nested-button` | Card with a nested control or selected text | A click on a nested button that toggles the card fails. Gap: no test covers selected-text suppression. | `audit:SelectableCard/behavior` | -| Theming anatomy map | `scripts/check-knowledge.mjs` | Consumer anatomy and current target | Missing, extra, or stale mappings fail repository validation. | `audit:SelectableCard/theming` | -| AR1, AR2, AR4 | `SelectableCard.test.tsx` checkbox tests; `Checkbox.a11y.test.tsx` and `Checkbox.a11y.chromium.spec.ts` SelectableCard states | Unchecked, checked, disabled (`card-unchecked`, `card-checked`, `card-disabled`) | A lost checkbox role or name, a wrong checked state, or a disabled card that is not exposed as unavailable or not reachable fails, including at the accessibility tree. The passthrough test fails if the root gains a role or tab stop; `SelectableCardAudit.a11y.chromium.spec.ts` fails on a missing root focus outline or a ring that changes under hover. | `audit:SelectableCard/a11y` | -| FR6, PR1 | `SelectableCard.test.tsx` passthrough test; source review | Ref; caller props | A `ref`, `data-*`, `className`, or `style` that stops reaching the root fails. Gap: no test asserts `xstyle` or the merge order of the styling inputs, or fails if SelectableCard adds its own listener or timer. | `audit:SelectableCard/behavior` | -| AR5 | `Checkbox.a11y.chromium.spec.ts` aborted-press check on the SelectableCard states | Press that slides off the card before the lift | A toggle after a slide-off lift fails. | `audit:SelectableCard/a11y` | +| Contract | Verification | Representative states | Mutation or failure expectation | Audit section | +| ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------- | +| FR1, FR2 | `SelectableCard.test.tsx` surface, checkbox, Enter, and Space tests | Unselected, selected | A missed toggle, a wrong `onChange` value, or a doubled toggle from Space fails. Target-reflection and handler-order tests fail on a lost target, variant, or selection reflection, or a changed order of `onChange` and a caller `onClick`. Gap: no test asserts the order of an enabled caller `onMouseUp`. | `audit:SelectableCard/behavior` | +| FR3 | `SelectableCard.test.tsx` elevation tests; stable visual baseline `core-selectablecard--single-select`; `SelectableCard.stories.tsx` | Selected with elevation; one selected default card beside unselected ones | A lost elevation while selected fails; a changed default ring or border comes back changed for review. Gap: palette and theme-added ring colors have no automated check. | `audit:SelectableCard/theming` | +| FR3 (forced colors) | `SelectableCard.test.tsx` forced-colors test; `SelectableCardForcedColors.a11y.chromium.spec.ts` on the multi-select, color-variants and disabled stories, a scrolled fixed-height card, and a zero-padding card | Selected and unselected cards under forced colors; a scrolled fixed-height selected card; a selected card with zero padding; the same cards outside forced colors | A selected card without a 2px `Highlight` border on its edge under forced colors, a scrolled card whose top or bottom edge loses it, a zero-padding card without it, an unselected card with one, or the border outside forced colors fails. | `audit:SelectableCard/a11y` | +| FR4 | `SelectableCard.test.tsx` touch-press test; `CardPress.a11y.chromium.spec.ts` on `core-selectablecard--single-select` | Rest; desktop hover and mouse press; touch press | A hover that does not paint over rest, a mouse press that does not paint over hover, or a touch press that does not match the desktop press or fade fails. `FocusRingOwner.a11y.chromium.spec.ts` fails if a focused nested button shows other than exactly one ring. | `audit:SelectableCard/design` | +| FR5, AR3 | `SelectableCard.test.tsx` disabled tests; `Checkbox.a11y.chromium.spec.ts` `card-disabled` state | Disabled click, Enter, Space | A toggle while disabled, or a disabled card that leaves keyboard reach, fails. `SelectableCardAudit.a11y.chromium.spec.ts` fails on a lost half opacity or a hover overlay on a disabled card. Gap: no test asserts the absent pressed overlay on a disabled card, and the target carries no disabled reflection to test (Current-state impact). | `audit:SelectableCard/a11y` | +| FR2 (nested) | `SelectableCard.test.tsx` nested-button test; `SelectableCardAudit.a11y.chromium.spec.ts` on `core-selectablecard--with-nested-button` | Card with a nested control or selected text | A click on a nested button that toggles the card fails. Gap: no test covers selected-text suppression. | `audit:SelectableCard/behavior` | +| Theming anatomy map | `scripts/check-knowledge.mjs` | Consumer anatomy and current target | Missing, extra, or stale mappings fail repository validation. | `audit:SelectableCard/theming` | +| AR1, AR2, AR4 | `SelectableCard.test.tsx` checkbox tests; `Checkbox.a11y.test.tsx` and `Checkbox.a11y.chromium.spec.ts` SelectableCard states | Unchecked, checked, disabled (`card-unchecked`, `card-checked`, `card-disabled`) | A lost checkbox role or name, a wrong checked state, or a disabled card that is not exposed as unavailable or not reachable fails, including at the accessibility tree. The passthrough test fails if the root gains a role or tab stop; `SelectableCardAudit.a11y.chromium.spec.ts` fails on a missing root focus outline or a ring that changes under hover. | `audit:SelectableCard/a11y` | +| FR6, PR1 | `SelectableCard.test.tsx` passthrough test; source review | Ref; caller props | A `ref`, `data-*`, `className`, or `style` that stops reaching the root fails. Gap: no test asserts `xstyle` or the merge order of the styling inputs, or fails if SelectableCard adds its own listener or timer. | `audit:SelectableCard/behavior` | +| AR5 | `Checkbox.a11y.chromium.spec.ts` aborted-press check on the SelectableCard states | Press that slides off the card before the lift | A toggle after a slide-off lift fails. | `audit:SelectableCard/a11y` | ## Decision log diff --git a/packages/core/src/SelectableCard/SelectableCard.tsx b/packages/core/src/SelectableCard/SelectableCard.tsx index 0e2003cf3b5b1..5f1e35a9dc5fd 100644 --- a/packages/core/src/SelectableCard/SelectableCard.tsx +++ b/packages/core/src/SelectableCard/SelectableCard.tsx @@ -193,8 +193,10 @@ const styles = stylex.create({ }, // Forced colors drop the ring's shadow and repaint the border. A selected // card draws a 2px `Highlight` border on its own box instead. The padding - // gives up the same 2px, so the content does not move. A border stays on the - // edge when a fixed-height card scrolls. The focus outline stays separate. + // gives up the same 2px, so the content does not move. A card with no + // padding has none to give up, so its content area loses the 2px. A border + // stays on the edge when a fixed-height card scrolls. The focus outline + // stays separate. selectedForcedColors: { borderWidth: {default: null, '@media (forced-colors: active)': '2px'}, borderStyle: {default: null, '@media (forced-colors: active)': 'solid'}, @@ -581,10 +583,10 @@ export function SelectableCard({ variant, selected: isSelected ? 'true' : 'false', }), - // Rings for the card's own checkbox only; a control in its children - // rings itself. The forced-colors ring is a class here, not in the - // merged styles: a `null` default there would unset the card's border - // and padding in every color mode. + // Rings for the card's own checkbox only. A control in its children + // rings itself. The forced-colors ring is a class here, outside the + // merged styles. A `null` default there would unset the card's + // border and padding in every color mode. stylex.props( focusWithinOwner, isSelected && styles.selectedForcedColors, diff --git a/packages/core/src/SelectableCard/__tests__/SelectableCardForcedColors.a11y.chromium.spec.ts b/packages/core/src/SelectableCard/__tests__/SelectableCardForcedColors.a11y.chromium.spec.ts index 1a1f8d9cffc0c..b51888a64efe0 100644 --- a/packages/core/src/SelectableCard/__tests__/SelectableCardForcedColors.a11y.chromium.spec.ts +++ b/packages/core/src/SelectableCard/__tests__/SelectableCardForcedColors.a11y.chromium.spec.ts @@ -7,8 +7,8 @@ * stories in real Chromium, with forced colors emulated and without * @output Browser evidence that, in forced colors, a selected card draws a 2px * border in the system Highlight color on its own edge, also when a - * fixed-height card scrolls, and an unselected card draws none; outside - * forced colors no card draws it + * fixed-height card scrolls or has zero padding, and an unselected card + * draws none; outside forced colors no card draws it * @position Regression proof for SelectableCard's forced-colors selection * (Chromium only: Playwright's WebKit matches the forced-colors query but * forces nothing) @@ -191,6 +191,39 @@ test('in forced colors a scrolled fixed-height card keeps the ring on its edge', expect(await read(box, midX, Math.floor(box.height) - 1)).toEqual(highlight); }); +test('in forced colors a selected card with zero padding still rings in Highlight', async ({ + page, +}) => { + const {highlight} = await readRings( + page, + 'core-selectablecard--multi-select', + 'active', + ); + const ring = await page.evaluate(() => { + // `padding={0}` sets the container padding variables to zero. + const card = document.querySelector( + '.astryx-selectable-card[data-selected="true"]', + )!; + for (const side of [ + 'inline-start', + 'inline-end', + 'block-start', + 'block-end', + ]) { + card.style.setProperty(`--container-padding-${side}`, '0px'); + } + const style = getComputedStyle(card); + return { + width: parseFloat(style.borderTopWidth), + style: style.borderTopStyle, + color: style.borderTopColor, + padding: parseFloat(style.paddingInlineStart), + }; + }); + expect(ring).toMatchObject({width: 2, style: 'solid', color: highlight}); + expect(ring.padding).toBe(0); +}); + test('outside forced colors no card draws the ring', async ({page}) => { for (const story of [ 'core-selectablecard--multi-select', From 0ffa1360d5a30a7b71d2c66805ddbbe55f27ab1f Mon Sep 17 00:00:00 2001 From: Cindy Zhang Date: Sun, 29 Nov 2026 08:47:07 -0800 Subject: [PATCH 5/7] fix(SelectableCard): draw the forced-colors ring on the ::after layer again The border on the card's own box either moved the content (where padding could not absorb it), overrode a caller's padding, or, without the padding give-back, shifted the layout on every toggle; and a theme's border color won over Highlight. The ::after layer takes no space, so a toggle moves nothing, and a theme does not style it, so the ring keeps Highlight under a theme that sets the card's border color. The one gap: on a fixed-height card whose content scrolls, the layer scrolls with that content. FR3, the changeset and the verification row say so. The browser spec adds a themed case and a case that a toggle moves no card. --- .../selectable-card-forced-colors-selected.md | 2 +- .../SelectableCard/SelectableCard.spec.md | 40 ++--- .../SelectableCard/SelectableCard.test.tsx | 5 +- .../src/SelectableCard/SelectableCard.tsx | 48 +++-- ...ableCardForcedColors.a11y.chromium.spec.ts | 169 ++++++++---------- 5 files changed, 133 insertions(+), 131 deletions(-) diff --git a/.changeset/selectable-card-forced-colors-selected.md b/.changeset/selectable-card-forced-colors-selected.md index 076c955ebe7ed..e13489514d972 100644 --- a/.changeset/selectable-card-forced-colors-selected.md +++ b/.changeset/selectable-card-forced-colors-selected.md @@ -2,6 +2,6 @@ '@astryxdesign/core': patch --- -[fix] SelectableCard: in forced colors (Windows High Contrast), a selected card now draws a 2px border in the system Highlight color on its own edge, so the selection stays visible, also when a fixed-height card scrolls. Before, a selected card painted the same as an unselected one. The border takes its own space, so under forced colors a selected card is up to 2px larger on each side. A theme that sets the card's border color keeps owning it. Normal color modes are unchanged. +[fix] SelectableCard: in forced colors (Windows High Contrast), a selected card now draws a 2px ring in the system Highlight color inside its edge, so the selection stays visible. Before, a selected card painted the same as an unselected one. The ring takes no space, so a toggle moves nothing, and it keeps Highlight under a theme that sets the card's border color. Normal color modes are unchanged. @cixzhang diff --git a/docs/specs/components/SelectableCard/SelectableCard.spec.md b/docs/specs/components/SelectableCard/SelectableCard.spec.md index 606ac712daa4a..de33b3fa0529c 100644 --- a/docs/specs/components/SelectableCard/SelectableCard.spec.md +++ b/docs/specs/components/SelectableCard/SelectableCard.spec.md @@ -141,14 +141,14 @@ Consumer migration instructions belong in consumer docs and release notes. ## Behavioral and layout contract -| ID | Invariant | Basis | -| --- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| FR1 | SelectableCard renders `component:Card` with the given `variant`, `elevation`, `padding`, and sizing. The root also carries the `selectable-card` target reflecting `variant`, `selected`, and, while disabled, `disabled`, and the first child is a visually hidden native `input type="checkbox"` named by `label` with `checked` equal to `isSelected`. | Current source and tests | -| FR2 | While enabled, a click on the card surface, a click or Space on the checkbox, or Enter on the checkbox calls `onChange(!isSelected)` exactly once. A click that belongs to nested interactive content, an open Tooltip or HoverCard surface (`component:Tooltip` FR11), or selected text does not toggle. A caller `onClick` runs after the toggle for a surface click, before it for a click or Space on the checkbox, and not at all for Enter; it also runs for clicks that do not toggle, including a click inside an open Tooltip or HoverCard surface. At the next minor, staged as `[breaking]`, a click inside an open layer stops at the layer root and the caller `onClick` no longer receives it (`architecture:layer-runtime` INV17); implementation gap: the current source still delivers that click to `onClick`. A caller `onMouseUp` runs after the card's own handling. | Current source and tests | -| FR3 | Selection adds a 2px inset ring through Card's ring variable, so layout does not move, and composes with any elevation shadow. `default`, `transparent`, and `muted` ring in `--color-accent`; each palette variant rings in its `--color-border-`; a theme-added variant rings in `--selectable-card-ring-color`. Selection also colors the border in the ring color where Card draws one, which is only the `default` variant. | Current source and tests Under forced colors, which drop the ring's shadow and repaint the border, a selected card, enabled or disabled, draws a 2px border in the system `Highlight` color on its own edge instead, so the selection stays visible, also when a fixed-height card scrolls; an unselected card draws none. That border takes its own space: selecting a card under forced colors adds up to 2px on each side (1px on `default`, which already draws a 1px border), so a card sized by its content grows and a fixed-size card's content area shrinks by that much. A theme that sets the border color on the `selectable-card` or `card` target owns that color under forced colors too, as it owns the border elsewhere. | -| FR4 | While enabled, the surface paints the shared hover overlay under a hover-capable pointer and the pressed overlay for mouse and touch presses; a press from any pointer that starts on a nested interactive element shows no pressed paint on the card, since it does not activate the card (`architecture:press-feedback` INV7). A touch press shows at once. Under the touch presentation, its release fades on the theme's exit motion tokens (`--duration-exit`, `--ease-exit`), per `spec:AST-094` FR5; a mouse press keeps the card's desktop press styling. Keyboard focus on the hidden checkbox shows one indicator on the card root (`architecture:interaction-modality` INV3). | Current source and tests | -| FR5 | `isDisabled` dims the card to half opacity, removes the card's own click and mouseup handling and the caller's `onClick` and `onMouseUp` (other caller event props still reach the root) and the hover and pressed overlays (`spec:AST-085` FR6), and keeps the checkbox focusable with `aria-disabled="true"`; no click, Space, or Enter calls `onChange`. The disabled state is reflected on the owning target as `data-disabled` (`architecture:component-theming-surface` INV6). | Current source and tests | -| FR6 | `ref` reaches the Card root. Supported DOM, ARIA, data, and event props reach the root; `xstyle`, `className`, and `style` merge after the component's interactive styles. | Current source and tests | +| ID | Invariant | Basis | +| --- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| FR1 | SelectableCard renders `component:Card` with the given `variant`, `elevation`, `padding`, and sizing. The root also carries the `selectable-card` target reflecting `variant`, `selected`, and, while disabled, `disabled`, and the first child is a visually hidden native `input type="checkbox"` named by `label` with `checked` equal to `isSelected`. | Current source and tests | +| FR2 | While enabled, a click on the card surface, a click or Space on the checkbox, or Enter on the checkbox calls `onChange(!isSelected)` exactly once. A click that belongs to nested interactive content, an open Tooltip or HoverCard surface (`component:Tooltip` FR11), or selected text does not toggle. A caller `onClick` runs after the toggle for a surface click, before it for a click or Space on the checkbox, and not at all for Enter; it also runs for clicks that do not toggle, including a click inside an open Tooltip or HoverCard surface. At the next minor, staged as `[breaking]`, a click inside an open layer stops at the layer root and the caller `onClick` no longer receives it (`architecture:layer-runtime` INV17); implementation gap: the current source still delivers that click to `onClick`. A caller `onMouseUp` runs after the card's own handling. | Current source and tests | +| FR3 | Selection adds a 2px inset ring through Card's ring variable, so layout does not move, and composes with any elevation shadow. `default`, `transparent`, and `muted` ring in `--color-accent`; each palette variant rings in its `--color-border-`; a theme-added variant rings in `--selectable-card-ring-color`. Selection also colors the border in the ring color where Card draws one, which is only the `default` variant. | Current source and tests Under forced colors, which drop the ring's shadow and repaint the border, a selected card, enabled or disabled, draws a 2px ring in the system `Highlight` color inside its edge instead, on a layer that takes no space and that a theme does not style, so the selection stays visible, a toggle moves nothing, and the ring keeps `Highlight` under a theme that sets the card's border color; an unselected card draws none. On a fixed-height card whose content scrolls, the ring scrolls with that content. | +| FR4 | While enabled, the surface paints the shared hover overlay under a hover-capable pointer and the pressed overlay for mouse and touch presses; a press from any pointer that starts on a nested interactive element shows no pressed paint on the card, since it does not activate the card (`architecture:press-feedback` INV7). A touch press shows at once. Under the touch presentation, its release fades on the theme's exit motion tokens (`--duration-exit`, `--ease-exit`), per `spec:AST-094` FR5; a mouse press keeps the card's desktop press styling. Keyboard focus on the hidden checkbox shows one indicator on the card root (`architecture:interaction-modality` INV3). | Current source and tests | +| FR5 | `isDisabled` dims the card to half opacity, removes the card's own click and mouseup handling and the caller's `onClick` and `onMouseUp` (other caller event props still reach the root) and the hover and pressed overlays (`spec:AST-085` FR6), and keeps the checkbox focusable with `aria-disabled="true"`; no click, Space, or Enter calls `onChange`. The disabled state is reflected on the owning target as `data-disabled` (`architecture:component-theming-surface` INV6). | Current source and tests | +| FR6 | `ref` reaches the Card root. Supported DOM, ARIA, data, and event props reach the root; `xstyle`, `className`, and `style` merge after the component's interactive styles. | Current source and tests | ### Allowed variation @@ -239,18 +239,18 @@ Consumer migration instructions belong in consumer docs and release notes. ## Verification map -| Contract | Verification | Representative states | Mutation or failure expectation | Audit section | -| ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------- | -| FR1, FR2 | `SelectableCard.test.tsx` surface, checkbox, Enter, and Space tests | Unselected, selected | A missed toggle, a wrong `onChange` value, or a doubled toggle from Space fails. Target-reflection and handler-order tests fail on a lost target, variant, selection, or disabled reflection, or a changed order of `onChange` and a caller `onClick`. Gap: no test asserts the order of an enabled caller `onMouseUp`. | `audit:SelectableCard/behavior` | -| FR3 | `SelectableCard.test.tsx` elevation tests; stable visual baseline `core-selectablecard--single-select`; `SelectableCard.stories.tsx` | Selected with elevation; one selected default card beside unselected ones | A lost elevation while selected fails; a changed default ring or border comes back changed for review. Gap: palette and theme-added ring colors have no automated check. | `audit:SelectableCard/theming` | -| FR3 (forced colors) | `SelectableCard.test.tsx` forced-colors test; `SelectableCardForcedColors.a11y.chromium.spec.ts` on the multi-select, color-variants and disabled stories, a scrolled fixed-height card, and a zero-padding card | Selected and unselected cards under forced colors; a scrolled fixed-height selected card; a selected card with zero padding; the same cards outside forced colors | A selected card without a 2px `Highlight` border on its edge under forced colors, a scrolled card whose top or bottom edge loses it, a zero-padding card without it, an unselected card with one, or the border outside forced colors fails. | `audit:SelectableCard/a11y` | -| FR4 | `SelectableCard.test.tsx` touch-press test; `CardPress.a11y.chromium.spec.ts` on `core-selectablecard--single-select` | Rest; desktop hover and mouse press; touch press | A hover that does not paint over rest, a mouse press that does not paint over hover, or a touch press that does not match the desktop press or fade fails. `FocusRingOwner.a11y.chromium.spec.ts` fails if a focused nested button shows other than exactly one ring. | `audit:SelectableCard/design` | -| FR5, AR3 | `SelectableCard.test.tsx` disabled tests; `Checkbox.a11y.chromium.spec.ts` `card-disabled` state | Disabled click, Enter, Space | A toggle while disabled, or a disabled card that leaves keyboard reach, fails. `SelectableCardAudit.a11y.chromium.spec.ts` fails on a lost half opacity, a hover overlay on a disabled card, or a missing `data-disabled`. Gap: no test asserts the absent pressed overlay on a disabled card. | `audit:SelectableCard/a11y` | -| FR2 (nested) | `SelectableCard.test.tsx` nested-button test; `SelectableCardAudit.a11y.chromium.spec.ts` on `core-selectablecard--with-nested-button` | Card with a nested control or selected text | A click on a nested button that toggles the card fails. Gap: no test covers selected-text suppression. | `audit:SelectableCard/behavior` | -| Theming anatomy map | `scripts/check-knowledge.mjs` | Consumer anatomy and current target | Missing, extra, or stale mappings fail repository validation. | `audit:SelectableCard/theming` | -| AR1, AR2, AR4 | `SelectableCard.test.tsx` checkbox tests; `Checkbox.a11y.test.tsx` and `Checkbox.a11y.chromium.spec.ts` SelectableCard states | Unchecked, checked, disabled (`card-unchecked`, `card-checked`, `card-disabled`) | A lost checkbox role or name, a wrong checked state, or a disabled card that is not exposed as unavailable or not reachable fails, including at the accessibility tree. The passthrough test fails if the root gains a role or tab stop; `SelectableCardAudit.a11y.chromium.spec.ts` fails on a missing root focus outline or a ring that changes under hover. | `audit:SelectableCard/a11y` | -| FR6, PR1 | `SelectableCard.test.tsx` passthrough test; source review | Ref; caller props | A `ref`, `data-*`, `className`, or `style` that stops reaching the root fails. Gap: no test asserts `xstyle` or the merge order of the styling inputs, or fails if SelectableCard adds its own listener or timer. | `audit:SelectableCard/behavior` | -| AR5 | `Checkbox.a11y.chromium.spec.ts` aborted-press check on the SelectableCard states | Press that slides off the card before the lift | A toggle after a slide-off lift fails. | `audit:SelectableCard/a11y` | +| Contract | Verification | Representative states | Mutation or failure expectation | Audit section | +| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------- | +| FR1, FR2 | `SelectableCard.test.tsx` surface, checkbox, Enter, and Space tests | Unselected, selected | A missed toggle, a wrong `onChange` value, or a doubled toggle from Space fails. Target-reflection and handler-order tests fail on a lost target, variant, selection, or disabled reflection, or a changed order of `onChange` and a caller `onClick`. Gap: no test asserts the order of an enabled caller `onMouseUp`. | `audit:SelectableCard/behavior` | +| FR3 | `SelectableCard.test.tsx` elevation tests; stable visual baseline `core-selectablecard--single-select`; `SelectableCard.stories.tsx` | Selected with elevation; one selected default card beside unselected ones | A lost elevation while selected fails; a changed default ring or border comes back changed for review. Gap: palette and theme-added ring colors have no automated check. | `audit:SelectableCard/theming` | +| FR3 (forced colors) | `SelectableCard.test.tsx` forced-colors test; `SelectableCardForcedColors.a11y.chromium.spec.ts` on the multi-select, color-variants and disabled stories, the probe theme, a toggle, and a zero-padding card | Selected and unselected cards under forced colors; a selected card under a theme that sets the card's border color; a toggle; a selected card with zero padding; the same cards outside forced colors | A selected card without a 2px `Highlight` ring inside its edge under forced colors, a themed card whose ring loses `Highlight`, a toggle that moves a card, an unselected card with a ring, or a ring outside forced colors fails. Gap: no test covers the ring on a fixed-height card whose content scrolls. | `audit:SelectableCard/a11y` | +| FR4 | `SelectableCard.test.tsx` touch-press test; `CardPress.a11y.chromium.spec.ts` on `core-selectablecard--single-select` | Rest; desktop hover and mouse press; touch press | A hover that does not paint over rest, a mouse press that does not paint over hover, or a touch press that does not match the desktop press or fade fails. `FocusRingOwner.a11y.chromium.spec.ts` fails if a focused nested button shows other than exactly one ring. | `audit:SelectableCard/design` | +| FR5, AR3 | `SelectableCard.test.tsx` disabled tests; `Checkbox.a11y.chromium.spec.ts` `card-disabled` state | Disabled click, Enter, Space | A toggle while disabled, or a disabled card that leaves keyboard reach, fails. `SelectableCardAudit.a11y.chromium.spec.ts` fails on a lost half opacity, a hover overlay on a disabled card, or a missing `data-disabled`. Gap: no test asserts the absent pressed overlay on a disabled card. | `audit:SelectableCard/a11y` | +| FR2 (nested) | `SelectableCard.test.tsx` nested-button test; `SelectableCardAudit.a11y.chromium.spec.ts` on `core-selectablecard--with-nested-button` | Card with a nested control or selected text | A click on a nested button that toggles the card fails. Gap: no test covers selected-text suppression. | `audit:SelectableCard/behavior` | +| Theming anatomy map | `scripts/check-knowledge.mjs` | Consumer anatomy and current target | Missing, extra, or stale mappings fail repository validation. | `audit:SelectableCard/theming` | +| AR1, AR2, AR4 | `SelectableCard.test.tsx` checkbox tests; `Checkbox.a11y.test.tsx` and `Checkbox.a11y.chromium.spec.ts` SelectableCard states | Unchecked, checked, disabled (`card-unchecked`, `card-checked`, `card-disabled`) | A lost checkbox role or name, a wrong checked state, or a disabled card that is not exposed as unavailable or not reachable fails, including at the accessibility tree. The passthrough test fails if the root gains a role or tab stop; `SelectableCardAudit.a11y.chromium.spec.ts` fails on a missing root focus outline or a ring that changes under hover. | `audit:SelectableCard/a11y` | +| FR6, PR1 | `SelectableCard.test.tsx` passthrough test; source review | Ref; caller props | A `ref`, `data-*`, `className`, or `style` that stops reaching the root fails. Gap: no test asserts `xstyle` or the merge order of the styling inputs, or fails if SelectableCard adds its own listener or timer. | `audit:SelectableCard/behavior` | +| AR5 | `Checkbox.a11y.chromium.spec.ts` aborted-press check on the SelectableCard states | Press that slides off the card before the lift | A toggle after a slide-off lift fails. | `audit:SelectableCard/a11y` | ## Decision log diff --git a/packages/core/src/SelectableCard/SelectableCard.test.tsx b/packages/core/src/SelectableCard/SelectableCard.test.tsx index faa03184086a3..b9f3dc9a40553 100644 --- a/packages/core/src/SelectableCard/SelectableCard.test.tsx +++ b/packages/core/src/SelectableCard/SelectableCard.test.tsx @@ -362,8 +362,7 @@ describe('SelectableCard forced colors (FR3)', () => { , ); const css = getForcedColorsRules(); - expect(css).toContain('border-color: highlight'); - expect(css).toContain('border-width: 2px'); - expect(css).not.toMatch(/::after\s*\{[^}]*border-color: highlight/); + expect(css).toMatch(/::after\s*\{[^}]*border-color: highlight/); + expect(css).toMatch(/::after\s*\{[^}]*border-width: 2px/); }); }); diff --git a/packages/core/src/SelectableCard/SelectableCard.tsx b/packages/core/src/SelectableCard/SelectableCard.tsx index 93157269be6f2..510d51f2f59ed 100644 --- a/packages/core/src/SelectableCard/SelectableCard.tsx +++ b/packages/core/src/SelectableCard/SelectableCard.tsx @@ -191,15 +191,34 @@ const styles = stylex.create({ }, }, }, - // Forced colors drop the ring's shadow and repaint the border. A selected - // card draws a 2px `Highlight` border on its own box instead. A border stays - // on the edge when a fixed-height card scrolls. The border takes its own - // space, so a selected card is up to 2px larger on each side. The focus - // outline stays separate. + // Forced colors drop the ring's shadow and repaint the border. The `::after` + // layer draws a 2px `Highlight` ring inside the card instead. It takes no + // space, so a toggle moves nothing. A theme does not style the layer, so the + // ring keeps its color. The focus outline stays separate. On a fixed-height + // card whose content scrolls, the layer scrolls with that content. selectedForcedColors: { - borderWidth: {default: null, '@media (forced-colors: active)': '2px'}, - borderStyle: {default: null, '@media (forced-colors: active)': 'solid'}, - borderColor: {default: null, '@media (forced-colors: active)': 'Highlight'}, + '::after': { + borderWidth: {default: null, '@media (forced-colors: active)': '2px'}, + borderStyle: {default: null, '@media (forced-colors: active)': 'solid'}, + borderColor: { + default: null, + '@media (forced-colors: active)': 'Highlight', + }, + }, + }, + // A disabled card has no overlay layer, so the forced-colors ring brings + // its own. + selectedForcedColorsLayer: { + '::after': { + content: {default: null, '@media (forced-colors: active)': '""'}, + position: {default: null, '@media (forced-colors: active)': 'absolute'}, + inset: {default: null, '@media (forced-colors: active)': 0}, + borderRadius: { + default: null, + '@media (forced-colors: active)': 'inherit', + }, + pointerEvents: {default: null, '@media (forced-colors: active)': 'none'}, + }, }, disabled: { cursor: 'default', @@ -563,14 +582,9 @@ export function SelectableCard({ selected: isSelected ? 'true' : 'false', disabled: isDisabled ? 'disabled' : null, }), - // Rings for the card's own checkbox only. A control in its children - // rings itself. The forced-colors ring is a class here, outside the - // merged styles. A `null` default there would unset the card's - // border in every color mode. - stylex.props( - focusWithinOwner, - isSelected && styles.selectedForcedColors, - ), + // Rings for the card's own checkbox only; a control in its children + // rings itself. + stylex.props(focusWithinOwner), classNameProp, style, )} @@ -579,6 +593,8 @@ export function SelectableCard({ styles.interactive, isSelected && selectedStyleForVariant(variant), !isDisabled && styles.overlay, + isSelected && styles.selectedForcedColors, + isSelected && isDisabled && styles.selectedForcedColorsLayer, // The touch press's strength and release, on the element the // controller writes to; the `::after` above paints off it. !isDisabled && interactionOverlayStyles.pressedAlpha, diff --git a/packages/core/src/SelectableCard/__tests__/SelectableCardForcedColors.a11y.chromium.spec.ts b/packages/core/src/SelectableCard/__tests__/SelectableCardForcedColors.a11y.chromium.spec.ts index b51888a64efe0..b9df342d75985 100644 --- a/packages/core/src/SelectableCard/__tests__/SelectableCardForcedColors.a11y.chromium.spec.ts +++ b/packages/core/src/SelectableCard/__tests__/SelectableCardForcedColors.a11y.chromium.spec.ts @@ -5,10 +5,11 @@ * @file SelectableCardForcedColors.a11y.chromium.spec.ts * @input The built SelectableCard multi-select, color-variants and disabled * stories in real Chromium, with forced colors emulated and without - * @output Browser evidence that, in forced colors, a selected card draws a 2px - * border in the system Highlight color on its own edge, also when a - * fixed-height card scrolls or has zero padding, and an unselected card - * draws none; outside forced colors no card draws it + * @output Browser evidence that, in forced colors, a selected card paints a + * 2px ring in the system Highlight color inside its edge, also with zero + * padding and under a theme that sets the card's border color, that a + * toggle moves no card, and that an unselected card paints none; outside + * forced colors the layer paints no ring * @position Regression proof for SelectableCard's forced-colors selection * (Chromium only: Playwright's WebKit matches the forced-colors query but * forces nothing) @@ -41,15 +42,24 @@ type Ring = { color: string; }; -/** Each card's own border, and the system Highlight color. */ -async function readRings( +async function open( page: Page, story: string, forcedColors: 'active' | 'none', -): Promise<{rings: Ring[]; highlight: string}> { + theme?: string, +): Promise { await page.emulateMedia({forcedColors}); - await page.goto(`${storybook.origin}/iframe.html?id=${story}&viewMode=story`); + const globals = theme ? `&globals=astryxTheme:${theme}` : ''; + await page.goto( + `${storybook.origin}/iframe.html?id=${story}&viewMode=story${globals}`, + ); await page.locator('.astryx-selectable-card').first().waitFor(); +} + +/** Each card's `::after` border, and the system Highlight color. */ +async function readRings( + page: Page, +): Promise<{rings: Ring[]; highlight: string}> { return page.evaluate(() => { const probe = document.createElement('span'); probe.style.color = 'Highlight'; @@ -59,7 +69,7 @@ async function readRings( const rings = [ ...document.querySelectorAll('.astryx-selectable-card'), ].map(card => { - const layer = getComputedStyle(card); + const layer = getComputedStyle(card, '::after'); const input = card.querySelector('input'); return { label: input?.getAttribute('aria-label') ?? '', @@ -73,6 +83,23 @@ async function readRings( }); } +function expectRings({rings, highlight}: {rings: Ring[]; highlight: string}) { + const selected = rings.filter(ring => ring.selected); + const unselected = rings.filter(ring => !ring.selected); + expect(selected.length).toBeGreaterThan(0); + expect(unselected.length).toBeGreaterThan(0); + for (const ring of selected) { + expect(ring, ring.label).toMatchObject({ + width: 2, + style: 'solid', + color: highlight, + }); + } + for (const ring of unselected) { + expect(ring.width, ring.label).toBe(0); + } +} + for (const story of [ 'core-selectablecard--multi-select', 'core-selectablecard--color-variants', @@ -81,31 +108,23 @@ for (const story of [ test(`${story}: in forced colors a selected card rings in Highlight and an unselected card does not`, async ({ page, }) => { - const {rings, highlight} = await readRings(page, story, 'active'); - const selected = rings.filter(ring => ring.selected); - const unselected = rings.filter(ring => !ring.selected); - expect(selected.length).toBeGreaterThan(0); - expect(unselected.length).toBeGreaterThan(0); - for (const ring of selected) { - expect(ring, ring.label).toMatchObject({ - width: 2, - style: 'solid', - color: highlight, - }); - } - for (const ring of unselected) { - expect( - ring.width === 2 && ring.color === highlight, - `${ring.label}: ${ring.width}px ${ring.color}`, - ).toBe(false); - } + await open(page, story, 'active'); + expectRings(await readRings(page)); }); } +test('in forced colors the ring keeps Highlight under a theme that sets the card border color', async ({ + page, +}) => { + // The probe theme sets `borderColor` on the `selectable-card` target. + await open(page, 'core-selectablecard--multi-select', 'active', 'probe'); + expectRings(await readRings(page)); +}); + test('in forced colors the selected card paints Highlight inside its edge', async ({ page, }) => { - await readRings(page, 'core-selectablecard--multi-select', 'active'); + await open(page, 'core-selectablecard--multi-select', 'active'); const pixel = async ( clip: {x: number; y: number; width: number; height: number}, x: number, @@ -134,71 +153,38 @@ test('in forced colors the selected card paints Highlight inside its edge', asyn const card = page .locator(`.astryx-selectable-card[data-selected="${selected}"]`) .first(); - // The card's own 2px border, halfway down. - return pixel((await card.boundingBox())!, 1); + // One pixel inside the card's own 1px edge, halfway down: on the ring. + return pixel((await card.boundingBox())!, 2); }; expect(await edge(true)).toEqual(highlight); expect(await edge(false)).not.toEqual(highlight); }); -test('in forced colors a scrolled fixed-height card keeps the ring on its edge', async ({ - page, -}) => { - await readRings(page, 'core-selectablecard--multi-select', 'active'); - await page.evaluate(() => { - const swatch = document.createElement('div'); - swatch.id = 'highlight-swatch'; - Object.assign(swatch.style, { - position: 'fixed', - right: '0', - bottom: '0', - width: '20px', - height: '20px', - backgroundColor: 'Highlight', - }); - document.body.append(swatch); - // A selected card with a fixed height scrolls its content, as Card does - // for a `height`. Fill it past that height and scroll to the end. - const card = document.querySelector( - '.astryx-selectable-card[data-selected="true"]', - )!; - card.style.height = '64px'; - card.style.overflow = 'auto'; - const filler = document.createElement('div'); - filler.style.height = '300px'; - filler.textContent = 'Long content'; - card.append(filler); - card.scrollTop = card.scrollHeight; - }); - const read = async ( - clip: {x: number; y: number; width: number; height: number}, - x: number, - y: number, - ) => { - const png = PNG.sync.read(await page.screenshot({clip})); - const i = (y * png.width + x) * 4; - return [png.data[i], png.data[i + 1], png.data[i + 2]]; - }; - const swatch = (await page.locator('#highlight-swatch').boundingBox())!; - const highlight = await read(swatch, 10, 10); - const box = (await page - .locator('.astryx-selectable-card[data-selected="true"]') - .first() - .boundingBox())!; - const midX = Math.floor(box.width / 2); - // The top and bottom edges carry the ring after the scroll. - expect(await read(box, midX, 0)).toEqual(highlight); - expect(await read(box, midX, Math.floor(box.height) - 1)).toEqual(highlight); +test('in forced colors a toggle moves no card', async ({page}) => { + await open(page, 'core-selectablecard--multi-select', 'active'); + const boxes = async () => + page.evaluate(() => + [ + ...document.querySelectorAll('.astryx-selectable-card'), + ].map(card => { + const {x, y, width, height} = card.getBoundingClientRect(); + return {x, y, width, height}; + }), + ); + const before = await boxes(); + // The story selects only its first card; the second starts unselected. + const card = page.locator('.astryx-selectable-card').nth(1); + await expect(card).toHaveAttribute('data-selected', 'false'); + await card.click(); + await expect(card).toHaveAttribute('data-selected', 'true'); + expect(await boxes()).toEqual(before); }); test('in forced colors a selected card with zero padding still rings in Highlight', async ({ page, }) => { - const {highlight} = await readRings( - page, - 'core-selectablecard--multi-select', - 'active', - ); + await open(page, 'core-selectablecard--multi-select', 'active'); + const {highlight} = await readRings(page); const ring = await page.evaluate(() => { // `padding={0}` sets the container padding variables to zero. const card = document.querySelector( @@ -212,27 +198,28 @@ test('in forced colors a selected card with zero padding still rings in Highligh ]) { card.style.setProperty(`--container-padding-${side}`, '0px'); } - const style = getComputedStyle(card); + const layer = getComputedStyle(card, '::after'); return { - width: parseFloat(style.borderTopWidth), - style: style.borderTopStyle, - color: style.borderTopColor, - padding: parseFloat(style.paddingInlineStart), + width: parseFloat(layer.borderTopWidth), + style: layer.borderTopStyle, + color: layer.borderTopColor, + padding: parseFloat(getComputedStyle(card).paddingInlineStart), }; }); expect(ring).toMatchObject({width: 2, style: 'solid', color: highlight}); expect(ring.padding).toBe(0); }); -test('outside forced colors no card draws the ring', async ({page}) => { +test('outside forced colors the layer paints no ring', async ({page}) => { for (const story of [ 'core-selectablecard--multi-select', 'core-selectablecard--color-variants', 'core-selectablecard--disabled', ]) { - const {rings} = await readRings(page, story, 'none'); + await open(page, story, 'none'); + const {rings} = await readRings(page); for (const ring of rings) { - expect(ring.width, `${story} ${ring.label}`).not.toBe(2); + expect(ring.width, `${story} ${ring.label}`).toBe(0); } } }); From 9a20347a564881c363d5395b497d6939bcb842ed Mon Sep 17 00:00:00 2001 From: Cindy Zhang Date: Sun, 29 Nov 2026 08:59:40 -0800 Subject: [PATCH 6/7] test(SelectableCard): the toggle case turns the only selected card off With another card still selected, the row keeps its tallest card's height, so a ring that took space would not move anything. Turning the only selected card off makes such a ring change the row's height. --- .../SelectableCardForcedColors.a11y.chromium.spec.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/core/src/SelectableCard/__tests__/SelectableCardForcedColors.a11y.chromium.spec.ts b/packages/core/src/SelectableCard/__tests__/SelectableCardForcedColors.a11y.chromium.spec.ts index b9df342d75985..56da44ad508d8 100644 --- a/packages/core/src/SelectableCard/__tests__/SelectableCardForcedColors.a11y.chromium.spec.ts +++ b/packages/core/src/SelectableCard/__tests__/SelectableCardForcedColors.a11y.chromium.spec.ts @@ -172,11 +172,12 @@ test('in forced colors a toggle moves no card', async ({page}) => { }), ); const before = await boxes(); - // The story selects only its first card; the second starts unselected. - const card = page.locator('.astryx-selectable-card').nth(1); - await expect(card).toHaveAttribute('data-selected', 'false'); - await card.click(); + // The story selects only its first card. Turning it off leaves no + // selected card, so a ring that took space would change the row's height. + const card = page.locator('.astryx-selectable-card').first(); await expect(card).toHaveAttribute('data-selected', 'true'); + await card.click(); + await expect(card).toHaveAttribute('data-selected', 'false'); expect(await boxes()).toEqual(before); }); From 3b8c81911c44abe09337551bd8d5437b8b2b7860 Mon Sep 17 00:00:00 2001 From: Cindy Zhang Date: Sun, 29 Nov 2026 09:52:24 -0800 Subject: [PATCH 7/7] docs(SelectableCard): FR3 states the forced-colors ring in its Invariant, with the narrower theme claim Move the forced-colors sentence from FR3's Basis cell to the end of its Invariant and restore the Basis. A theme can author a ::after block, so the record, comment and changeset now say only that a theme's border color on the card does not reach the layer. The changeset names the scrolled fixed-height case. --- .../selectable-card-forced-colors-selected.md | 2 +- .../SelectableCard/SelectableCard.spec.md | 16 ++++++++-------- .../core/src/SelectableCard/SelectableCard.tsx | 9 ++++----- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/.changeset/selectable-card-forced-colors-selected.md b/.changeset/selectable-card-forced-colors-selected.md index e13489514d972..41ee2289e2cb0 100644 --- a/.changeset/selectable-card-forced-colors-selected.md +++ b/.changeset/selectable-card-forced-colors-selected.md @@ -2,6 +2,6 @@ '@astryxdesign/core': patch --- -[fix] SelectableCard: in forced colors (Windows High Contrast), a selected card now draws a 2px ring in the system Highlight color inside its edge, so the selection stays visible. Before, a selected card painted the same as an unselected one. The ring takes no space, so a toggle moves nothing, and it keeps Highlight under a theme that sets the card's border color. Normal color modes are unchanged. +[fix] SelectableCard: in forced colors (Windows High Contrast), a selected card now draws a 2px ring in the system Highlight color inside its edge, so the selection stays visible. Before, a selected card painted the same as an unselected one. The ring takes no space, so a toggle moves nothing, and it keeps Highlight under a theme that sets the card's border color. On a fixed-height card whose content scrolls, the ring scrolls with that content. Normal color modes are unchanged. @cixzhang diff --git a/docs/specs/components/SelectableCard/SelectableCard.spec.md b/docs/specs/components/SelectableCard/SelectableCard.spec.md index de33b3fa0529c..856779b1a3b22 100644 --- a/docs/specs/components/SelectableCard/SelectableCard.spec.md +++ b/docs/specs/components/SelectableCard/SelectableCard.spec.md @@ -141,14 +141,14 @@ Consumer migration instructions belong in consumer docs and release notes. ## Behavioral and layout contract -| ID | Invariant | Basis | -| --- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| FR1 | SelectableCard renders `component:Card` with the given `variant`, `elevation`, `padding`, and sizing. The root also carries the `selectable-card` target reflecting `variant`, `selected`, and, while disabled, `disabled`, and the first child is a visually hidden native `input type="checkbox"` named by `label` with `checked` equal to `isSelected`. | Current source and tests | -| FR2 | While enabled, a click on the card surface, a click or Space on the checkbox, or Enter on the checkbox calls `onChange(!isSelected)` exactly once. A click that belongs to nested interactive content, an open Tooltip or HoverCard surface (`component:Tooltip` FR11), or selected text does not toggle. A caller `onClick` runs after the toggle for a surface click, before it for a click or Space on the checkbox, and not at all for Enter; it also runs for clicks that do not toggle, including a click inside an open Tooltip or HoverCard surface. At the next minor, staged as `[breaking]`, a click inside an open layer stops at the layer root and the caller `onClick` no longer receives it (`architecture:layer-runtime` INV17); implementation gap: the current source still delivers that click to `onClick`. A caller `onMouseUp` runs after the card's own handling. | Current source and tests | -| FR3 | Selection adds a 2px inset ring through Card's ring variable, so layout does not move, and composes with any elevation shadow. `default`, `transparent`, and `muted` ring in `--color-accent`; each palette variant rings in its `--color-border-`; a theme-added variant rings in `--selectable-card-ring-color`. Selection also colors the border in the ring color where Card draws one, which is only the `default` variant. | Current source and tests Under forced colors, which drop the ring's shadow and repaint the border, a selected card, enabled or disabled, draws a 2px ring in the system `Highlight` color inside its edge instead, on a layer that takes no space and that a theme does not style, so the selection stays visible, a toggle moves nothing, and the ring keeps `Highlight` under a theme that sets the card's border color; an unselected card draws none. On a fixed-height card whose content scrolls, the ring scrolls with that content. | -| FR4 | While enabled, the surface paints the shared hover overlay under a hover-capable pointer and the pressed overlay for mouse and touch presses; a press from any pointer that starts on a nested interactive element shows no pressed paint on the card, since it does not activate the card (`architecture:press-feedback` INV7). A touch press shows at once. Under the touch presentation, its release fades on the theme's exit motion tokens (`--duration-exit`, `--ease-exit`), per `spec:AST-094` FR5; a mouse press keeps the card's desktop press styling. Keyboard focus on the hidden checkbox shows one indicator on the card root (`architecture:interaction-modality` INV3). | Current source and tests | -| FR5 | `isDisabled` dims the card to half opacity, removes the card's own click and mouseup handling and the caller's `onClick` and `onMouseUp` (other caller event props still reach the root) and the hover and pressed overlays (`spec:AST-085` FR6), and keeps the checkbox focusable with `aria-disabled="true"`; no click, Space, or Enter calls `onChange`. The disabled state is reflected on the owning target as `data-disabled` (`architecture:component-theming-surface` INV6). | Current source and tests | -| FR6 | `ref` reaches the Card root. Supported DOM, ARIA, data, and event props reach the root; `xstyle`, `className`, and `style` merge after the component's interactive styles. | Current source and tests | +| ID | Invariant | Basis | +| --- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------ | +| FR1 | SelectableCard renders `component:Card` with the given `variant`, `elevation`, `padding`, and sizing. The root also carries the `selectable-card` target reflecting `variant`, `selected`, and, while disabled, `disabled`, and the first child is a visually hidden native `input type="checkbox"` named by `label` with `checked` equal to `isSelected`. | Current source and tests | +| FR2 | While enabled, a click on the card surface, a click or Space on the checkbox, or Enter on the checkbox calls `onChange(!isSelected)` exactly once. A click that belongs to nested interactive content, an open Tooltip or HoverCard surface (`component:Tooltip` FR11), or selected text does not toggle. A caller `onClick` runs after the toggle for a surface click, before it for a click or Space on the checkbox, and not at all for Enter; it also runs for clicks that do not toggle, including a click inside an open Tooltip or HoverCard surface. At the next minor, staged as `[breaking]`, a click inside an open layer stops at the layer root and the caller `onClick` no longer receives it (`architecture:layer-runtime` INV17); implementation gap: the current source still delivers that click to `onClick`. A caller `onMouseUp` runs after the card's own handling. | Current source and tests | +| FR3 | Selection adds a 2px inset ring through Card's ring variable, so layout does not move, and composes with any elevation shadow. `default`, `transparent`, and `muted` ring in `--color-accent`; each palette variant rings in its `--color-border-`; a theme-added variant rings in `--selectable-card-ring-color`. Selection also colors the border in the ring color where Card draws one, which is only the `default` variant. Under forced colors, which drop the ring's shadow and repaint the border, a selected card, enabled or disabled, draws a 2px ring in the system `Highlight` color inside its edge instead, on a layer that takes no space and that a theme's border color on the card does not reach, so the selection stays visible, a toggle moves nothing, and the ring keeps `Highlight` under a theme that sets the card's border color; an unselected card draws none. On a fixed-height card whose content scrolls, the ring scrolls with that content. | Current source and tests | +| FR4 | While enabled, the surface paints the shared hover overlay under a hover-capable pointer and the pressed overlay for mouse and touch presses; a press from any pointer that starts on a nested interactive element shows no pressed paint on the card, since it does not activate the card (`architecture:press-feedback` INV7). A touch press shows at once. Under the touch presentation, its release fades on the theme's exit motion tokens (`--duration-exit`, `--ease-exit`), per `spec:AST-094` FR5; a mouse press keeps the card's desktop press styling. Keyboard focus on the hidden checkbox shows one indicator on the card root (`architecture:interaction-modality` INV3). | Current source and tests | +| FR5 | `isDisabled` dims the card to half opacity, removes the card's own click and mouseup handling and the caller's `onClick` and `onMouseUp` (other caller event props still reach the root) and the hover and pressed overlays (`spec:AST-085` FR6), and keeps the checkbox focusable with `aria-disabled="true"`; no click, Space, or Enter calls `onChange`. The disabled state is reflected on the owning target as `data-disabled` (`architecture:component-theming-surface` INV6). | Current source and tests | +| FR6 | `ref` reaches the Card root. Supported DOM, ARIA, data, and event props reach the root; `xstyle`, `className`, and `style` merge after the component's interactive styles. | Current source and tests | ### Allowed variation diff --git a/packages/core/src/SelectableCard/SelectableCard.tsx b/packages/core/src/SelectableCard/SelectableCard.tsx index 510d51f2f59ed..d34981d08ff0a 100644 --- a/packages/core/src/SelectableCard/SelectableCard.tsx +++ b/packages/core/src/SelectableCard/SelectableCard.tsx @@ -191,11 +191,10 @@ const styles = stylex.create({ }, }, }, - // Forced colors drop the ring's shadow and repaint the border. The `::after` - // layer draws a 2px `Highlight` ring inside the card instead. It takes no - // space, so a toggle moves nothing. A theme does not style the layer, so the - // ring keeps its color. The focus outline stays separate. On a fixed-height - // card whose content scrolls, the layer scrolls with that content. + // Forced colors drop the ring's shadow and repaint the border, so selection + // needs its own ring. The layer takes no space, so a toggle moves nothing. A + // theme's border color on the card does not reach the layer. On a + // fixed-height card whose content scrolls, the layer scrolls with it. selectedForcedColors: { '::after': { borderWidth: {default: null, '@media (forced-colors: active)': '2px'},