@astryxdesign/core 0.7.2 → 0.7.3-canary.06872b4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/dist/CheckboxInput/CheckboxInput.d.ts.map +1 -1
  2. package/dist/CheckboxInput/CheckboxInput.js +19 -24
  3. package/dist/DropdownMenu/DropdownMenu.d.ts.map +1 -1
  4. package/dist/DropdownMenu/DropdownMenu.js +52 -10
  5. package/dist/DropdownMenu/DropdownMenuContext.d.ts +34 -1
  6. package/dist/DropdownMenu/DropdownMenuContext.d.ts.map +1 -1
  7. package/dist/DropdownMenu/DropdownMenuContext.js +15 -0
  8. package/dist/DropdownMenu/DropdownMenuSubMenu.d.ts +21 -2
  9. package/dist/DropdownMenu/DropdownMenuSubMenu.d.ts.map +1 -1
  10. package/dist/DropdownMenu/DropdownMenuSubMenu.js +375 -42
  11. package/dist/DropdownMenu/menuRegionStops.d.ts +2 -2
  12. package/dist/DropdownMenu/menuRegionStops.js +2 -2
  13. package/dist/FileInput/FileInput.d.ts.map +1 -1
  14. package/dist/FileInput/FileInput.js +14 -12
  15. package/dist/Selector/SelectorOption.d.ts.map +1 -1
  16. package/dist/Selector/SelectorOption.js +1 -0
  17. package/dist/Slider/Slider.d.ts.map +1 -1
  18. package/dist/Slider/Slider.js +7 -14
  19. package/dist/Switch/Switch.d.ts.map +1 -1
  20. package/dist/Switch/Switch.js +12 -14
  21. package/dist/Switch/switch.markers.stylex.d.ts +2 -0
  22. package/dist/Switch/switch.markers.stylex.d.ts.map +1 -1
  23. package/dist/Switch/switch.markers.stylex.js +6 -0
  24. package/dist/TimeInput/TimeInput.d.ts +2 -1
  25. package/dist/TimeInput/TimeInput.d.ts.map +1 -1
  26. package/dist/Tooltip/Tooltip.d.ts.map +1 -1
  27. package/dist/Tooltip/Tooltip.js +36 -14
  28. package/dist/Tooltip/useTooltip.d.ts.map +1 -1
  29. package/dist/Tooltip/useTooltip.js +11 -2
  30. package/dist/TopNav/TopNav.d.ts.map +1 -1
  31. package/dist/TopNav/TopNav.js +2 -2
  32. package/dist/TopNav/TopNavHeading.d.ts.map +1 -1
  33. package/dist/TopNav/TopNavHeading.js +1 -0
  34. package/dist/Typeahead/Typeahead.d.ts.map +1 -1
  35. package/dist/Typeahead/Typeahead.js +14 -2
  36. package/dist/astryx.css +4 -2
  37. package/dist/hooks/useMenuPress.d.ts +11 -1
  38. package/dist/hooks/useMenuPress.d.ts.map +1 -1
  39. package/dist/hooks/useMenuPress.js +43 -5
  40. package/dist/utils/timeParser.d.ts +4 -0
  41. package/dist/utils/timeParser.d.ts.map +1 -1
  42. package/dist/utils/timeParser.js +9 -2
  43. package/package.json +4 -4
  44. package/scripts/agent-doc-state.mjs +35 -8
  45. package/src/BottomSheet/BottomSheet.spec.md +13 -6
  46. package/src/BottomSheet/BottomSheetSwitcher.spec.md +121 -51
  47. package/src/CheckboxInput/CheckboxInput.test.tsx +44 -5
  48. package/src/CheckboxInput/CheckboxInput.tsx +16 -26
  49. package/src/CheckboxInput/__tests__/Checkbox.a11y.states.ts +3 -3
  50. package/src/CheckboxList/CheckboxList.test.tsx +9 -6
  51. package/src/ContextMenu/ContextMenu.test.tsx +41 -0
  52. package/src/DateRangeInput/DateRangeInput.spec.md +13 -13
  53. package/src/DropdownMenu/DropdownMenu.spec.md +33 -2
  54. package/src/DropdownMenu/DropdownMenu.tsx +79 -8
  55. package/src/DropdownMenu/DropdownMenuContext.public.test.ts +22 -0
  56. package/src/DropdownMenu/DropdownMenuContext.tsx +39 -1
  57. package/src/DropdownMenu/DropdownMenuSubMenu.doc.mjs +16 -1
  58. package/src/DropdownMenu/DropdownMenuSubMenu.test.tsx +623 -1
  59. package/src/DropdownMenu/DropdownMenuSubMenu.tsx +556 -99
  60. package/src/DropdownMenu/__tests__/SubMenuHeaderFooter.a11y.chromium.spec.ts +267 -0
  61. package/src/DropdownMenu/menuRegionStops.ts +2 -2
  62. package/src/DropdownMenu/modules/useMenuPress.spec.md +9 -0
  63. package/src/FileInput/FileInput.test.tsx +30 -7
  64. package/src/FileInput/FileInput.tsx +21 -11
  65. package/src/Selector/Selector.spec.md +11 -11
  66. package/src/Selector/Selector.test.tsx +16 -0
  67. package/src/Selector/SelectorOption.tsx +4 -0
  68. package/src/SideNav/SideNav.test.tsx +35 -0
  69. package/src/Slider/Slider.spec.md +11 -11
  70. package/src/Slider/Slider.test.tsx +3 -3
  71. package/src/Slider/Slider.tsx +8 -15
  72. package/src/Switch/Switch.test.tsx +29 -8
  73. package/src/Switch/Switch.tsx +13 -14
  74. package/src/Switch/__tests__/Switch.a11y.states.ts +2 -2
  75. package/src/Switch/switch.markers.stylex.ts +4 -0
  76. package/src/Table/Table.spec.md +2 -0
  77. package/src/Table/plugins/infiniteScroll/useTableInfiniteScroll.spec.md +244 -0
  78. package/src/Table/plugins/selection/useTableSelection.test.tsx +5 -3
  79. package/src/Table/plugins/virtualization/useTableVirtualization.spec.md +266 -0
  80. package/src/TimeInput/TimeInput.doc.mjs +5 -3
  81. package/src/TimeInput/TimeInput.test.tsx +20 -0
  82. package/src/TimeInput/TimeInput.tsx +2 -1
  83. package/src/Tokenizer/Tokenizer.spec.md +28 -28
  84. package/src/Tooltip/Tooltip.test.tsx +51 -6
  85. package/src/Tooltip/Tooltip.tsx +41 -18
  86. package/src/Tooltip/__tests__/Tooltip.a11y.chromium.spec.ts +129 -0
  87. package/src/Tooltip/__tests__/Tooltip.a11y.renders.tsx +86 -0
  88. package/src/Tooltip/__tests__/Tooltip.a11y.states.ts +132 -0
  89. package/src/Tooltip/__tests__/Tooltip.a11y.test.tsx +126 -0
  90. package/src/Tooltip/__tests__/TooltipHoverBridge.a11y.chromium.spec.ts +74 -0
  91. package/src/Tooltip/useTooltip.test.tsx +23 -0
  92. package/src/Tooltip/useTooltip.tsx +22 -9
  93. package/src/TopNav/TopNav.tsx +11 -1
  94. package/src/TopNav/TopNavHeading.tsx +1 -0
  95. package/src/TopNav/__tests__/TopNavMobileLongHeading.a11y.chromium.spec.ts +74 -0
  96. package/src/Typeahead/Typeahead.test.tsx +89 -0
  97. package/src/Typeahead/Typeahead.tsx +15 -2
  98. package/src/hooks/useMenuPress.ts +45 -7
  99. package/src/utils/timeParser.test.ts +11 -0
  100. package/src/utils/timeParser.ts +9 -2
