@astryxdesign/core 0.7.1 → 0.7.2-canary.198a7e3

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 (163) hide show
  1. package/dist/Button/Button.d.ts.map +1 -1
  2. package/dist/Button/Button.js +38 -14
  3. package/dist/Drawer/Drawer.d.ts +191 -0
  4. package/dist/Drawer/Drawer.d.ts.map +1 -0
  5. package/dist/Drawer/Drawer.js +382 -0
  6. package/dist/Drawer/DrawerHeader.d.ts +85 -0
  7. package/dist/Drawer/DrawerHeader.d.ts.map +1 -0
  8. package/dist/Drawer/DrawerHeader.js +134 -0
  9. package/dist/Drawer/index.d.ts +11 -0
  10. package/dist/Drawer/index.d.ts.map +1 -0
  11. package/dist/Drawer/index.js +11 -0
  12. package/dist/Drawer/useDrawerDialogPresence.d.ts +42 -0
  13. package/dist/Drawer/useDrawerDialogPresence.d.ts.map +1 -0
  14. package/dist/Drawer/useDrawerDialogPresence.js +236 -0
  15. package/dist/DropdownMenu/DropdownMenu.js +1 -1
  16. package/dist/DropdownMenu/DropdownMenuSubMenu.js +4 -4
  17. package/dist/HoverCard/useHoverCard.d.ts.map +1 -1
  18. package/dist/HoverCard/useHoverCard.js +10 -2
  19. package/dist/Layer/layerViewportInset.stylex.d.ts +6 -2
  20. package/dist/Layer/layerViewportInset.stylex.d.ts.map +1 -1
  21. package/dist/Layer/layerViewportInset.stylex.js +6 -2
  22. package/dist/Layer/useLayer.d.ts.map +1 -1
  23. package/dist/Layer/useLayer.js +13 -7
  24. package/dist/Layer/useLayerDismissal.d.ts +1 -1
  25. package/dist/Layer/useLayerDismissal.js +1 -1
  26. package/dist/Layout/container.stylex.d.ts +5 -5
  27. package/dist/Layout/container.stylex.js +4 -4
  28. package/dist/Markdown/plugins/frontmatter.d.ts.map +1 -1
  29. package/dist/Markdown/plugins/frontmatter.js +7 -3
  30. package/dist/MultiSelector/MultiSelector.d.ts.map +1 -1
  31. package/dist/MultiSelector/MultiSelector.js +22 -8
  32. package/dist/MultiSelector/OptionActions.a11y.chromium.spec.js +100 -2
  33. package/dist/MultiSelector/hooks.d.ts.map +1 -1
  34. package/dist/MultiSelector/hooks.js +3 -1
  35. package/dist/Pagination/Pagination.d.ts +8 -5
  36. package/dist/Pagination/Pagination.d.ts.map +1 -1
  37. package/dist/Pagination/Pagination.js +21 -8
  38. package/dist/Popover/Popover.js +2 -2
  39. package/dist/PowerSearch/PowerSearch.js +1 -1
  40. package/dist/Selector/hooks.d.ts.map +1 -1
  41. package/dist/Selector/hooks.js +6 -2
  42. package/dist/Switch/Switch.d.ts +1 -1
  43. package/dist/Switch/Switch.d.ts.map +1 -1
  44. package/dist/Switch/Switch.js +13 -1
  45. package/dist/TabList/TabMenu.d.ts +2 -2
  46. package/dist/TabList/TabMenu.d.ts.map +1 -1
  47. package/dist/TabList/TabMenu.js +6 -3
  48. package/dist/Text/useTruncation.d.ts +7 -5
  49. package/dist/Text/useTruncation.d.ts.map +1 -1
  50. package/dist/Text/useTruncation.js +16 -5
  51. package/dist/Tooltip/useTooltip.d.ts.map +1 -1
  52. package/dist/Tooltip/useTooltip.js +11 -0
  53. package/dist/Typeahead/BaseTypeahead.d.ts.map +1 -1
  54. package/dist/Typeahead/BaseTypeahead.js +26 -0
  55. package/dist/astryx.css +21 -10
  56. package/dist/hooks/useEntryAnimation.d.ts +2 -1
  57. package/dist/hooks/useEntryAnimation.d.ts.map +1 -1
  58. package/dist/hooks/useEntryAnimation.js +14 -12
  59. package/dist/hooks/useIsHydrating.d.ts +6 -0
  60. package/dist/hooks/useIsHydrating.d.ts.map +1 -0
  61. package/dist/hooks/useIsHydrating.js +30 -0
  62. package/dist/i18n/generated-locales/en.generated.d.ts.map +1 -1
  63. package/dist/i18n/generated-locales/en.generated.js +112 -1
  64. package/dist/i18n/generated-locales/pseudo.generated.d.ts.map +1 -1
  65. package/dist/i18n/generated-locales/pseudo.generated.js +112 -1
  66. package/dist/index.d.ts +1 -0
  67. package/dist/index.d.ts.map +1 -1
  68. package/dist/index.js +1 -0
  69. package/dist/theme/derivedVarRegistry.d.ts.map +1 -1
  70. package/dist/theme/derivedVarRegistry.js +0 -3
  71. package/dist/utils/focusOutline.stylex.d.ts +4 -0
  72. package/dist/utils/focusOutline.stylex.d.ts.map +1 -1
  73. package/dist/utils/focusOutline.stylex.js +4 -0
  74. package/dist/utils/sharedMutationObserver.d.ts +21 -0
  75. package/dist/utils/sharedMutationObserver.d.ts.map +1 -0
  76. package/dist/utils/sharedMutationObserver.js +69 -0
  77. package/locales/en.json +444 -0
  78. package/locales/pseudo.json +333 -0
  79. package/package.json +9 -4
  80. package/src/Button/Button.doc.mjs +2 -2
  81. package/src/Button/Button.test.tsx +155 -9
  82. package/src/Button/Button.tsx +39 -16
  83. package/src/Button/__tests__/Button.a11y.known-failures.ts +1 -62
  84. package/src/Button/__tests__/Button.a11y.states.ts +0 -10
  85. package/src/Drawer/Drawer.doc.mjs +472 -0
  86. package/src/Drawer/Drawer.spec.md +357 -0
  87. package/src/Drawer/Drawer.test.tsx +1300 -0
  88. package/src/Drawer/Drawer.tsx +613 -0
  89. package/src/Drawer/DrawerDirection.test.tsx +127 -0
  90. package/src/Drawer/DrawerHeader.doc.mjs +293 -0
  91. package/src/Drawer/DrawerHeader.test.tsx +102 -0
  92. package/src/Drawer/DrawerHeader.tsx +235 -0
  93. package/src/Drawer/__tests__/DrawerAudit.a11y.chromium.spec.ts +401 -0
  94. package/src/Drawer/__tests__/DrawerHeaderAudit.a11y.chromium.spec.ts +297 -0
  95. package/src/Drawer/index.ts +13 -0
  96. package/src/Drawer/useDrawerDialogPresence.ts +284 -0
  97. package/src/DropdownMenu/DropdownMenu.test.tsx +0 -12
  98. package/src/DropdownMenu/DropdownMenu.tsx +2 -2
  99. package/src/DropdownMenu/DropdownMenuSubMenu.tsx +2 -2
  100. package/src/DropdownMenu/__tests__/Menu.a11y.chromium.spec.ts +145 -0
  101. package/src/DropdownMenu/__tests__/Menu.a11y.known-failures.ts +26 -0
  102. package/src/DropdownMenu/__tests__/Menu.a11y.renders.tsx +65 -0
  103. package/src/DropdownMenu/__tests__/Menu.a11y.states.ts +138 -0
  104. package/src/DropdownMenu/__tests__/Menu.a11y.test.tsx +136 -0
  105. package/src/HoverCard/HoverCard.test.tsx +58 -0
  106. package/src/HoverCard/useHoverCard.tsx +10 -2
  107. package/src/IconButton/IconButton.doc.mjs +2 -2
  108. package/src/IconButton/IconButton.test.tsx +3 -1
  109. package/src/Layer/layerViewportInset.source-build.test.mjs +90 -0
  110. package/src/Layer/layerViewportInset.stylex.ts +6 -2
  111. package/src/Layer/layerViewportInset.test.ts +1 -0
  112. package/src/Layer/useLayer.tsx +24 -13
  113. package/src/Layer/useLayerDismissal.ts +1 -1
  114. package/src/Layout/container.stylex.ts +6 -6
  115. package/src/List/ListItem.doc.mjs +8 -5
  116. package/src/Markdown/plugins/frontmatter.test.tsx +25 -0
  117. package/src/Markdown/plugins/frontmatter.ts +7 -3
  118. package/src/MultiSelector/MultiSelector.test.tsx +159 -0
  119. package/src/MultiSelector/MultiSelector.tsx +40 -7
  120. package/src/MultiSelector/OptionActions.a11y.chromium.spec.ts +112 -2
  121. package/src/MultiSelector/hooks.ts +3 -1
  122. package/src/MultiSelector/useMultiCombobox.doc.mjs +267 -0
  123. package/src/Pagination/Pagination.doc.mjs +7 -7
  124. package/src/Pagination/Pagination.spec.md +9 -9
  125. package/src/Pagination/Pagination.test.tsx +242 -0
  126. package/src/Pagination/Pagination.tsx +27 -11
  127. package/src/Popover/Popover.test.tsx +2 -2
  128. package/src/Popover/Popover.tsx +4 -4
  129. package/src/PowerSearch/PowerSearch.test.tsx +85 -0
  130. package/src/PowerSearch/PowerSearch.tsx +2 -2
  131. package/src/Selector/hooks.ts +6 -2
  132. package/src/Selector/useCombobox.doc.mjs +237 -0
  133. package/src/Switch/Switch.test.tsx +49 -0
  134. package/src/Switch/Switch.tsx +11 -0
  135. package/src/TabList/TabList.test.tsx +67 -0
  136. package/src/TabList/TabMenu.doc.mjs +4 -3
  137. package/src/TabList/TabMenu.tsx +7 -4
  138. package/src/Text/useTruncation.test.tsx +69 -0
  139. package/src/Text/useTruncation.ts +16 -5
  140. package/src/Tokenizer/Tokenizer.test.tsx +54 -1
  141. package/src/Tooltip/Tooltip.test.tsx +31 -0
  142. package/src/Tooltip/useTooltip.test.tsx +13 -0
  143. package/src/Tooltip/useTooltip.tsx +11 -0
  144. package/src/TreeList/TreeList.spec.md +29 -17
  145. package/src/Typeahead/BaseTypeahead.tsx +26 -0
  146. package/src/Typeahead/Typeahead.test.tsx +260 -2
  147. package/src/hooks/useEntryAnimation.doc.mjs +4 -4
  148. package/src/hooks/useEntryAnimation.ssr.test.tsx +143 -0
  149. package/src/hooks/useEntryAnimation.ts +15 -16
  150. package/src/hooks/useIsHydrating.test.tsx +70 -0
  151. package/src/hooks/useIsHydrating.ts +31 -0
  152. package/src/i18n/InternationalizationProvider.doc.mjs +8 -0
  153. package/src/i18n/InternationalizationProvider.spec.md +252 -0
  154. package/src/i18n/__tests__/InternationalizationProvider.test.tsx +128 -0
  155. package/src/i18n/generated-locales/en.generated.ts +121 -0
  156. package/src/i18n/generated-locales/pseudo.generated.ts +121 -0
  157. package/src/i18n/useTranslator.test.tsx +37 -0
  158. package/src/index.ts +1 -0
  159. package/src/theme/derivedVarRegistry.test.ts +0 -3
  160. package/src/theme/derivedVarRegistry.ts +0 -3
  161. package/src/utils/focusOutline.stylex.ts +4 -0
  162. package/src/utils/sharedMutationObserver.test.ts +53 -0
  163. package/src/utils/sharedMutationObserver.ts +78 -0
