Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

test(a11y): point the ClickableCard button binding at the card surface (#6150)

홍규진af44c3a6660e
diff --git a/apps/storybook/rtl-audit/verified-not-applicable.json b/apps/storybook/rtl-audit/verified-not-applicable.json
index 798391b7fc..4e46b6f5cb 100644
--- a/apps/storybook/rtl-audit/verified-not-applicable.json
+++ b/apps/storybook/rtl-audit/verified-not-applicable.json
@@ -101,6 +101,10 @@
"packages/core/src/SelectableCard/index.ts": "sha256:9cf677856807a09ee444ce68b21118bca9729592485f892da7e0bb64ee1d7501"
}
},
+ {
+ "component": "core/ClickableCard",
+ "reason": "ClickableCard composes Card and adds only an interactive layer: a hover/active overlay pinned with `inset: 0`, a bordered variant whose padding is expressed through the logical `--container-padding-inline-*`/`--container-padding-block-*` variables, and a visually-hidden role-bearing control clipped to 1×1. Neither its source nor Card's carries a physical `left`/`right`, margin, padding, or border anywhere; nothing scrolls, drags, or sits to one side. The stories render text, a price, and an Astryx Button with no directional glyph. Verified by the audit's own detectors over every ClickableCard story: D1 icon-mirror, D5 positional-mirror, and the decoration pass all returned N-A with zero not-RTL findings."
+ },
{
"component": "core/AspectRatio",
"reason": "AspectRatio only establishes a symmetric aspect-ratio box and sizes its single child to fill that box. It has no inline-axis placement, ordering, directional glyph, scrolling, dragging, overlay, or keyboard behavior."
diff --git a/packages/core/src/Button/__tests__/Button.a11y.chromium.spec.ts b/packages/core/src/Button/__tests__/Button.a11y.chromium.spec.ts
index c9b9cd8406..ae1974197b 100644
--- a/packages/core/src/Button/__tests__/Button.a11y.chromium.spec.ts
+++ b/packages/core/src/Button/__tests__/Button.a11y.chromium.spec.ts
@@ -21,7 +21,13 @@
* ./Button.a11y.known-failures.ts, both shared with the jsdom lane.
*/
-import {expect, test, type CDPSession, type Page} from '@playwright/test';
+import {
+ expect,
+ test,
+ type CDPSession,
+ type Locator,
+ type Page,
+} from '@playwright/test';
import {
BUTTON_PATTERN,
blockingResults,
@@ -93,6 +99,14 @@ async function activationsOn(page: Page): Promise<number> {
return Number(raw ?? '0');
}
+function pointerTargetFor(
+ page: Page,
+ state: ButtonBindingRow,
+): Locator | undefined {
+ const selector = (state as ButtonBindingState).pointerTargetSelector;
+ return selector == null ? undefined : page.locator(selector).first();
+}
+
async function runState(
page: Page,
cdp: CDPSession,
@@ -111,6 +125,7 @@ async function runState(
return createChromiumHarness({
page,
subject: page.locator('#storybook-root').getByRole('button').first(),
+ pointerTarget: pointerTargetFor(page, state),
cdp,
});
},
@@ -306,6 +321,7 @@ test('every expectation is exercised by at least one bound state', async ({
.locator('#storybook-root')
.getByRole('button')
.first(),
+ pointerTarget: pointerTargetFor(page, state),
cdp,
});
},
diff --git a/packages/core/src/Button/__tests__/Button.a11y.known-failures.ts b/packages/core/src/Button/__tests__/Button.a11y.known-failures.ts
index 0f7fe78ed1..26a22b2940 100644
--- a/packages/core/src/Button/__tests__/Button.a11y.known-failures.ts
+++ b/packages/core/src/Button/__tests__/Button.a11y.known-failures.ts
@@ -83,33 +83,4 @@ export const BUTTON_KNOWN_FAILURES: ReadonlyArray<KnownFailure> = [
userImpact: 'The same, from an icon button.',
reason: 'Inherited from Button, as above.',
},
-
- // ---- ClickableCard's role-bearing element cannot be clicked -------------
- {
- expectation: 'button.action.survives-an-aborted-press',
- binding: 'ClickableCard',
- state: 'clickable-card',
- evidenceLayer: 'real-browser',
- failureEquals:
- 'a pointer press cannot land on this control: something else is on top of it at its own centre, so there is no press here to abort',
- standardsReference: 'WCAG 2.2 2.5.2 Pointer Cancellation (Level A)',
- userImpact:
- 'The same defect seen from the other side: pointer cancellation cannot be demonstrated on a control no pointer press can land on. Recorded rather than reported green — a serene pass here would claim an outcome nobody observed.',
- reason:
- 'Same cause as the record above. It is a second record rather than a wider one because a known failure names exactly one outcome, and these two would be fixed and verified separately.',
- },
- {
- expectation: 'button.action.runs-on-pointer',
- binding: 'ClickableCard',
- state: 'clickable-card',
- evidenceLayer: 'real-browser',
- failureEquals:
- 'a pointer could not reach this control within 2000ms: the browser never found it visible, stable, and able to receive a pointer event. Something is covering it, or it is clipped to nothing.',
- standardsReference:
- 'Current Astryx buttons family FR2 and WAI-ARIA APG Button operability requirement; supports WCAG 2.2 4.1.2 Name, Role, Value (Level A)',
- userImpact:
- "Anyone whose tooling acts on the accessible object rather than on pixels — a speech-input user saying the card's name, or assistive technology dispatching a click at the element it is told is the button — aims at a 1×1 control the card's own content paints over. A sighted mouse user is unaffected: they click the card surface, which handles it.",
- reason:
- 'ClickableCard deliberately splits the surface that takes the click from the hidden button that carries the role and name. Reconciling the two is a design-system decision, not a change this contract should make.',
- },
];
diff --git a/packages/core/src/Button/__tests__/Button.a11y.renders.tsx b/packages/core/src/Button/__tests__/Button.a11y.renders.tsx
index e87015db19..0d75b70bac 100644
--- a/packages/core/src/Button/__tests__/Button.a11y.renders.tsx
+++ b/packages/core/src/Button/__tests__/Button.a11y.renders.tsx
@@ -88,12 +88,19 @@ export const BUTTON_STATE_RENDERS: Record<ButtonStateId, StateRender> = {
),
'clickable-card': activate => (
- <ClickableCard label="Open billing settings" onClick={activate}>
+ <ClickableCard
+ data-a11y-pointer-target
+ label="Open billing settings"
+ onClick={activate}>
<div>Billing</div>
</ClickableCard>
),
'clickable-card-disabled': activate => (
- <ClickableCard label="Open billing settings" isDisabled onClick={activate}>
+ <ClickableCard
+ data-a11y-pointer-target
+ label="Open billing settings"
+ isDisabled
+ onClick={activate}>
<div>Billing</div>
</ClickableCard>
),
diff --git a/packages/core/src/Button/__tests__/Button.a11y.states.ts b/packages/core/src/Button/__tests__/Button.a11y.states.ts
index 63ef1a7601..1edbb8df2f 100644
--- a/packages/core/src/Button/__tests__/Button.a11y.states.ts
+++ b/packages/core/src/Button/__tests__/Button.a11y.states.ts
@@ -92,6 +92,13 @@ export interface ButtonBindingState {
* typo here is reported as a stale inventory, not as a standards failure.
*/
readonly visibleLabel: string | null;
+ /**
+ * The surface that receives pointer input when it is not the role-bearing
+ * element. ClickableCard keeps its button/link hidden for role, name, and
+ * keyboard focus, and takes the pointer on the card surface; a binding that
+ * aimed the pointer at the hidden control would be testing the wrong surface.
+ */
+ readonly pointerTargetSelector?: string;
/** The checked-in Storybook story the Chromium lane drives. */
readonly storyId: string;
/**
@@ -220,6 +227,7 @@ export const BUTTON_BINDING_STATES = [
"a card whose whole surface performs an action, through the hidden button that carries the card's role and name",
facts: facts(),
visibleLabel: null,
+ pointerTargetSelector: '[data-a11y-pointer-target]',
storyId: 'a11y-button-pattern--clickable-card-default',
},
{
@@ -228,6 +236,7 @@ export const BUTTON_BINDING_STATES = [
summary: 'a disabled action card',
facts: facts({operable: false, focusable: false, unavailable: true}),
visibleLabel: null,
+ pointerTargetSelector: '[data-a11y-pointer-target]',
storyId: 'a11y-button-pattern--clickable-card-disabled',
},
diff --git a/packages/core/src/ClickableCard/ClickableCard.test.tsx b/packages/core/src/ClickableCard/ClickableCard.test.tsx
index ef6d67c312..0229c56d7c 100644
--- a/packages/core/src/ClickableCard/ClickableCard.test.tsx
+++ b/packages/core/src/ClickableCard/ClickableCard.test.tsx
@@ -2,6 +2,7 @@
import {describe, it, expect, vi} from 'vitest';
import {render, screen, fireEvent} from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
import {ClickableCard} from './ClickableCard';
describe('ClickableCard', () => {
@@ -47,6 +48,47 @@ describe('ClickableCard', () => {
expect(handleClick).toHaveBeenCalledTimes(1);
});
+ it('calls onClick once when the accessible control itself is clicked', () => {
+ const handleClick = vi.fn();
+ render(
+ <ClickableCard label="Test card" onClick={handleClick}>
+ <span>Content</span>
+ </ClickableCard>,
+ );
+ // Pointer activation aimed at the element carrying the role — what
+ // speech input, assistive technology, and automation dispatch.
+ fireEvent.click(screen.getByRole('button', {name: 'Test card'}));
+ expect(handleClick).toHaveBeenCalledTimes(1);
+ });
+
+ it('passes the card surface as currentTarget for surface clicks', () => {
+ const seen: EventTarget[] = [];
+ render(
+ <ClickableCard
+ label="Test card"
+ onClick={e => seen.push(e.currentTarget)}>
+ <span>Content</span>
+ </ClickableCard>,
+ );
+ fireEvent.click(screen.getByText('Content'));
+ expect(seen).toHaveLength(1);
+ expect(seen[0]).toBe(screen.getByText('Content').parentElement);
+ });
+
+ it('calls onClick exactly once when the surface of an href card is clicked without preventDefault', () => {
+ const handleClick = vi.fn();
+ render(
+ <ClickableCard label="Nav card" href="/settings" onClick={handleClick}>
+ <span>Content</span>
+ </ClickableCard>,
+ );
+ // The container hook proxies the surface click to the link with
+ // `link.click()`; that synthetic click bubbles back through the card and
+ // must not run the consumer callback a second time.
+ fireEvent.click(screen.getByText('Content'));
+ expect(handleClick).toHaveBeenCalledTimes(1);
+ });
+
it('does NOT call onClick when a nested button is clicked', () => {
const handleCardClick = vi.fn();
const handleButtonClick = vi.fn();
@@ -86,25 +128,80 @@ describe('ClickableCard', () => {
expect(link).toHaveAttribute('target', '_blank');
});
- it('disabled button is disabled', () => {
+ it('disabled button is disabled and the surface runs nothing', () => {
const handleClick = vi.fn();
render(
<ClickableCard label="Disabled" onClick={handleClick} isDisabled>
- Content
+ <span>Content</span>
</ClickableCard>,
);
const button = screen.getByRole('button', {name: 'Disabled'});
expect(button).toBeDisabled();
+ fireEvent.click(screen.getByText('Content'));
+ fireEvent.click(button);
+ expect(handleClick).not.toHaveBeenCalled();
});
- it('disabled link has aria-disabled', () => {
+ it('disabled link has aria-disabled, leaves the tab order, and the surface runs nothing', () => {
+ const handleClick = vi.fn();
render(
- <ClickableCard label="Disabled link" href="/settings" isDisabled>
- Content
+ <ClickableCard
+ label="Disabled link"
+ href="/settings"
+ onClick={handleClick}
+ isDisabled>
+ <span>Content</span>
</ClickableCard>,
);
const link = screen.getByRole('link', {name: 'Disabled link'});
expect(link).toHaveAttribute('aria-disabled', 'true');
+ expect(link).toHaveAttribute('tabindex', '-1');
+ fireEvent.click(screen.getByText('Content'));
+ expect(handleClick).not.toHaveBeenCalled();
+ });
+
+ it('runs onClick once from the keyboard via the hidden button', async () => {
+ const user = userEvent.setup();
+ const handleClick = vi.fn();
+ render(
+ <ClickableCard label="Test card" onClick={handleClick}>
+ <span>Content</span>
+ </ClickableCard>,
+ );
+ await user.tab();
+ expect(screen.getByRole('button', {name: 'Test card'})).toHaveFocus();
+ await user.keyboard('{Enter}');
+ await user.keyboard(' ');
+ expect(handleClick).toHaveBeenCalledTimes(2);
+ });
+
+ it('does NOT call onClick when a nested input is clicked', () => {
+ const handleCardClick = vi.fn();
+ render(
+ <ClickableCard label="Test card" onClick={handleCardClick}>
+ <input aria-label="Quantity" readOnly value="1" />
+ </ClickableCard>,
+ );
+ fireEvent.click(screen.getByRole('textbox', {name: 'Quantity'}));
+ expect(handleCardClick).not.toHaveBeenCalled();
+ });
+
+ it('does NOT call onClick when text inside the card is selected', () => {
+ const handleClick = vi.fn();
+ render(
+ <ClickableCard label="Test card" onClick={handleClick}>
+ <span>Selectable body text</span>
+ </ClickableCard>,
+ );
+ const text = screen.getByText('Selectable body text');
+ const range = document.createRange();
+ range.selectNodeContents(text);
+ const selection = document.getSelection()!;
+ selection.removeAllRanges();
+ selection.addRange(range);
+ fireEvent.click(text);
+ expect(handleClick).not.toHaveBeenCalled();
+ selection.removeAllRanges();
});
describe('elevation', () => {