@@ -242,28 +242,51 @@ export function Tooltip({
242
242
  return;
243
243
  }
244
244
 
245
+ const attach = (el: HTMLElement) => {
246
+ // Use combined ref for position + interaction
247
+ tooltip.ref(el);
248
+
249
+ // Set aria-describedby, merging with existing
250
+ const existingDescribedBy = el.getAttribute('aria-describedby');
251
+ el.setAttribute(
252
+ 'aria-describedby',
253
+ mergeIds(existingDescribedBy, tooltip.describedBy) ?? '',
254
+ );
255
+
256
+ return () => {
257
+ tooltip.ref(null);
258
+ if (existingDescribedBy) {
259
+ el.setAttribute('aria-describedby', existingDescribedBy);
260
+ } else {
261
+ el.removeAttribute('aria-describedby');
262
+ }
263
+ };
264
+ };
265
+
245
266
  const el = anchorRef.current;
246
- if (!el) {
247
- return;
267
+ if (el) {
268
+ return attach(el);
248
269
  }
249
270
 
250
- // Use combined ref for position + interaction
251
- tooltip.ref(el);
252
-
253
- // Set aria-describedby, merging with existing
254
- const existingDescribedBy = el.getAttribute('aria-describedby');
255
- el.setAttribute(
256
- 'aria-describedby',
257
- mergeIds(existingDescribedBy, tooltip.describedBy) ?? '',
258
- );
259
-
260
- return () => {
261
- tooltip.ref(null);
262
- if (existingDescribedBy) {
263
- el.setAttribute('aria-describedby', existingDescribedBy);
264
- } else {
265
- el.removeAttribute('aria-describedby');
271
+ // React attaches an ancestor's ref after its descendants' layout effects,
272
+ // so a tooltip rendered inside its own anchor (SideNavItem's collapsed
273
+ // rail tooltip) still sees null here on mount, and this effect's deps
274
+ // never change to re-run it. Re-check once the commit has attached all
275
+ // refs; if the anchor is still gone, this tooltip has no anchor, as before.
276
+ let detach: (() => void) | undefined;
277
+ let cancelled = false;
278
+ queueMicrotask(() => {
279
+ if (cancelled) {
280
+ return;
266
281
  }
282
+ const el = anchorRef.current;
283
+ if (el) {
284
+ detach = attach(el);
285
+ }
286
+ });
287
+ return () => {
288
+ cancelled = true;
289
+ detach?.();
267
290
  };
268
291
  }, [anchorRef, tooltip.ref, tooltip.describedBy]);
269
292
 
@@ -0,0 +1,129 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Tooltip.a11y.chromium.spec.ts
5
+ * @input Built tooltip stories and TOOLTIP_PATTERN in real Chromium
6
+ * @output Browser evidence for every tooltip expectation across Tooltip's and useTooltip's representative states
7
+ * @position Chromium lane of the Tooltip binding
8
+ */
9
+
10
+ import {
11
+ expect,
12
+ test,
13
+ type CDPSession,
14
+ type Locator,
15
+ type Page,
16
+ } from '@playwright/test';
17
+ import {
18
+ TOOLTIP_PATTERN,
19
+ blockingResults,
20
+ checkAccessibilitySpec,
21
+ formatFailures,
22
+ neverExercised,
23
+ summarize,
24
+ type BindingResult,
25
+ } from '@astryxdesign/a11y-spec';
26
+ import {
27
+ createChromiumHarness,
28
+ holdMotionStill,
29
+ } from '@astryxdesign/a11y-spec/chromium';
30
+ import {
31
+ DEFAULT_STORYBOOK_DIR,
32
+ serveStorybook,
33
+ type StaticServer,
34
+ } from '@astryxdesign/a11y-spec/storybook';
35
+ import {
36
+ TOOLTIP_BINDING_STATES,
37
+ type TooltipBindingState,
38
+ } from './Tooltip.a11y.states';
39
+
40
+ let storybook: StaticServer;
41
+
42
+ test.beforeAll(async () => {
43
+ storybook = await serveStorybook(
44
+ process.env.ASTRYX_STORYBOOK_DIR ?? DEFAULT_STORYBOOK_DIR,
45
+ );
46
+ });
47
+
48
+ test.afterAll(async () => {
49
+ await storybook?.close();
50
+ });
51
+
52
+ function storyUrl(storyId: string): string {
53
+ return `${storybook.origin}/iframe.html?id=${storyId}&viewMode=story`;
54
+ }
55
+
56
+ async function mountState(
57
+ page: Page,
58
+ state: TooltipBindingState,
59
+ ): Promise<{subject: Locator; related: Record<string, Locator>}> {
60
+ await page.goto(storyUrl(state.storyId), {waitUntil: 'load'});
61
+ await holdMotionStill(page);
62
+ const root = page.locator('#storybook-root');
63
+ const subject =
64
+ state.triggerRole == null
65
+ ? root.getByText(state.triggerText, {exact: true})
66
+ : root.getByRole(state.triggerRole, {
67
+ name: state.triggerText,
68
+ exact: true,
69
+ });
70
+ await expect(subject).toBeVisible();
71
+ return {
72
+ subject,
73
+ related: {
74
+ // The layer may mount the tooltip outside the story root, and it stays
75
+ // in the page while hidden, so it is found page-wide, hidden included.
76
+ tooltip: page.getByRole('tooltip', {includeHidden: true}),
77
+ before: root.getByRole('button', {
78
+ name: 'Before the trigger',
79
+ exact: true,
80
+ }),
81
+ after: root.getByRole('button', {
82
+ name: 'After the trigger',
83
+ exact: true,
84
+ }),
85
+ },
86
+ };
87
+ }
88
+
89
+ async function runState(
90
+ page: Page,
91
+ cdp: CDPSession,
92
+ state: TooltipBindingState,
93
+ ): Promise<BindingResult> {
94
+ return checkAccessibilitySpec({
95
+ spec: TOOLTIP_PATTERN,
96
+ binding: 'Tooltip',
97
+ state: state.id,
98
+ facts: state.facts,
99
+ mount: async () => {
100
+ const {subject, related} = await mountState(page, state);
101
+ return createChromiumHarness({page, cdp, subject, related});
102
+ },
103
+ });
104
+ }
105
+
106
+ test('every tooltip expectation is exercised by a Tooltip state', async ({
107
+ page,
108
+ }) => {
109
+ test.setTimeout(3 * 60 * 1000);
110
+ const cdp = await page.context().newCDPSession(page);
111
+ const results: BindingResult[] = [];
112
+ for (const state of TOOLTIP_BINDING_STATES) {
113
+ results.push(await runState(page, cdp, state));
114
+ }
115
+ expect(neverExercised(results)).toEqual([]);
116
+ });
117
+
118
+ for (const state of TOOLTIP_BINDING_STATES) {
119
+ test(`Tooltip [${state.id}] — ${state.summary}`, async ({page}) => {
120
+ test.setTimeout(2 * 60 * 1000);
121
+ const cdp = await page.context().newCDPSession(page);
122
+ const result = await runState(page, cdp, state);
123
+ const report = summarize(TOOLTIP_PATTERN, [result]);
124
+ // Required rows block (AST-020 FR9); advisory rows report.
125
+ expect(formatFailures(blockingResults([result]))).toBe('');
126
+ expect(report.unrunLayers).toEqual([]);
127
+ expect(report.counts.unexpectedPass).toBe(0);
128
+ });
129
+ }
@@ -0,0 +1,86 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ /**
6
+ * @file Tooltip.a11y.renders.tsx
7
+ * @input One tooltip binding state from Tooltip.a11y.states.ts
8
+ * @output The React tree every lane renders for that state (the jsdom test directly, the story through Storybook): a page button before the trigger, the trigger and its tooltip, and a page button after it
9
+ * @position Shared fixture for the Tooltip and useTooltip binding
10
+ */
11
+
12
+ import {useRef, type ReactElement} from 'react';
13
+ import {Button} from '../../Button/Button';
14
+ import {isRenderable} from '../../utils/isRenderable';
15
+ import {Tooltip} from '../Tooltip';
16
+ import {useTooltip} from '../useTooltip';
17
+ import type {TooltipBindingState} from './Tooltip.a11y.states';
18
+
19
+ const HINT_ID = 'tooltip-a11y-hint';
20
+
21
+ type TriggerState = Pick<
22
+ TooltipBindingState,
23
+ 'attachment' | 'triggerText' | 'content' | 'hint'
24
+ >;
25
+
26
+ /** A caller button the tooltip attaches to through `anchorRef`. */
27
+ function AnchorRefTrigger({state}: {state: TriggerState}): ReactElement {
28
+ const anchorRef = useRef<HTMLButtonElement>(null);
29
+ return (
30
+ <>
31
+ <button
32
+ ref={anchorRef}
33
+ type="button"
34
+ aria-describedby={state.hint == null ? undefined : HINT_ID}>
35
+ {state.triggerText}
36
+ </button>
37
+ <Tooltip anchorRef={anchorRef} content={state.content} />
38
+ </>
39
+ );
40
+ }
41
+
42
+ /** A caller button wired by hand through `useTooltip`. */
43
+ function HookTrigger({state}: {state: TriggerState}): ReactElement {
44
+ const tooltip = useTooltip();
45
+ return (
46
+ <>
47
+ <button
48
+ ref={tooltip.ref}
49
+ type="button"
50
+ aria-describedby={tooltip.describedBy}>
51
+ {state.triggerText}
52
+ </button>
53
+ {tooltip.renderTooltip(state.content)}
54
+ </>
55
+ );
56
+ }
57
+
58
+ function Trigger({state}: {state: TriggerState}): ReactElement {
59
+ switch (state.attachment) {
60
+ case 'wrapped-element':
61
+ return (
62
+ <Tooltip content={state.content}>
63
+ <Button label={state.triggerText} />
64
+ </Tooltip>
65
+ );
66
+ case 'text':
67
+ return <Tooltip content={state.content}>{state.triggerText}</Tooltip>;
68
+ case 'anchor-ref':
69
+ return <AnchorRefTrigger state={state} />;
70
+ case 'hook':
71
+ return <HookTrigger state={state} />;
72
+ }
73
+ }
74
+
75
+ export function renderTooltipState(state: TriggerState): ReactElement {
76
+ return (
77
+ <div style={{padding: 64}}>
78
+ <button type="button">Before the trigger</button>{' '}
79
+ <Trigger state={state} />
80
+ {isRenderable(state.hint) ? (
81
+ <span id={HINT_ID}> {state.hint}</span>
82
+ ) : null}{' '}
83
+ <button type="button">After the trigger</button>
84
+ </div>
85
+ );
86
+ }
@@ -0,0 +1,132 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Tooltip.a11y.states.ts
5
+ * @input Tooltip's and useTooltip's representative states and the facts TOOLTIP_PATTERN reads
6
+ * @output TOOLTIP_BINDING_STATES and the explicit ownership exclusions for this binding
7
+ * @position Binding inventory shared by the jsdom test and the Chromium spec (Tooltip and useTooltip under spec:AST-020 FR15)
8
+ */
9
+
10
+ import type {TooltipStateFacts} from '@astryxdesign/a11y-spec';
11
+
12
+ /**
13
+ * How the caller attaches the tooltip: wrapping an element, wrapping plain
14
+ * text, pointing `anchorRef` at its own element, or calling `useTooltip`.
15
+ */
16
+ export type TooltipAttachment =
17
+ 'wrapped-element' | 'text' | 'anchor-ref' | 'hook';
18
+
19
+ export interface TooltipBindingState {
20
+ readonly id: string;
21
+ readonly summary: string;
22
+ readonly storyId: string;
23
+ readonly attachment: TooltipAttachment;
24
+ /**
25
+ * The trigger's visible text. A `button` trigger is also named by it; a
26
+ * text trigger has no role, so the lanes find it by this text.
27
+ */
28
+ readonly triggerText: string;
29
+ readonly triggerRole: 'button' | null;
30
+ /** The tooltip `content`. */
31
+ readonly content: string;
32
+ /** A visible hint the trigger is already described by, besides the tooltip. */
33
+ readonly hint?: string;
34
+ readonly facts: TooltipStateFacts;
35
+ }
36
+
37
+ const story = (id: string) => `a11y-tooltip--${id}`;
38
+
39
+ /** Tooltip's and useTooltip's default hover delay. */
40
+ const DEFAULT_DELAY: TooltipStateFacts = {showsOnHover: true, showDelayMs: 200};
41
+
42
+ export const TOOLTIP_BINDING_STATES = [
43
+ {
44
+ id: 'wrapped-button',
45
+ summary:
46
+ 'a Tooltip wrapping a Button, which attaches to the Button and describes it',
47
+ storyId: story('wrapped-button'),
48
+ attachment: 'wrapped-element',
49
+ triggerText: 'Save',
50
+ triggerRole: 'button',
51
+ content: 'Saves your changes to this draft',
52
+ facts: DEFAULT_DELAY,
53
+ },
54
+ {
55
+ id: 'text-trigger',
56
+ summary:
57
+ 'a Tooltip wrapping plain text, which renders its own focusable inline trigger',
58
+ storyId: story('text-trigger'),
59
+ attachment: 'text',
60
+ triggerText: 'Draft',
61
+ triggerRole: null,
62
+ content: 'Only you can see a draft',
63
+ facts: DEFAULT_DELAY,
64
+ },
65
+ {
66
+ id: 'anchor-ref-with-hint',
67
+ summary:
68
+ 'a Tooltip attached through anchorRef to a caller button that is already described by a visible hint, so the trigger is described by both',
69
+ storyId: story('anchor-ref-with-hint'),
70
+ attachment: 'anchor-ref',
71
+ triggerText: 'Publish',
72
+ triggerRole: 'button',
73
+ content: 'Makes this page visible to everyone',
74
+ hint: 'Last published yesterday',
75
+ facts: DEFAULT_DELAY,
76
+ },
77
+ {
78
+ id: 'use-tooltip-hook',
79
+ summary:
80
+ "useTooltip on a caller button, which spreads the hook's ref and describedBy onto it and renders the tooltip",
81
+ storyId: story('use-tooltip-hook'),
82
+ attachment: 'hook',
83
+ triggerText: 'Archive',
84
+ triggerRole: 'button',
85
+ content: 'Moves this page out of the list',
86
+ facts: DEFAULT_DELAY,
87
+ },
88
+ ] as const satisfies ReadonlyArray<TooltipBindingState>;
89
+
90
+ export const TOOLTIP_EXCLUSIONS = [
91
+ {
92
+ id: 'focus-trigger',
93
+ owner:
94
+ "the 24 core hosts that pass focusTrigger 'always' — the disabledMessage tooltips on the field and choice controls (TextInput, TextArea, NumberInput, Switch, CheckboxInput, CheckboxList, RadioList, Selector, MultiSelector, SegmentedControl, Slider, Typeahead, Tokenizer, FileInput, and the date and time inputs), the Slider value bubble and ProgressBar marks — each through its own suite (for example TextInput.test.tsx 'shows the reason tooltip on keyboard focus'); and any caller that passes 'never'",
95
+ reason:
96
+ "'always' attaches the focus listeners to a wrapper that is not itself focusable, so focusin bubbling from the control inside it shows the hint; the described element and the focused element differ, which this contract's trigger-centred rows do not model, so each host proves its own keyboard path. 'never' detaches focus showing for a trigger inside a composite widget that moves focus itself, which then owns how a keyboard user reaches the hint; no shipped composition uses it. Every state here uses the default 'auto'.",
97
+ },
98
+ {
99
+ id: 'touch-trigger',
100
+ owner:
101
+ 'useTooltip.test.tsx and Tooltip.test.tsx (touchTrigger suites) through the shared useTouchTrigger hook',
102
+ reason:
103
+ 'On a touch pointer there is no hover, so a tap opens the tooltip or leaves it to the control the tap operates; the APG defines no touch behaviour, and the Chromium lane drives a mouse and a keyboard only.',
104
+ },
105
+ {
106
+ id: 'controlled-and-disabled',
107
+ owner:
108
+ 'Tooltip.test.tsx and useTooltip.test.tsx (isOpen, isDefaultOpen and isEnabled suites)',
109
+ reason:
110
+ 'A controlled tooltip answers Escape by reporting instead of hiding, and a disabled one never shows; both hand visibility to the caller, so the hover and focus outcomes this contract reads belong to the uncontrolled, enabled tooltip every state renders.',
111
+ },
112
+ {
113
+ id: 'interactive-hover-content',
114
+ owner: 'the HoverCard binding and the overlay-dismissal family',
115
+ reason:
116
+ 'Hover content a user can interact with is a non-modal dialog, not a tooltip, so HoverCard and other interactive popovers are reviewed separately; no state here places a focusable control inside a tooltip.',
117
+ },
118
+ {
119
+ id: 'host-compositions',
120
+ owner:
121
+ "the composing components' own contracts (Button for the IconButton label tooltip, the input status binding for useInputStatusIcon, which renders the on-field status tooltip) and their tests",
122
+ reason:
123
+ 'IconButton, useInputStatusIcon and Lab InfoTip render Tooltip or useTooltip for their own purposes; this binding proves the tooltip they render, and what each host adds around it is that host.',
124
+ },
125
+ {
126
+ id: 'placement-and-paint',
127
+ owner:
128
+ 'Tooltip.test.tsx (placement and alignment), the layer runtime anchor tests, and the repository visual gate',
129
+ reason:
130
+ 'Placement, alignment, the inverted surface and the hover underline on a text trigger are layout and paint; they change no role, description, focus or dismissal outcome, so every state uses the default placement.',
131
+ },
132
+ ] as const;
@@ -0,0 +1,126 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ /** @vitest-environment jsdom */
3
+
4
+ /**
5
+ * @file Tooltip.a11y.test.tsx
6
+ * @input TOOLTIP_PATTERN bound to Tooltip's and useTooltip's representative states
7
+ * @output jsdom-lane proof of the DOM expectations and an honest "unrun" report for the browser layers
8
+ * @position Binding test for Tooltip and useTooltip (the Chromium spec covers the rest)
9
+ */
10
+
11
+ import {cleanup, render, screen} from '@testing-library/react';
12
+ import {describe, expect, it} from 'vitest';
13
+ import {
14
+ TOOLTIP_PATTERN,
15
+ checkAccessibilitySpec,
16
+ createJsdomHarness,
17
+ expectAccessibilitySpec,
18
+ summarize,
19
+ type BindingResult,
20
+ } from '@astryxdesign/a11y-spec';
21
+ import {renderTooltipState} from './Tooltip.a11y.renders';
22
+ import {
23
+ TOOLTIP_BINDING_STATES,
24
+ TOOLTIP_EXCLUSIONS,
25
+ type TooltipBindingState,
26
+ } from './Tooltip.a11y.states';
27
+
28
+ function triggerFor(state: TooltipBindingState): HTMLElement {
29
+ return state.triggerRole == null
30
+ ? screen.getByText(state.triggerText, {exact: true})
31
+ : screen.getByRole(state.triggerRole, {name: state.triggerText});
32
+ }
33
+
34
+ function relatedFor(): Readonly<Record<string, Element>> {
35
+ return {
36
+ // The tooltip stays in the page while hidden; it is found with hidden
37
+ // elements included so the DOM rows can read it before it shows.
38
+ tooltip: screen.getByRole('tooltip', {hidden: true}),
39
+ before: screen.getByRole('button', {name: 'Before the trigger'}),
40
+ after: screen.getByRole('button', {name: 'After the trigger'}),
41
+ };
42
+ }
43
+
44
+ async function checkState(state: TooltipBindingState): Promise<BindingResult> {
45
+ return checkAccessibilitySpec({
46
+ spec: TOOLTIP_PATTERN,
47
+ binding: 'Tooltip',
48
+ state: state.id,
49
+ facts: state.facts,
50
+ mount: async () => {
51
+ render(renderTooltipState(state));
52
+ return createJsdomHarness({
53
+ subject: triggerFor(state),
54
+ related: relatedFor(),
55
+ });
56
+ },
57
+ unmount: cleanup,
58
+ });
59
+ }
60
+
61
+ describe('Tooltip — tooltip pattern, jsdom lane', () => {
62
+ it.each(
63
+ TOOLTIP_BINDING_STATES.map(
64
+ state => [state.id, state.summary, state] as const,
65
+ ),
66
+ )('%s — %s', async (_id, _summary, state) => {
67
+ await expectAccessibilitySpec({
68
+ spec: TOOLTIP_PATTERN,
69
+ binding: 'Tooltip',
70
+ state: state.id,
71
+ facts: state.facts,
72
+ render: () => {
73
+ render(renderTooltipState(state));
74
+ },
75
+ subject: () => triggerFor(state),
76
+ related: () => relatedFor(),
77
+ cleanup,
78
+ });
79
+ });
80
+
81
+ it('runs the DOM layer and reports the browser-owned outcomes as unrun', async () => {
82
+ const results: BindingResult[] = [];
83
+ for (const state of TOOLTIP_BINDING_STATES) {
84
+ results.push(await checkState(state));
85
+ }
86
+ const report = summarize(TOOLTIP_PATTERN, results);
87
+ expect(report.counts.pass).toBeGreaterThan(0);
88
+ expect(report.unrunLayers).toEqual(['accessibility-tree', 'real-browser']);
89
+ expect(report.counts.unexpectedPass).toBe(0);
90
+ });
91
+ });
92
+
93
+ describe('tooltip binding inventory', () => {
94
+ it('gives every representative state a distinct checked-in story', () => {
95
+ const stories = TOOLTIP_BINDING_STATES.map(state => state.storyId);
96
+ expect(new Set(stories).size).toBe(stories.length);
97
+ });
98
+
99
+ it('keeps focus-trigger opt-outs, touch, controlled visibility, interactive hover content, host compositions and paint explicit', () => {
100
+ expect(TOOLTIP_EXCLUSIONS.map(row => row.id)).toEqual([
101
+ 'focus-trigger',
102
+ 'touch-trigger',
103
+ 'controlled-and-disabled',
104
+ 'interactive-hover-content',
105
+ 'host-compositions',
106
+ 'placement-and-paint',
107
+ ]);
108
+ for (const exclusion of TOOLTIP_EXCLUSIONS) {
109
+ expect(exclusion.owner.length, exclusion.id).toBeGreaterThan(20);
110
+ expect(exclusion.reason.length, exclusion.id).toBeGreaterThan(80);
111
+ }
112
+ });
113
+
114
+ it('renders the trigger, one tooltip and both page buttons for every state', () => {
115
+ for (const state of TOOLTIP_BINDING_STATES) {
116
+ render(renderTooltipState(state));
117
+ expect(triggerFor(state), state.id).toBeTruthy();
118
+ expect(
119
+ screen.getAllByRole('tooltip', {hidden: true}),
120
+ state.id,
121
+ ).toHaveLength(1);
122
+ expect(Object.keys(relatedFor())).toEqual(['tooltip', 'before', 'after']);
123
+ cleanup();
124
+ }
125
+ });
126
+ });
@@ -0,0 +1,74 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file TooltipHoverBridge.a11y.chromium.spec.ts
5
+ * @input The `Core/Tooltip` Default story in a built Storybook and real mouse
6
+ * input.
7
+ * @output Real-engine proof that a pointer moving from the trigger onto the
8
+ * tooltip in one step keeps the tooltip open (WCAG 2.2 1.4.13 Content on
9
+ * Hover or Focus, hoverable), and that leaving the tooltip still hides it.
10
+ * @position Run with `pnpm test:a11y-contract`. The defect lives in the order
11
+ * the engine dispatches mouseout and mouseleave on one pointer step, which
12
+ * only a real engine produces.
13
+ */
14
+
15
+ import {expect, test, type Page} from '@playwright/test';
16
+ import {holdMotionStill} from '@astryxdesign/a11y-spec/chromium';
17
+ import {
18
+ DEFAULT_STORYBOOK_DIR,
19
+ serveStorybook,
20
+ type StaticServer,
21
+ } from '@astryxdesign/a11y-spec/storybook';
22
+
23
+ let storybook: StaticServer;
24
+
25
+ test.beforeAll(async () => {
26
+ storybook = await serveStorybook(
27
+ process.env.ASTRYX_STORYBOOK_DIR ?? DEFAULT_STORYBOOK_DIR,
28
+ );
29
+ });
30
+
31
+ test.afterAll(async () => {
32
+ await storybook?.close();
33
+ });
34
+
35
+ const STORY = 'core-tooltip--default';
36
+
37
+ async function openTooltip(page: Page) {
38
+ await page.setViewportSize({width: 900, height: 600});
39
+ await page.goto(`${storybook.origin}/iframe.html?id=${STORY}&viewMode=story`);
40
+ await holdMotionStill(page);
41
+ const trigger = page.getByRole('button', {name: 'Hover me'});
42
+ await trigger.hover();
43
+ const tooltip = page.getByRole('tooltip');
44
+ await expect(tooltip).toBeVisible();
45
+ const t = await trigger.boundingBox();
46
+ const s = await tooltip.boundingBox();
47
+ if (t == null || s == null) {
48
+ throw new Error('the trigger or the tooltip has no layout box');
49
+ }
50
+ return {tooltip, s};
51
+ }
52
+
53
+ test('a one-step move from the trigger onto the tooltip keeps it open', async ({
54
+ page,
55
+ }) => {
56
+ const {tooltip, s} = await openTooltip(page);
57
+
58
+ // One mousemove event straight onto the tooltip, as a quick hand makes.
59
+ await page.mouse.move(s.x + s.width / 2, s.y + s.height / 2);
60
+ // Well past the 100ms hover bridge.
61
+ await page.waitForTimeout(400);
62
+
63
+ await expect(tooltip).toBeVisible();
64
+ });
65
+
66
+ test('leaving the tooltip for the page still hides it', async ({page}) => {
67
+ const {tooltip, s} = await openTooltip(page);
68
+
69
+ await page.mouse.move(s.x + s.width / 2, s.y + s.height / 2);
70
+ await page.waitForTimeout(200);
71
+ await page.mouse.move(5, 5);
72
+
73
+ await expect(tooltip).toBeHidden();
74
+ });
@@ -214,6 +214,29 @@ describe('useTooltip — hide delay', () => {
214
214
  expect(onHide).toHaveBeenCalledTimes(1);
215
215
  });
216
216
 
217
+ it('stays open when the pointer crosses onto the tooltip in one step', () => {
218
+ const onHide = vi.fn();
219
+ showTooltip(onHide);
220
+ const surface = tooltipElement();
221
+
222
+ // A one-step crossing dispatches in browser order: the trigger's mouseout
223
+ // (React derives the surface's onMouseEnter from it), then the trigger's
224
+ // native mouseleave, both pointing at the surface. fireEvent.mouseLeave
225
+ // would add a mouseout after the leave, so the leave is dispatched raw.
226
+ fireEvent.mouseOut(trigger(), {relatedTarget: surface});
227
+ act(() => {
228
+ trigger().dispatchEvent(
229
+ new MouseEvent('mouseleave', {relatedTarget: surface}),
230
+ );
231
+ });
232
+ tick(500);
233
+ expect(onHide).not.toHaveBeenCalled();
234
+
235
+ fireEvent.mouseOut(surface, {relatedTarget: document.body});
236
+ tick(100);
237
+ expect(onHide).toHaveBeenCalledTimes(1);
238
+ });
239
+
217
240
  it('uses an explicit hideDelay instead of the hover bridge', () => {
218
241
  const onHide = vi.fn();
219
242
  showTooltip(onHide, {hideDelay: 500});
@@ -397,15 +397,28 @@ export function useTooltip(options: TooltipOptions = {}): TooltipReturn {
397
397
  scheduleShow();
398
398
  }, [isTouchPointerRef, scheduleShow]);
399
399
 
400
- const handleMouseLeave = useCallback(() => {
401
- // On touch the synthesized mouseleave arrives with the next tap elsewhere,
402
- // which the outside-tap dismissal already handles — and handling it here
403
- // too would close the tooltip behind the tap-open bookkeeping's back.
404
- if (isTouchPointerRef.current) {
405
- return;
406
- }
407
- scheduleHide();
408
- }, [isTouchPointerRef, scheduleHide]);
400
+ const handleMouseLeave = useCallback(
401
+ (event: Event) => {
402
+ // On touch the synthesized mouseleave arrives with the next tap elsewhere,
403
+ // which the outside-tap dismissal already handles — and handling it here
404
+ // too would close the tooltip behind the tap-open bookkeeping's back.
405
+ if (isTouchPointerRef.current) {
406
+ return;
407
+ }
408
+ // Leaving straight onto the tooltip: the surface's onMouseEnter already
409
+ // ran, because React dispatches it from the mouseout that precedes this
410
+ // mouseleave, so a hide scheduled now would never be cancelled. The
411
+ // surface's own mouse leave schedules the hide instead.
412
+ const next = (event as MouseEvent).relatedTarget as Node | null;
413
+ const surface =
414
+ next == null ? null : next.ownerDocument?.getElementById(layerId);
415
+ if (surface != null && surface.contains(next)) {
416
+ return;
417
+ }
418
+ scheduleHide();
419
+ },
420
+ [isTouchPointerRef, layerId, scheduleHide],
421
+ );
409
422
 
410
423
  const handleFocusIn = useCallback(
411
424
  (e: Event) => {