@@ -183,6 +183,37 @@ describe('Tooltip', () => {
183
183
  });
184
184
  });
185
185
 
186
+ describe('icon-only trigger', () => {
187
+ // A rendered icon is an SVGElement, and ShowPopoverOptions.source is
188
+ // declared as an HTMLElement. Handing the icon to showPopover throws
189
+ // during dictionary conversion, before the popover opens, so the hint
190
+ // never appeared. (#7226)
191
+ it('opens an icon trigger without passing an SVGElement as the source', async () => {
192
+ const showSpy = vi.mocked(HTMLElement.prototype.showPopover);
193
+ showSpy.mockClear();
194
+
195
+ render(
196
+ <Tooltip content="Shared memory" isDefaultOpen>
197
+ <svg data-testid="icon" aria-hidden="true" />
198
+ </Tooltip>,
199
+ );
200
+
201
+ await waitFor(() => {
202
+ expect(showSpy).toHaveBeenCalled();
203
+ });
204
+
205
+ const [options] = showSpy.mock.calls[0];
206
+ // Compared as a boolean on purpose: a plain `toBeUndefined` failure makes
207
+ // the diff printer walk the SVGElement, which it cannot inspect.
208
+ expect(options?.source === undefined).toBe(true);
209
+
210
+ // The icon is still the trigger the ARIA tooltip pattern is wired to.
211
+ expect(screen.getByTestId('icon').getAttribute('aria-describedby')).toBe(
212
+ screen.getByRole('tooltip', {hidden: true}).id,
213
+ );
214
+ });
215
+ });
216
+
186
217
  describe('WCAG 1.4.13 — content on hover or focus', () => {
187
218
  it('dismisses on Escape while visible (dismissible)', async () => {
188
219
  const onOpenChange = vi.fn();
@@ -147,6 +147,19 @@ describe('useTooltip — show delay', () => {
147
147
 
148
148
  expect(onShow).not.toHaveBeenCalled();
149
149
  });
150
+
151
+ it('drops a pending show when isEnabled turns false before the delay elapses', () => {
152
+ const onShow = vi.fn();
153
+ const {rerender} = render(<Harness onShow={onShow} />);
154
+
155
+ fireEvent.mouseEnter(trigger());
156
+ tick(100);
157
+ rerender(<Harness isEnabled={false} onShow={onShow} />);
158
+ tick(1000);
159
+
160
+ expect(onShow).not.toHaveBeenCalled();
161
+ expect(tooltipElement().matches(':popover-open')).toBe(false);
162
+ });
150
163
  });
151
164
 
152
165
  describe('useTooltip — touch suppression', () => {
@@ -352,6 +352,17 @@ export function useTooltip(options: TooltipOptions = {}): TooltipReturn {
352
352
  }, delay);
353
353
  }, [isEnabled, isOpen, clearTimeouts, showLayer, delay]);
354
354
 
355
+ // A show scheduled while the triggers were enabled must not outlive them:
356
+ // disabling also detaches the leave listener that would have cancelled it,
357
+ // so the timer would open a tooltip that nothing ever closes. Only the
358
+ // pending show is dropped; a pending hide still runs.
359
+ useEffect(() => {
360
+ if (!isEnabled && showTimeoutRef.current) {
361
+ clearTimeout(showTimeoutRef.current);
362
+ showTimeoutRef.current = null;
363
+ }
364
+ }, [isEnabled]);
365
+
355
366
  // Schedule hide with delay (suppressed when isOpen is true).
356
367
  // A small hover bridge (when hideDelay is 0) lets the pointer travel from the
357
368
  // trigger onto the tooltip surface without the tooltip vanishing — required
@@ -96,14 +96,15 @@ Supporting one does not justify omitting another from the durable contract.
96
96
 
97
97
  ## Behavioral and layout contract
98
98
 
99
- | ID | Invariant | Basis | Contract state |
100
- | --- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- | --------------------------------------------------- |
101
- | FR1 | The current render contains one Tree list, one Item and Item label per rendered node, optional Header, Chevron, Item description, Start content, End content, and Guide parts, and delegated Chevron glyphs. | Current source, docs, and tests | Current behavior |
102
- | FR2 | Tree list, Item, Chevron, Item label, and Guide carry the five current `tree-list*` targets documented below. | Current source and target docs | Current behavior |
103
- | FR3 | Chevron glyph delegates to Icon's `icon` target. Header, Start content, and End content are consumer-owned and have no TreeList target. | Current source and component docs | Current ownership |
104
- | FR4 | Item description is a stable library-rendered part below Item label and currently has no public target. It does not inherit through `tree-list-item-label`; both spans are siblings inside the row content. | Current source and target docs | Current reachability gap; no new target is accepted |
105
- | FR5 | `TreeListItemData` MUST admit `className`, `style`, and `xstyle` as one per-item styling seam. Every supplied value MUST compose on the same Item row box; an implementation MUST NOT treat current support for only one mechanism as authority to exclude the other two. | Owner decision; `architecture:public-component-api` INV5–INV6; `spec:AST-002/DEC-1` | Settled intent; implementation may be staged |
106
- | FR6 | The Item row box is the logical element that paints the row, owns its hover state, and contains Start content, Item label and description, and End content. The styling seam MUST NOT move to the semantic `<li>` or another element without a compatibility decision. | Owner decision and the caller-owned per-row interaction boundary | Settled intent |
99
+ | ID | Invariant | Basis | Contract state |
100
+ | --- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- | --------------------------------------------------- |
101
+ | FR1 | The current render contains one Tree list, one Item and Item label per rendered node, optional Header, Chevron, Item description, Start content, End content, and Guide parts, and delegated Chevron glyphs. | Current source, docs, and tests | Current behavior |
102
+ | FR2 | Tree list, Item, Chevron, Item label, and Guide carry the five current `tree-list*` targets documented below. | Current source and target docs | Current behavior |
103
+ | FR3 | Chevron glyph delegates to Icon's `icon` target. Header, Start content, and End content are consumer-owned and have no TreeList target. | Current source and component docs | Current ownership |
104
+ | FR4 | Item description is a stable library-rendered part below Item label and currently has no public target. It does not inherit through `tree-list-item-label`; both spans are siblings inside the row content. | Current source and target docs | Current reachability gap; no new target is accepted |
105
+ | FR5 | `TreeListItemData` MUST admit `className`, `style`, and `xstyle` as one per-item styling seam. Every supplied value MUST compose on the same Item row box; an implementation MUST NOT treat current support for only one mechanism as authority to exclude the other two. | Owner decision; `architecture:public-component-api` INV5–INV6; `spec:AST-002/DEC-1` | Settled intent; implementation may be staged |
106
+ | FR6 | The Item row box is the logical element that paints the row, owns its hover state, and contains Start content, Item label and description, and End content. The styling seam MUST NOT move to the semantic `<li>` or another element without a compatibility decision. | Owner decision and the caller-owned per-row interaction boundary | Settled intent |
107
+ | FR7 | A click on an Item row outside its Item label performs the row's action: an Item with `onClick` runs it; otherwise an Item with children toggles; otherwise an Item whose only action is its link follows that link as Enter does, with modified and middle clicks following the shared enlarged-surface rule in `family:navigation-destinations`. The Chevron and controls in Start content and End content keep their own activation, and a disabled Item does nothing. | Owner decision; `family:navigation-destinations` | Settled intent; implementation may be staged |
107
108
 
108
109
  ### Allowed variation
109
110
 
@@ -183,6 +184,16 @@ structure. Its current lack of a target is a reachability gap, not a decision
183
184
  that it must remain unthemeable. Header, Start content, and End content remain
184
185
  caller-owned even though TreeList positions their slot wrappers.
185
186
 
187
+ ### Design decisions
188
+
189
+ <!-- design-decisions:v1 -->
190
+
191
+ | ID | Decision | Intent or reason | Applies to | Allowed variation |
192
+ | --- | ---------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
193
+ | DD1 | Every Item spans the full width of the tree list at any depth; its nesting indent sits inside the row, ahead of its content. | Hover, pressed, and selected fills line up across depths, so the tree reads as one list of equal rows while labels keep their per-level alignment. | Item at every depth, at rest and through hover, pressed, selected, disabled, and focus | Themes set the indent step with `--tree-list-indent` and may restyle the row's fill, radius, and padding; row padding adds to the indent instead of replacing it. |
194
+ | DD2 | A nested Item's indent area is part of the row's painted target: it shows the row's hover and press feedback. | The whole painted row reads as one target, matching where a click acts (FR7), so no part of a row lights up apart from the rest. | Nested Items that act on click | Themes may restyle the feedback through the `tree-list-item` target. |
195
+ | DD3 | Guides paint above row fills, and an Item whose focus ring is showing paints above the guides. | Hierarchy lines stay continuous through hover and selection, and the focus indicator is never cut; on a focused row that is also filled, the ring takes precedence and the fill covers the guides at that row. | Guide and Item in `lineGuides` trees | Themes may recolor or hide guides through the `tree-list-guide` target. |
196
+
186
197
  ### Theming anatomy
187
198
 
188
199
  <!-- anatomy-theming:v1 -->
@@ -242,15 +253,16 @@ authorize or prohibit a future target.
242
253
 
243
254
  ## Verification map
244
255
 
245
- | Contract | Verification | Representative states | Mutation or failure expectation | Audit section |
246
- | ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ |
247
- | FR1 | `TreeList.test.tsx` rendering, hierarchy, slot, and accessibility suites plus source inspection | Flat, nested, described, headed, and slotted items | Removing asserted Tree list, Header, Item, Chevron, Item label, Item description, Start content, End content, or Guide behavior fails existing role, content, hierarchy, or state assertions; Chevron glyph presence remains source-inspected only. | `audit:TreeList/anatomy` |
248
- | FR2 | `TreeList.test.tsx` and `themingTargets.test.ts` | Five local targets and their documented states | Removing or moving any current local target fails focused class assertions or the global inventory. | `audit:TreeList/theming` |
249
- | FR3 | Source inspection plus Icon public target metadata | Expandable rows and caller-provided slots | Existing focused tests do not assert the composed Icon instance; changing glyph or slot ownership requires this map and the relevant owner metadata to change. | `audit:TreeList/theming` |
250
- | FR4 | `TreeList.test.tsx` description rendering test and source inspection | Item with description | Removing description fails content coverage; adding a target requires an explicit map update. | `audit:TreeList/anatomy` |
251
- | AR1 | Tree View accessibility contract (`internal/a11y-spec`, pending) bound to TreeList, in jsdom and Chromium; `TreeList.test.tsx` row-naming cases ("names a parent row by its label alone, not the chevron toggle", "names a plain row by its label and describes it with its description", "names and describes link and action rows themselves, not only their inner control", "keeps start and end content, including controls, out of the row name", "typeahead matches the label, not the description or start content") and `TreeListRowNames.a11y.chromium.spec.ts` for the browser-computed names; `TreeList.test.tsx` structural ARIA cases ("sets aria-level, aria-posinset, and aria-setsize at the top level", "sets aria-level/posinset/setsize correctly at deeper levels", "sets aria-level across three depths"); `TreeList.test.tsx` and `useTreeFocus.test.tsx` keyboard suites | Flat and nested trees; expanded/collapsed; selected/unselected; LTR and RTL; typeahead | A row loses its role, label name, state or position, two rows hold a Tab stop, an arrow key stops moving or stops mirroring under RTL, Home/End or typeahead stop working, or the tree claims multi-select | `audit:TreeList/accessibility` |
252
- | FR5, FR6, ORD1 | Focused `TreeList.test.tsx` row-identity and styling-composition coverage, required with implementation | One input at a time; all three together; sibling rows | Dropping any mechanism, applying mechanisms to different elements, targeting the `<li>`, changing the merge order, or styling a sibling row fails. | `audit:TreeList/api` |
253
- | Theming anatomy map | `scripts/check-knowledge.mjs` | Canonical anatomy and five current local targets | Missing, extra, duplicated, prefixed, or stale mappings fail repository validation. | `audit:TreeList/theming` |
256
+ | Contract | Verification | Representative states | Mutation or failure expectation | Audit section |
257
+ | ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ |
258
+ | FR1 | `TreeList.test.tsx` rendering, hierarchy, slot, and accessibility suites plus source inspection | Flat, nested, described, headed, and slotted items | Removing asserted Tree list, Header, Item, Chevron, Item label, Item description, Start content, End content, or Guide behavior fails existing role, content, hierarchy, or state assertions; Chevron glyph presence remains source-inspected only. | `audit:TreeList/anatomy` |
259
+ | FR2 | `TreeList.test.tsx` and `themingTargets.test.ts` | Five local targets and their documented states | Removing or moving any current local target fails focused class assertions or the global inventory. | `audit:TreeList/theming` |
260
+ | FR3 | Source inspection plus Icon public target metadata | Expandable rows and caller-provided slots | Existing focused tests do not assert the composed Icon instance; changing glyph or slot ownership requires this map and the relevant owner metadata to change. | `audit:TreeList/theming` |
261
+ | FR4 | `TreeList.test.tsx` description rendering test and source inspection | Item with description | Removing description fails content coverage; adding a target requires an explicit map update. | `audit:TreeList/anatomy` |
262
+ | AR1 | Tree View accessibility contract (`internal/a11y-spec`, pending) bound to TreeList, in jsdom and Chromium; `TreeList.test.tsx` row-naming cases ("names a parent row by its label alone, not the chevron toggle", "names a plain row by its label and describes it with its description", "names and describes link and action rows themselves, not only their inner control", "keeps start and end content, including controls, out of the row name", "typeahead matches the label, not the description or start content") and `TreeListRowNames.a11y.chromium.spec.ts` for the browser-computed names; `TreeList.test.tsx` structural ARIA cases ("sets aria-level, aria-posinset, and aria-setsize at the top level", "sets aria-level/posinset/setsize correctly at deeper levels", "sets aria-level across three depths"); `TreeList.test.tsx` and `useTreeFocus.test.tsx` keyboard suites | Flat and nested trees; expanded/collapsed; selected/unselected; LTR and RTL; typeahead | A row loses its role, label name, state or position, two rows hold a Tab stop, an arrow key stops moving or stops mirroring under RTL, Home/End or typeahead stop working, or the tree claims multi-select | `audit:TreeList/accessibility` |
263
+ | FR5, FR6, ORD1 | Focused `TreeList.test.tsx` row-identity and styling-composition coverage, required with implementation | One input at a time; all three together; sibling rows | Dropping any mechanism, applying mechanisms to different elements, targeting the `<li>`, changing the merge order, or styling a sibling row fails. | `audit:TreeList/api` |
264
+ | FR7 | Focused `TreeList.test.tsx` row-click coverage, required with implementation | Action, parent, link, and disabled rows; clicks in the indent and padding, on the Chevron, and on Start and End content controls; plain, modified, and middle clicks | A click outside the label does nothing or runs the wrong action, a link-row click reaches ancestors twice, the Chevron or a Start or End content control activates the row, or a disabled row acts. | `audit:TreeList/behavior` |
265
+ | Theming anatomy map | `scripts/check-knowledge.mjs` | Canonical anatomy and five current local targets | Missing, extra, duplicated, prefixed, or stale mappings fail repository validation. | `audit:TreeList/theming` |
254
266
 
255
267
  Focused target-placement assertions cover all five local targets. Runtime support
256
268
  and mutation-sensitive coverage for the item styling seam may land separately,
@@ -624,6 +624,32 @@ export const BaseTypeahead = function BaseTypeahead<T extends SearchableItem>({
624
624
  sourceGenRef.current = ++searchGenRef.current;
625
625
  }
626
626
 
627
+ // The previous source is remembered in state, not a ref, so a render React
628
+ // discards cannot consume the comparison without its state updates.
629
+ const [sourceOfState, setSourceOfState] = useState(searchSource);
630
+ if (sourceOfState !== searchSource) {
631
+ setSourceOfState(searchSource);
632
+ if (isLoading) {
633
+ setIsLoading(false);
634
+ setHasSearched(false);
635
+ }
636
+ loadingRef.current = false;
637
+ }
638
+
639
+ // When the search source is replaced, any in-flight load from the previous
640
+ // source is abandoned (generation bumped above). Notify the wrapper's busy lane
641
+ // in an effect so external store listeners run safely after commit.
642
+ const isInitialMountRef = useRef(true);
643
+ useEffect(() => {
644
+ if (isInitialMountRef.current) {
645
+ isInitialMountRef.current = false;
646
+ return;
647
+ }
648
+ if (!loadingRef.current) {
649
+ onLoadingChangeRef.current?.(false);
650
+ }
651
+ }, [searchSource]);
652
+
627
653
  // Layer for dropdown
628
654
  const handleLayerShow = useCallback(() => {
629
655
  onOpenChange?.(true);
@@ -17,10 +17,20 @@ import {
17
17
  beforeAll,
18
18
  afterAll,
19
19
  beforeEach,
20
+ afterEach,
20
21
  } from 'vitest';
21
22
  import {render, screen, fireEvent, waitFor, act} from '@testing-library/react';
22
23
  import userEvent from '@testing-library/user-event';
23
- import {createRef, Profiler, type ProfilerOnRenderCallback} from 'react';
24
+ import {__resetLiveRegionsForTest} from '../hooks/useAnnounce';
25
+ import {
26
+ createRef,
27
+ Profiler,
28
+ startTransition,
29
+ StrictMode,
30
+ Suspense,
31
+ useState,
32
+ type ProfilerOnRenderCallback,
33
+ } from 'react';
24
34
  import {Typeahead} from './Typeahead';
25
35
  import {readFile} from 'node:fs/promises';
26
36
  import {resolve} from 'node:path';
@@ -70,6 +80,10 @@ afterAll(() => {
70
80
  (HTMLElement.prototype as any).matches = originalMatches;
71
81
  });
72
82
 
83
+ afterEach(() => {
84
+ __resetLiveRegionsForTest();
85
+ });
86
+
73
87
  // Test data
74
88
  const fruits: SearchableItem[] = [
75
89
  {id: '1', label: 'Apple'},
@@ -964,6 +978,193 @@ describe('BaseTypeahead hasEntriesOnFocus', () => {
964
978
  ).not.toBeInTheDocument();
965
979
  });
966
980
 
981
+ it('clears the loading state when the search source is replaced during an in-flight load', async () => {
982
+ let settle: (items: SearchableItem[]) => void = () => {};
983
+ const bootstrap = vi.fn(
984
+ async () =>
985
+ new Promise<SearchableItem[]>(resolve => {
986
+ settle = resolve;
987
+ }),
988
+ );
989
+ const initialSource: SearchSource = {search: () => [], bootstrap};
990
+ const replacementSource: SearchSource = {
991
+ search: () => [],
992
+ bootstrap: () => [],
993
+ };
994
+
995
+ const {rerender} = render(
996
+ <BaseTypeahead
997
+ searchSource={initialSource}
998
+ value={null}
999
+ onChange={() => {}}
1000
+ hasEntriesOnFocus
1001
+ />,
1002
+ );
1003
+ const input = screen.getByRole('combobox');
1004
+
1005
+ fireEvent.focus(input);
1006
+ await waitFor(() => {
1007
+ expect(screen.getByRole('status', {name: 'Loading'})).toBeInTheDocument();
1008
+ });
1009
+
1010
+ rerender(
1011
+ <BaseTypeahead
1012
+ searchSource={replacementSource}
1013
+ value={null}
1014
+ onChange={() => {}}
1015
+ hasEntriesOnFocus
1016
+ />,
1017
+ );
1018
+
1019
+ await waitFor(() => {
1020
+ expect(
1021
+ screen.queryByRole('status', {name: 'Loading'}),
1022
+ ).not.toBeInTheDocument();
1023
+ });
1024
+
1025
+ await act(async () => {
1026
+ settle([]);
1027
+ await Promise.resolve();
1028
+ });
1029
+ expect(
1030
+ screen.queryByRole('status', {name: 'Loading'}),
1031
+ ).not.toBeInTheDocument();
1032
+ });
1033
+
1034
+ it('keeps the loading state under StrictMode for a pending autofocus bootstrap', async () => {
1035
+ let settle: (items: SearchableItem[]) => void = () => {};
1036
+ const bootstrap = vi.fn(
1037
+ async () =>
1038
+ new Promise<SearchableItem[]>(resolve => {
1039
+ settle = resolve;
1040
+ }),
1041
+ );
1042
+ render(
1043
+ <StrictMode>
1044
+ <Typeahead
1045
+ label="Test"
1046
+ searchSource={{search: () => [], bootstrap}}
1047
+ value={null}
1048
+ onChange={() => {}}
1049
+ hasAutoFocus
1050
+ hasEntriesOnFocus
1051
+ />
1052
+ </StrictMode>,
1053
+ );
1054
+
1055
+ expect(screen.getByRole('status', {name: 'Loading'})).toBeInTheDocument();
1056
+
1057
+ await act(async () => {
1058
+ settle([]);
1059
+ await Promise.resolve();
1060
+ });
1061
+ expect(
1062
+ screen.queryByRole('status', {name: 'Loading'}),
1063
+ ).not.toBeInTheDocument();
1064
+ });
1065
+
1066
+ let settlePendingTransitionA: (items: SearchableItem[]) => void = () => {};
1067
+ const stableTransitionSourceA: SearchSource = {
1068
+ search: vi.fn(
1069
+ async () =>
1070
+ new Promise<SearchableItem[]>(resolve => {
1071
+ settlePendingTransitionA = resolve;
1072
+ }),
1073
+ ),
1074
+ bootstrap: () => [],
1075
+ };
1076
+ const stableTransitionSourceB: SearchSource = {
1077
+ search: vi.fn(async () => []),
1078
+ bootstrap: () => [],
1079
+ };
1080
+
1081
+ it('clears loading and aria-busy when source is replaced in a transition that suspends and retries', async () => {
1082
+ let isSuspended = false;
1083
+ let resolveSuspension: () => void = () => {};
1084
+ let pendingSuspension: Promise<void> | null = null;
1085
+
1086
+ function SuspendingSibling({shouldSuspend}: {shouldSuspend: boolean}) {
1087
+ if (shouldSuspend && isSuspended && pendingSuspension) {
1088
+ // eslint-disable-next-line @typescript-eslint/only-throw-error
1089
+ throw pendingSuspension;
1090
+ }
1091
+ return null;
1092
+ }
1093
+
1094
+ let updateState!: (source: SearchSource, shouldSuspend: boolean) => void;
1095
+
1096
+ function TransitionContainer() {
1097
+ const [source, setSource] = useState<SearchSource>(
1098
+ stableTransitionSourceA,
1099
+ );
1100
+ const [shouldSuspend, setShouldSuspend] = useState(false);
1101
+ updateState = (newSource, suspend) => {
1102
+ setSource(newSource);
1103
+ setShouldSuspend(suspend);
1104
+ };
1105
+
1106
+ return (
1107
+ <Suspense fallback={<div>Suspended...</div>}>
1108
+ <Typeahead
1109
+ label="Test"
1110
+ searchSource={source}
1111
+ value={null}
1112
+ onChange={() => {}}
1113
+ debounceMs={0}
1114
+ />
1115
+ <SuspendingSibling shouldSuspend={shouldSuspend} />
1116
+ </Suspense>
1117
+ );
1118
+ }
1119
+
1120
+ render(<TransitionContainer />);
1121
+ const input = screen.getByRole('combobox');
1122
+
1123
+ // Trigger a load so aria-busy="true" is set on the combobox
1124
+ fireEvent.change(input, {target: {value: 'query'}});
1125
+ await waitFor(() => {
1126
+ expect(input).toHaveAttribute('aria-busy', 'true');
1127
+ });
1128
+ expect(screen.getByRole('status', {name: 'Loading'})).toBeInTheDocument();
1129
+
1130
+ // Create the pending promise for suspension
1131
+ isSuspended = true;
1132
+ pendingSuspension = new Promise<void>(resolve => {
1133
+ resolveSuspension = () => {
1134
+ isSuspended = false;
1135
+ resolve();
1136
+ };
1137
+ });
1138
+
1139
+ // Inside startTransition, switch from source A to source B while sibling suspends
1140
+ act(() => {
1141
+ startTransition(() => {
1142
+ updateState(stableTransitionSourceB, true);
1143
+ });
1144
+ });
1145
+
1146
+ // The render suspended, so the previous committed state remains
1147
+ expect(input).toHaveAttribute('aria-busy', 'true');
1148
+
1149
+ // Resolve the pending promise and let the transition commit
1150
+ await act(async () => {
1151
+ resolveSuspension();
1152
+ await pendingSuspension;
1153
+ });
1154
+
1155
+ // Settle the abandoned load
1156
+ await act(async () => {
1157
+ settlePendingTransitionA([]);
1158
+ await Promise.resolve();
1159
+ });
1160
+
1161
+ // The combobox must not keep aria-busy and the spinner must be gone
1162
+ expect(input).not.toHaveAttribute('aria-busy');
1163
+ expect(
1164
+ screen.queryByRole('status', {name: 'Loading'}),
1165
+ ).not.toBeInTheDocument();
1166
+ });
1167
+
967
1168
  it('shows bootstrap results on mouse click', async () => {
968
1169
  render(
969
1170
  <BaseTypeahead
@@ -1323,6 +1524,63 @@ describe('BaseTypeahead hasSearched reset', () => {
1323
1524
  // "No results found" should disappear since hasSearched is reset
1324
1525
  expect(screen.queryByText('No results found')).not.toBeInTheDocument();
1325
1526
  });
1527
+
1528
+ it('resets hasSearched and does not announce "No results found" when search source is replaced during a pending search', async () => {
1529
+ let settle: (items: SearchableItem[]) => void = () => {};
1530
+ const initialSource: SearchSource = {
1531
+ search: vi.fn(
1532
+ async () =>
1533
+ new Promise<SearchableItem[]>(resolve => {
1534
+ settle = resolve;
1535
+ }),
1536
+ ),
1537
+ bootstrap: () => [],
1538
+ };
1539
+ const replacementSource: SearchSource = {
1540
+ search: vi.fn(async () => []),
1541
+ bootstrap: () => [],
1542
+ };
1543
+
1544
+ const {rerender} = render(
1545
+ <BaseTypeahead
1546
+ searchSource={initialSource}
1547
+ value={null}
1548
+ onChange={() => {}}
1549
+ debounceMs={0}
1550
+ />,
1551
+ );
1552
+ const input = screen.getByRole('combobox');
1553
+
1554
+ // Type a query that starts an asynchronous search
1555
+ fireEvent.change(input, {target: {value: 'abc'}});
1556
+ expect(initialSource.search).toHaveBeenCalledWith('abc');
1557
+
1558
+ // Replace the search source while the search is still pending
1559
+ rerender(
1560
+ <BaseTypeahead
1561
+ searchSource={replacementSource}
1562
+ value={null}
1563
+ onChange={() => {}}
1564
+ debounceMs={0}
1565
+ />,
1566
+ );
1567
+
1568
+ // Settle the abandoned search
1569
+ await act(async () => {
1570
+ settle([]);
1571
+ await Promise.resolve();
1572
+ });
1573
+
1574
+ await act(
1575
+ async () =>
1576
+ new Promise<void>(resolve => requestAnimationFrame(() => resolve())),
1577
+ );
1578
+ expect(
1579
+ document.querySelector('[data-astryx-live-region="polite"]')
1580
+ ?.textContent ?? '',
1581
+ ).not.toContain('No results found');
1582
+ expect(screen.queryByText('No results found')).not.toBeInTheDocument();
1583
+ });
1326
1584
  });
1327
1585
 
1328
1586
  describe('BaseTypeahead popover after selection', () => {
@@ -2313,7 +2571,7 @@ describe('Typeahead consumer key handler order', () => {
2313
2571
  currentTarget = event.currentTarget;
2314
2572
  event.preventDefault();
2315
2573
  });
2316
- const {container} = render(
2574
+ render(
2317
2575
  <Typeahead
2318
2576
  label="Fruit"
2319
2577
  searchSource={fruitSource}
@@ -18,12 +18,12 @@ export const docs = {
18
18
  {
19
19
  name: 'entryStyle',
20
20
  type: 'StyleXStyles | null',
21
- description: 'A StyleX style object for the entry animation, or null if the element was rendered on initial page load (no animation needed).',
21
+ description: 'A StyleX style object for the entry animation, or null if the element was rendered on initial page load or hydrated from server HTML (no animation needed).',
22
22
  },
23
23
  ],
24
24
  usage: {
25
25
  description:
26
- 'Returns a StyleX style for animating an element on mount. Only animates when the element is dynamically inserted after the initial page paint; elements rendered on page load are not animated. Uses Astryx motion tokens (duration, easing) for consistent animation timing. Requires "use client"; does not support SSR.',
26
+ 'Returns a StyleX style for animating an element on mount. Only animates when the element is dynamically inserted after the initial page paint; elements rendered on page load are not animated. Uses Astryx motion tokens (duration, easing) for consistent animation timing. Server-rendered elements hydrate without the entry style and never animate; elements mounted after hydration animate.',
27
27
  bestPractices: [
28
28
  { guidance: true, description: 'Use for conditionally rendered elements like validation messages, toasts, or expanding sections.' },
29
29
  { guidance: true, description: 'Spread the returned style into stylex.props() alongside other styles.' },
@@ -39,7 +39,7 @@ export const docs = {
39
39
  /** @type {import('@astryxdesign/cli/authoring').HookTranslationDoc} */
40
40
  export const docsDense = {
41
41
  description:
42
- 'Returns StyleX style for animating element on mount. Only animates when element dynamically inserted after initial page paint; elements rendered on page load not animated. Uses Astryx motion tokens (duration, easing) for consistent timing. Requires "use client"; does not support SSR.',
42
+ 'Returns StyleX style for animating element on mount. Only animates when element dynamically inserted after initial page paint; elements rendered on page load not animated. Uses Astryx motion tokens (duration, easing) for consistent timing. Server-rendered elements hydrate without entry style, never animate; elements mounted after hydration animate.',
43
43
  paramDescriptions: {
44
44
  preset: 'animation preset applied on mount.',
45
45
  },
@@ -48,7 +48,7 @@ export const docsDense = {
48
48
  },
49
49
  usage: {
50
50
  description:
51
- 'Returns StyleX style for animating element on mount. Only animates when element dynamically inserted after initial page paint; elements rendered on page load not animated. Uses Astryx motion tokens (duration, easing) for consistent timing. Requires "use client"; does not support SSR.',
51
+ 'Returns StyleX style for animating element on mount. Only animates when element dynamically inserted after initial page paint; elements rendered on page load not animated. Uses Astryx motion tokens (duration, easing) for consistent timing. Server-rendered elements hydrate without entry style, never animate; elements mounted after hydration animate.',
52
52
  bestPractices: [
53
53
  { guidance: true, description: 'Use for conditionally rendered elements like validation messages, toasts, expanding sections.' },
54
54
  { guidance: true, description: 'Spread returned style into stylex.props() alongside other styles.' },