@astryxdesign/core 0.7.1 → 0.7.2-canary.151434a

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 (251) hide show
  1. package/dist/AspectRatio/AspectRatio.d.ts +6 -8
  2. package/dist/AspectRatio/AspectRatio.d.ts.map +1 -1
  3. package/dist/AspectRatio/AspectRatio.js +44 -3
  4. package/dist/Button/Button.d.ts.map +1 -1
  5. package/dist/Button/Button.js +38 -14
  6. package/dist/CheckboxInput/CheckboxInput.d.ts +1 -1
  7. package/dist/CheckboxInput/CheckboxInput.d.ts.map +1 -1
  8. package/dist/CheckboxInput/CheckboxInput.js +3 -1
  9. package/dist/CheckboxList/CheckboxListItem.d.ts +9 -1
  10. package/dist/CheckboxList/CheckboxListItem.d.ts.map +1 -1
  11. package/dist/CheckboxList/CheckboxListItem.js +4 -2
  12. package/dist/Dialog/Dialog.d.ts.map +1 -1
  13. package/dist/Dialog/Dialog.js +20 -8
  14. package/dist/Drawer/Drawer.d.ts +191 -0
  15. package/dist/Drawer/Drawer.d.ts.map +1 -0
  16. package/dist/Drawer/Drawer.js +382 -0
  17. package/dist/Drawer/DrawerHeader.d.ts +85 -0
  18. package/dist/Drawer/DrawerHeader.d.ts.map +1 -0
  19. package/dist/Drawer/DrawerHeader.js +134 -0
  20. package/dist/Drawer/index.d.ts +11 -0
  21. package/dist/Drawer/index.d.ts.map +1 -0
  22. package/dist/Drawer/index.js +11 -0
  23. package/dist/Drawer/useDrawerDialogPresence.d.ts +42 -0
  24. package/dist/Drawer/useDrawerDialogPresence.d.ts.map +1 -0
  25. package/dist/Drawer/useDrawerDialogPresence.js +236 -0
  26. package/dist/DropdownMenu/DropdownMenu.js +1 -1
  27. package/dist/DropdownMenu/DropdownMenuDivider.d.ts +5 -3
  28. package/dist/DropdownMenu/DropdownMenuDivider.d.ts.map +1 -1
  29. package/dist/DropdownMenu/DropdownMenuDivider.js +7 -3
  30. package/dist/DropdownMenu/DropdownMenuSubMenu.js +4 -4
  31. package/dist/EmptyState/EmptyState.d.ts.map +1 -1
  32. package/dist/EmptyState/EmptyState.js +4 -10
  33. package/dist/Field/Field.d.ts +1 -1
  34. package/dist/Field/Field.d.ts.map +1 -1
  35. package/dist/Field/Field.js +8 -4
  36. package/dist/HoverCard/useHoverCard.d.ts.map +1 -1
  37. package/dist/HoverCard/useHoverCard.js +10 -2
  38. package/dist/Item/Item.d.ts +6 -2
  39. package/dist/Item/Item.d.ts.map +1 -1
  40. package/dist/Item/Item.js +19 -4
  41. package/dist/Layer/layerViewportInset.stylex.d.ts +6 -2
  42. package/dist/Layer/layerViewportInset.stylex.d.ts.map +1 -1
  43. package/dist/Layer/layerViewportInset.stylex.js +6 -2
  44. package/dist/Layer/useLayer.d.ts.map +1 -1
  45. package/dist/Layer/useLayer.js +13 -7
  46. package/dist/Layer/useLayerDismissal.d.ts +1 -1
  47. package/dist/Layer/useLayerDismissal.js +1 -1
  48. package/dist/Layout/container.stylex.d.ts +5 -5
  49. package/dist/Layout/container.stylex.js +4 -4
  50. package/dist/List/List.d.ts +46 -19
  51. package/dist/List/List.d.ts.map +1 -1
  52. package/dist/List/List.js +28 -10
  53. package/dist/List/ListContext.d.ts +8 -3
  54. package/dist/List/ListContext.d.ts.map +1 -1
  55. package/dist/List/ListContext.js +7 -2
  56. package/dist/List/ListItem.d.ts +13 -5
  57. package/dist/List/ListItem.d.ts.map +1 -1
  58. package/dist/List/ListItem.js +21 -8
  59. package/dist/List/index.d.ts +1 -1
  60. package/dist/List/index.d.ts.map +1 -1
  61. package/dist/Markdown/Markdown.d.ts.map +1 -1
  62. package/dist/Markdown/Markdown.js +8 -1
  63. package/dist/Markdown/plugins/frontmatter.d.ts.map +1 -1
  64. package/dist/Markdown/plugins/frontmatter.js +7 -3
  65. package/dist/MetadataList/MetadataList.d.ts.map +1 -1
  66. package/dist/MetadataList/MetadataList.js +5 -1
  67. package/dist/MetadataList/MetadataListContext.d.ts +1 -1
  68. package/dist/MetadataList/MetadataListContext.d.ts.map +1 -1
  69. package/dist/MultiSelector/MultiSelector.d.ts.map +1 -1
  70. package/dist/MultiSelector/MultiSelector.js +22 -8
  71. package/dist/MultiSelector/OptionActions.a11y.chromium.spec.js +100 -2
  72. package/dist/MultiSelector/hooks.d.ts.map +1 -1
  73. package/dist/MultiSelector/hooks.js +3 -1
  74. package/dist/Pagination/Pagination.d.ts +8 -5
  75. package/dist/Pagination/Pagination.d.ts.map +1 -1
  76. package/dist/Pagination/Pagination.js +21 -8
  77. package/dist/Popover/Popover.js +2 -2
  78. package/dist/PowerSearch/PowerSearch.js +1 -1
  79. package/dist/RadioList/RadioListItem.d.ts +9 -1
  80. package/dist/RadioList/RadioListItem.d.ts.map +1 -1
  81. package/dist/RadioList/RadioListItem.js +2 -0
  82. package/dist/Selector/hooks.d.ts.map +1 -1
  83. package/dist/Selector/hooks.js +6 -2
  84. package/dist/Switch/Switch.d.ts +1 -1
  85. package/dist/Switch/Switch.d.ts.map +1 -1
  86. package/dist/Switch/Switch.js +13 -1
  87. package/dist/TabList/TabMenu.d.ts +2 -2
  88. package/dist/TabList/TabMenu.d.ts.map +1 -1
  89. package/dist/TabList/TabMenu.js +6 -3
  90. package/dist/Text/useTruncation.d.ts +7 -5
  91. package/dist/Text/useTruncation.d.ts.map +1 -1
  92. package/dist/Text/useTruncation.js +16 -5
  93. package/dist/Tooltip/useTooltip.d.ts.map +1 -1
  94. package/dist/Tooltip/useTooltip.js +11 -0
  95. package/dist/Typeahead/BaseTypeahead.d.ts.map +1 -1
  96. package/dist/Typeahead/BaseTypeahead.js +26 -0
  97. package/dist/astryx.css +35 -12
  98. package/dist/hooks/useEntryAnimation.d.ts +2 -1
  99. package/dist/hooks/useEntryAnimation.d.ts.map +1 -1
  100. package/dist/hooks/useEntryAnimation.js +14 -12
  101. package/dist/hooks/useIsHydrating.d.ts +6 -0
  102. package/dist/hooks/useIsHydrating.d.ts.map +1 -0
  103. package/dist/hooks/useIsHydrating.js +30 -0
  104. package/dist/i18n/generated-locales/en.generated.d.ts.map +1 -1
  105. package/dist/i18n/generated-locales/en.generated.js +112 -1
  106. package/dist/i18n/generated-locales/pseudo.generated.d.ts.map +1 -1
  107. package/dist/i18n/generated-locales/pseudo.generated.js +112 -1
  108. package/dist/index.d.ts +1 -0
  109. package/dist/index.d.ts.map +1 -1
  110. package/dist/index.js +1 -0
  111. package/dist/theme/derivedVarRegistry.d.ts.map +1 -1
  112. package/dist/theme/derivedVarRegistry.js +0 -3
  113. package/dist/utils/focusOutline.stylex.d.ts +4 -0
  114. package/dist/utils/focusOutline.stylex.d.ts.map +1 -1
  115. package/dist/utils/focusOutline.stylex.js +4 -0
  116. package/dist/utils/plainDate.d.ts.map +1 -1
  117. package/dist/utils/plainDate.js +15 -9
  118. package/dist/utils/sharedMutationObserver.d.ts +21 -0
  119. package/dist/utils/sharedMutationObserver.d.ts.map +1 -0
  120. package/dist/utils/sharedMutationObserver.js +69 -0
  121. package/locales/en.json +444 -0
  122. package/locales/pseudo.json +333 -0
  123. package/package.json +9 -4
  124. package/src/AspectRatio/AspectRatio.test.tsx +44 -43
  125. package/src/AspectRatio/AspectRatio.tsx +38 -18
  126. package/src/AspectRatio/__tests__/AspectRatioFitLayers.a11y.browser.spec.ts +157 -0
  127. package/src/Button/Button.doc.mjs +2 -2
  128. package/src/Button/Button.test.tsx +155 -9
  129. package/src/Button/Button.tsx +39 -16
  130. package/src/Button/__tests__/Button.a11y.known-failures.ts +1 -62
  131. package/src/Button/__tests__/Button.a11y.states.ts +0 -10
  132. package/src/CheckboxInput/CheckboxInput.test.tsx +34 -0
  133. package/src/CheckboxInput/CheckboxInput.tsx +3 -1
  134. package/src/CheckboxList/CheckboxList.test.tsx +22 -0
  135. package/src/CheckboxList/CheckboxListItem.doc.mjs +16 -0
  136. package/src/CheckboxList/CheckboxListItem.tsx +10 -0
  137. package/src/Dialog/Dialog.test.tsx +46 -0
  138. package/src/Dialog/Dialog.tsx +20 -7
  139. package/src/Dialog/__tests__/Dialog.a11y.known-failures.ts +0 -14
  140. package/src/Drawer/Drawer.doc.mjs +472 -0
  141. package/src/Drawer/Drawer.spec.md +357 -0
  142. package/src/Drawer/Drawer.test.tsx +1300 -0
  143. package/src/Drawer/Drawer.tsx +613 -0
  144. package/src/Drawer/DrawerDirection.test.tsx +127 -0
  145. package/src/Drawer/DrawerHeader.doc.mjs +293 -0
  146. package/src/Drawer/DrawerHeader.test.tsx +102 -0
  147. package/src/Drawer/DrawerHeader.tsx +235 -0
  148. package/src/Drawer/__tests__/DrawerAudit.a11y.chromium.spec.ts +401 -0
  149. package/src/Drawer/__tests__/DrawerHeaderAudit.a11y.chromium.spec.ts +297 -0
  150. package/src/Drawer/index.ts +13 -0
  151. package/src/Drawer/useDrawerDialogPresence.ts +284 -0
  152. package/src/DropdownMenu/DropdownMenu.test.tsx +21 -12
  153. package/src/DropdownMenu/DropdownMenu.tsx +2 -2
  154. package/src/DropdownMenu/DropdownMenuDivider.doc.mjs +2 -2
  155. package/src/DropdownMenu/DropdownMenuDivider.tsx +9 -5
  156. package/src/DropdownMenu/DropdownMenuSubMenu.tsx +2 -2
  157. package/src/DropdownMenu/__tests__/Menu.a11y.chromium.spec.ts +145 -0
  158. package/src/DropdownMenu/__tests__/Menu.a11y.known-failures.ts +26 -0
  159. package/src/DropdownMenu/__tests__/Menu.a11y.renders.tsx +65 -0
  160. package/src/DropdownMenu/__tests__/Menu.a11y.states.ts +138 -0
  161. package/src/DropdownMenu/__tests__/Menu.a11y.test.tsx +136 -0
  162. package/src/EmptyState/EmptyState.doc.mjs +3 -2
  163. package/src/EmptyState/EmptyState.spec.md +189 -0
  164. package/src/EmptyState/EmptyState.test.tsx +74 -3
  165. package/src/EmptyState/EmptyState.tsx +4 -8
  166. package/src/Field/Field.doc.mjs +14 -8
  167. package/src/Field/Field.spec.md +217 -0
  168. package/src/Field/Field.test.tsx +60 -2
  169. package/src/Field/Field.tsx +17 -8
  170. package/src/HoverCard/HoverCard.test.tsx +58 -0
  171. package/src/HoverCard/useHoverCard.tsx +10 -2
  172. package/src/IconButton/IconButton.doc.mjs +2 -2
  173. package/src/IconButton/IconButton.test.tsx +3 -1
  174. package/src/Item/Item.doc.mjs +12 -8
  175. package/src/Item/Item.spec.md +226 -0
  176. package/src/Item/Item.test.tsx +61 -0
  177. package/src/Item/Item.tsx +40 -4
  178. package/src/Layer/layerViewportInset.source-build.test.mjs +90 -0
  179. package/src/Layer/layerViewportInset.stylex.ts +6 -2
  180. package/src/Layer/layerViewportInset.test.ts +1 -0
  181. package/src/Layer/useLayer.tsx +24 -13
  182. package/src/Layer/useLayerDismissal.ts +1 -1
  183. package/src/Layout/container.stylex.ts +6 -6
  184. package/src/List/List.doc.mjs +14 -1
  185. package/src/List/List.spec.md +129 -77
  186. package/src/List/List.test.tsx +163 -94
  187. package/src/List/List.tsx +74 -18
  188. package/src/List/ListContext.tsx +9 -3
  189. package/src/List/ListItem.doc.mjs +24 -5
  190. package/src/List/ListItem.tsx +56 -27
  191. package/src/List/index.ts +1 -1
  192. package/src/Markdown/Markdown.tsx +14 -1
  193. package/src/Markdown/plugins/frontmatter.test.tsx +25 -0
  194. package/src/Markdown/plugins/frontmatter.ts +7 -3
  195. package/src/MetadataList/MetadataList.doc.mjs +2 -2
  196. package/src/MetadataList/MetadataList.test.tsx +38 -0
  197. package/src/MetadataList/MetadataList.tsx +8 -1
  198. package/src/MetadataList/MetadataListContext.tsx +1 -1
  199. package/src/MultiSelector/MultiSelector.test.tsx +159 -0
  200. package/src/MultiSelector/MultiSelector.tsx +40 -7
  201. package/src/MultiSelector/OptionActions.a11y.chromium.spec.ts +112 -2
  202. package/src/MultiSelector/hooks.ts +3 -1
  203. package/src/MultiSelector/useMultiCombobox.doc.mjs +267 -0
  204. package/src/Pagination/Pagination.doc.mjs +7 -7
  205. package/src/Pagination/Pagination.spec.md +9 -9
  206. package/src/Pagination/Pagination.test.tsx +242 -0
  207. package/src/Pagination/Pagination.tsx +27 -11
  208. package/src/Popover/Popover.test.tsx +2 -2
  209. package/src/Popover/Popover.tsx +4 -4
  210. package/src/PowerSearch/PowerSearch.test.tsx +85 -0
  211. package/src/PowerSearch/PowerSearch.tsx +2 -2
  212. package/src/RadioList/RadioList.test.tsx +22 -0
  213. package/src/RadioList/RadioListItem.doc.mjs +16 -0
  214. package/src/RadioList/RadioListItem.tsx +10 -1
  215. package/src/Selector/hooks.ts +6 -2
  216. package/src/Selector/useCombobox.doc.mjs +237 -0
  217. package/src/Switch/Switch.test.tsx +49 -0
  218. package/src/Switch/Switch.tsx +11 -0
  219. package/src/TabList/TabList.spec.md +57 -44
  220. package/src/TabList/TabList.test.tsx +67 -0
  221. package/src/TabList/TabMenu.doc.mjs +4 -3
  222. package/src/TabList/TabMenu.tsx +7 -4
  223. package/src/Text/useTruncation.test.tsx +69 -0
  224. package/src/Text/useTruncation.ts +16 -5
  225. package/src/Tokenizer/Tokenizer.test.tsx +54 -1
  226. package/src/Tooltip/Tooltip.test.tsx +31 -0
  227. package/src/Tooltip/useTooltip.test.tsx +13 -0
  228. package/src/Tooltip/useTooltip.tsx +11 -0
  229. package/src/TreeList/TreeList.spec.md +29 -17
  230. package/src/Typeahead/BaseTypeahead.tsx +26 -0
  231. package/src/Typeahead/Typeahead.test.tsx +260 -2
  232. package/src/hooks/useEntryAnimation.doc.mjs +4 -4
  233. package/src/hooks/useEntryAnimation.ssr.test.tsx +143 -0
  234. package/src/hooks/useEntryAnimation.ts +15 -16
  235. package/src/hooks/useIsHydrating.test.tsx +70 -0
  236. package/src/hooks/useIsHydrating.ts +31 -0
  237. package/src/i18n/InternationalizationProvider.doc.mjs +8 -0
  238. package/src/i18n/InternationalizationProvider.spec.md +252 -0
  239. package/src/i18n/__tests__/InternationalizationProvider.test.tsx +128 -0
  240. package/src/i18n/generated-locales/en.generated.ts +121 -0
  241. package/src/i18n/generated-locales/pseudo.generated.ts +121 -0
  242. package/src/i18n/useTranslator.test.tsx +37 -0
  243. package/src/index.ts +1 -0
  244. package/src/reset.css +0 -29
  245. package/src/theme/derivedVarRegistry.test.ts +3 -3
  246. package/src/theme/derivedVarRegistry.ts +0 -3
  247. package/src/utils/focusOutline.stylex.ts +4 -0
  248. package/src/utils/plainDate.test.ts +37 -1
  249. package/src/utils/plainDate.ts +15 -5
  250. package/src/utils/sharedMutationObserver.test.ts +53 -0
  251. package/src/utils/sharedMutationObserver.ts +78 -0
@@ -0,0 +1,157 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file AspectRatioFitLayers.a11y.browser.spec.ts
5
+ * @input The built FitModes story (its rendered markup and compiled CSS) and
6
+ * Tailwind's preflight.css
7
+ * @output Browser evidence that `fit` fills the box on the documented setups
8
+ * @position AspectRatio integration proof. Which rule sizes the child is a
9
+ * cascade-layer question, and only a shipping engine resolves the cascade.
10
+ */
11
+
12
+ import * as fs from 'node:fs';
13
+ import {fileURLToPath} from 'node:url';
14
+ import {expect, test, type Page} from '@playwright/test';
15
+ import {
16
+ DEFAULT_STORYBOOK_DIR,
17
+ serveStorybook,
18
+ type StaticServer,
19
+ } from '@astryxdesign/a11y-spec/storybook';
20
+
21
+ const PREFLIGHT_CSS = fs.readFileSync(
22
+ fileURLToPath(import.meta.resolve('tailwindcss/preflight.css')),
23
+ 'utf8',
24
+ );
25
+
26
+ // The layer order each setup guide declares, and the layer preflight goes in.
27
+ const TAILWIND_SETUPS = [
28
+ {
29
+ name: 'Tailwind v4',
30
+ order:
31
+ '@layer reset, theme, base, astryx-base, astryx-theme, components, utilities;',
32
+ preflightLayer: 'base',
33
+ },
34
+ {
35
+ name: 'Tailwind v3',
36
+ order: '@layer reset, tw-preflight, astryx-base, astryx-theme;',
37
+ preflightLayer: 'tw-preflight',
38
+ },
39
+ ];
40
+
41
+ // A 100×100 image in a 320px-wide 16:9 box: filling the box makes it 320×180.
42
+ const IMAGE =
43
+ "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100'/%3E";
44
+
45
+ type Fit = 'cover' | 'contain';
46
+
47
+ let storybook: StaticServer;
48
+ test.beforeAll(async () => {
49
+ storybook = await serveStorybook(
50
+ process.env.ASTRYX_STORYBOOK_DIR ?? DEFAULT_STORYBOOK_DIR,
51
+ );
52
+ });
53
+ test.afterAll(async () => {
54
+ await storybook?.close();
55
+ });
56
+
57
+ /**
58
+ * The markup AspectRatio renders for `fit`, and every CSS rule the story
59
+ * page loaded, taken from the built story so the classes and rules are the
60
+ * component's real compiled output. The child image gets a fixed id, a
61
+ * local source and any extra class.
62
+ */
63
+ async function captureStory(page: Page, fit: Fit, mediaClass: string) {
64
+ await page.goto(
65
+ `${storybook.origin}/iframe.html?id=core-aspectratio--fit-modes&viewMode=story`,
66
+ );
67
+ const wrapper = page.locator(`[data-astryx-aspect-ratio-override="${fit}"]`);
68
+ await expect(wrapper).toHaveCount(1);
69
+ return wrapper.evaluate(
70
+ (element, {image, extraClass}) => {
71
+ const root = element.parentElement?.cloneNode(true);
72
+ const media =
73
+ root instanceof HTMLElement ? root.querySelector('img') : null;
74
+ if (!(root instanceof HTMLElement) || media == null) {
75
+ throw new Error('FitModes no longer renders an img inside AspectRatio');
76
+ }
77
+ media.id = 'media';
78
+ media.src = image;
79
+ if (extraClass) {
80
+ media.classList.add(extraClass);
81
+ }
82
+ const css = [...document.styleSheets]
83
+ .flatMap(sheet => [...sheet.cssRules].map(rule => rule.cssText))
84
+ .join('\n');
85
+ return {html: root.outerHTML, css};
86
+ },
87
+ {image: IMAGE, extraClass: mediaClass},
88
+ );
89
+ }
90
+
91
+ /** Re-host the captured story with `before` CSS ahead of it and `after` CSS behind it. */
92
+ async function measureMedia(
93
+ page: Page,
94
+ fit: Fit,
95
+ {
96
+ before = [],
97
+ after = [],
98
+ mediaClass = '',
99
+ }: {
100
+ before?: string[];
101
+ after?: string[];
102
+ mediaClass?: string;
103
+ },
104
+ ) {
105
+ const {html, css} = await captureStory(page, fit, mediaClass);
106
+ await page.setContent(
107
+ `<!doctype html><div style="width: 320px">${html}</div>`,
108
+ );
109
+ for (const content of [...before, css, ...after]) {
110
+ await page.addStyleTag({content});
111
+ }
112
+ await page.waitForFunction(
113
+ () => (document.getElementById('media') as HTMLImageElement).complete,
114
+ );
115
+ return page.evaluate(() => {
116
+ const media = document.getElementById('media');
117
+ if (!media) {
118
+ throw new Error('missing media');
119
+ }
120
+ const box = media.getBoundingClientRect();
121
+ return {
122
+ width: box.width,
123
+ height: box.height,
124
+ objectFit: getComputedStyle(media).objectFit,
125
+ };
126
+ });
127
+ }
128
+
129
+ for (const setup of TAILWIND_SETUPS) {
130
+ for (const fit of ['cover', 'contain'] as const) {
131
+ test(`fit="${fit}" fills the box on the ${setup.name} setup`, async ({
132
+ page,
133
+ }) => {
134
+ const media = await measureMedia(page, fit, {
135
+ before: [
136
+ setup.order,
137
+ `@layer ${setup.preflightLayer} { ${PREFLIGHT_CSS} }`,
138
+ ],
139
+ });
140
+ expect(media).toEqual({width: 320, height: 180, objectFit: fit});
141
+ });
142
+ }
143
+ }
144
+
145
+ test('fit fills the box with only Astryx CSS loaded', async ({page}) => {
146
+ const media = await measureMedia(page, 'cover', {});
147
+ expect(media).toEqual({width: 320, height: 180, objectFit: 'cover'});
148
+ });
149
+
150
+ test('a utility class on the child still wins over fit', async ({page}) => {
151
+ const media = await measureMedia(page, 'cover', {
152
+ before: [TAILWIND_SETUPS[0].order, `@layer base { ${PREFLIGHT_CSS} }`],
153
+ after: ['@layer utilities { .h-10 { height: 40px; } }'],
154
+ mediaClass: 'h-10',
155
+ });
156
+ expect(media).toEqual({width: 320, height: 40, objectFit: 'cover'});
157
+ });
@@ -138,7 +138,7 @@ export const docs = {
138
138
  {
139
139
  name: 'isLoading',
140
140
  type: 'boolean',
141
- description: 'Shows a loading spinner and disables interaction. Announces "Loading" via a live region.',
141
+ description: 'Shows a loading spinner and blocks re-activation while staying focusable (aria-busy + aria-disabled, not native disabled, so keyboard focus is never dropped mid-action). Announces "Loading" via a live region.',
142
142
  default: 'false',
143
143
  },
144
144
  {
@@ -419,7 +419,7 @@ export const docsDense = {
419
419
  displayName: 'HTML name for form submission',
420
420
  value: 'HTML value for form submission',
421
421
  form: 'associates button with form element by ID',
422
- isLoading: 'shows spinner+disables interaction; announces via live region',
422
+ isLoading: 'shows spinner, blocks re-activation but stays focusable (aria-disabled, not native disabled); announces via live region',
423
423
  icon: 'icon element rendered before label text; unsized Astryx Icon defaults to sm for sm/md buttons and md for lg',
424
424
  isIconOnly: 'when true, renders square icon-only button; label becomes aria-label',
425
425
  width: "Width of button. Numbers=pixels, strings=as-is (e.g. '100%' for full-width). Default: content width, capped at the container; label truncates w/ ellipsis in a narrow row; icon-only stays square.",
@@ -11,7 +11,13 @@
11
11
 
12
12
  import {readFileSync} from 'node:fs';
13
13
  import {describe, it, expect, vi} from 'vitest';
14
- import {render, screen, fireEvent, act} from '@testing-library/react';
14
+ import {
15
+ render,
16
+ screen,
17
+ fireEvent,
18
+ createEvent,
19
+ act,
20
+ } from '@testing-library/react';
15
21
  import userEvent from '@testing-library/user-event';
16
22
  import {Button} from './Button';
17
23
  import * as stylex from '@stylexjs/stylex';
@@ -127,8 +133,9 @@ describe('Button', () => {
127
133
  it('shows isLoading state with spinner', () => {
128
134
  render(<Button label="Submit" isLoading />);
129
135
  const button = screen.getByRole('button');
130
- // Button should be disabled when loading
131
- expect(button).toBeDisabled();
136
+ // Busy is aria-disabled (focusable), not native disabled — see #4871.
137
+ expect(button).not.toBeDisabled();
138
+ expect(button).toHaveAttribute('aria-disabled', 'true');
132
139
  expect(button.className).toContain('styles.inactive');
133
140
  expect(button.className).not.toContain('styles.disabled');
134
141
  });
@@ -143,7 +150,7 @@ describe('Button', () => {
143
150
 
144
151
  it('sets aria-busy synchronously while clickAction is pending', async () => {
145
152
  // The spinner reveal is visually delayed (CSS animation-delay), but the
146
- // loading DOM state — aria-busy and disabled — must not be delayed.
153
+ // loading DOM state — aria-busy and aria-disabled — must not be delayed.
147
154
  const user = userEvent.setup();
148
155
  let resolveAction: (() => void) | undefined;
149
156
  const clickAction = vi.fn(
@@ -157,7 +164,9 @@ describe('Button', () => {
157
164
 
158
165
  await user.click(button);
159
166
  expect(button).toHaveAttribute('aria-busy', 'true');
160
- expect(button).toBeDisabled();
167
+ // Busy is aria-disabled (focusable), not native disabled — see #4871.
168
+ expect(button).not.toBeDisabled();
169
+ expect(button).toHaveAttribute('aria-disabled', 'true');
161
170
 
162
171
  await act(async () => {
163
172
  resolveAction?.();
@@ -165,6 +174,7 @@ describe('Button', () => {
165
174
  });
166
175
  expect(button).not.toHaveAttribute('aria-busy', 'true');
167
176
  expect(button).not.toBeDisabled();
177
+ expect(button).not.toHaveAttribute('aria-disabled');
168
178
  });
169
179
 
170
180
  it('renders the loading spinner with the inherit shade for every variant (#2717)', () => {
@@ -310,9 +320,10 @@ describe('Button', () => {
310
320
  );
311
321
  // endContent should still be in the DOM
312
322
  expect(screen.getByTestId('end')).toBeInTheDocument();
313
- // Button should be disabled and have aria-busy
323
+ // Busy is aria-disabled (focusable), not native disabled — see #4871.
314
324
  const button = screen.getByRole('button');
315
- expect(button).toBeDisabled();
325
+ expect(button).not.toBeDisabled();
326
+ expect(button).toHaveAttribute('aria-disabled', 'true');
316
327
  expect(button).toHaveAttribute('aria-busy', 'true');
317
328
  });
318
329
 
@@ -516,6 +527,111 @@ describe('Button', () => {
516
527
  expect(handleKeyDown).toHaveBeenCalledTimes(1);
517
528
  });
518
529
 
530
+ it('uses aria-disabled instead of disabled while isLoading, so the button stays focusable (#4871)', () => {
531
+ render(<Button label="Save" isLoading />);
532
+ const button = screen.getByRole('button');
533
+ // Native disabled would move focus to <body> the moment the action
534
+ // starts, losing the keyboard user's place — busy must stay
535
+ // aria-disabled + focusable per the "Disabled vs Busy" convention.
536
+ expect(button).not.toHaveAttribute('disabled');
537
+ expect(button).toHaveAttribute('aria-disabled', 'true');
538
+ expect(button).toHaveAttribute('aria-busy', 'true');
539
+ button.focus();
540
+ expect(button).toHaveFocus();
541
+ });
542
+
543
+ it('does not fire onClick while aria-disabled via isLoading', async () => {
544
+ const user = userEvent.setup();
545
+ const handleClick = vi.fn();
546
+ render(<Button label="Save" isLoading onClick={handleClick} />);
547
+ await user.click(screen.getByRole('button'));
548
+ expect(handleClick).not.toHaveBeenCalled();
549
+ });
550
+
551
+ it('does not let a click on a busy button reach a wrapping ancestor handler', async () => {
552
+ // A native `disabled` element never dispatches a click, so it never
553
+ // reaches an ancestor either. aria-disabled (busy-only) is a real,
554
+ // interactive element that still dispatches one — preventDefault alone
555
+ // only cancels the button's own default action, not propagation, so
556
+ // an unrelated wrapper (a clickable row/card/backdrop) would otherwise
557
+ // still fire.
558
+ const user = userEvent.setup();
559
+ const ancestorClick = vi.fn();
560
+ render(
561
+ <div onClick={ancestorClick}>
562
+ <Button label="Save" isLoading />
563
+ </div>,
564
+ );
565
+ await user.click(screen.getByRole('button'));
566
+ expect(ancestorClick).not.toHaveBeenCalled();
567
+ });
568
+
569
+ it('does not let a click on a busy-only anchor Button reach a wrapping ancestor handler', async () => {
570
+ const user = userEvent.setup();
571
+ const ancestorClick = vi.fn();
572
+ render(
573
+ <div onClick={ancestorClick}>
574
+ <Button label="Docs" href="https://example.com" isLoading />
575
+ </div>,
576
+ );
577
+ await user.click(screen.getByRole('link'));
578
+ expect(ancestorClick).not.toHaveBeenCalled();
579
+ });
580
+
581
+ it('suppresses activation keys but passes other keys while aria-disabled via isLoading', async () => {
582
+ const user = userEvent.setup();
583
+ const handleKeyDown = vi.fn();
584
+ render(<Button label="Save" isLoading onKeyDown={handleKeyDown} />);
585
+ const button = screen.getByRole('button');
586
+ button.focus();
587
+ await user.keyboard('{Enter}');
588
+ expect(handleKeyDown).not.toHaveBeenCalled();
589
+
590
+ await user.keyboard('{Escape}');
591
+ expect(handleKeyDown).toHaveBeenCalledTimes(1);
592
+ });
593
+
594
+ it('suppresses activation keys but passes other keys on a busy-only anchor Button', async () => {
595
+ // The button-rendered path suppresses Enter/Space while aria-disabled;
596
+ // the anchor-rendered path (href set, busy-only) shares the same
597
+ // handleKeyDown but only wires onClick, so a consumer onKeyDown still
598
+ // received Enter/Space on a busy link.
599
+ const user = userEvent.setup();
600
+ const handleKeyDown = vi.fn();
601
+ render(
602
+ <Button
603
+ label="Docs"
604
+ href="https://example.com"
605
+ isLoading
606
+ onKeyDown={handleKeyDown}
607
+ />,
608
+ );
609
+ const link = screen.getByRole('link');
610
+ link.focus();
611
+ await user.keyboard('{Enter}');
612
+ expect(handleKeyDown).not.toHaveBeenCalled();
613
+
614
+ await user.keyboard('{Escape}');
615
+ expect(handleKeyDown).toHaveBeenCalledTimes(1);
616
+ });
617
+
618
+ it('keeps native disabled (not aria-disabled) when isDisabled and not busy, even without a tooltip', () => {
619
+ render(<Button label="Save" isDisabled />);
620
+ const button = screen.getByRole('button');
621
+ expect(button).toHaveAttribute('disabled');
622
+ expect(button).not.toHaveAttribute('aria-disabled');
623
+ });
624
+
625
+ it('keeps native disabled when isDisabled and isLoading are both true (isDisabled wins)', () => {
626
+ render(<Button label="Save" isDisabled isLoading />);
627
+ const button = screen.getByRole('button');
628
+ // "isDisabled behavior unchanged: that stays native disabled" — busy-only
629
+ // aria-disabled is only for the case where busy is the SOLE reason the
630
+ // button can't be clicked, not when it's also genuinely isDisabled.
631
+ expect(button).toHaveAttribute('disabled');
632
+ expect(button).not.toHaveAttribute('aria-disabled');
633
+ });
634
+
519
635
  it('has a live region that announces loading state', () => {
520
636
  const {rerender} = render(<Button label="Submit" />);
521
637
  const button = screen.getByRole('button');
@@ -663,8 +779,6 @@ describe('Button', () => {
663
779
  });
664
780
 
665
781
  it('exposes aria-busy on the link-rendered button while loading', () => {
666
- // Non-interruptible loading disables the button, which falls back to
667
- // <button> rendering — so an anchor only shows loading when interruptible.
668
782
  render(
669
783
  <Button
670
784
  label="Docs"
@@ -682,6 +796,38 @@ describe('Button', () => {
682
796
  const link = screen.getByRole('link');
683
797
  expect(link).not.toHaveAttribute('aria-busy');
684
798
  });
799
+
800
+ it('stays an anchor while busy-only, not a disabled <button> fallback (#4871)', () => {
801
+ // Non-interruptible busy is exactly the isBusyOnlyDisabled case: not
802
+ // isDisabled, blocked only because a fire-once action is in flight.
803
+ // Swapping the element to <button disabled> here would drop focus the
804
+ // same way the native disabled attribute did (credit @AKnassa, #4879).
805
+ render(<Button label="Docs" href="https://example.com" isLoading />);
806
+ const link = screen.getByRole('link', {name: 'Docs'});
807
+ expect(link.tagName).toBe('A');
808
+ expect(link).toHaveAttribute('href', 'https://example.com');
809
+ expect(link).toHaveAttribute('aria-busy', 'true');
810
+ expect(link).toHaveAttribute('aria-disabled', 'true');
811
+ expect(link).not.toHaveAttribute('disabled');
812
+ });
813
+
814
+ it('keeps a busy-only anchor focusable and guards its navigation', () => {
815
+ render(<Button label="Docs" href="https://example.com" isLoading />);
816
+ const link = screen.getByRole('link', {name: 'Docs'});
817
+ link.focus();
818
+ expect(link).toHaveFocus();
819
+
820
+ const event = createEvent.click(link);
821
+ fireEvent(link, event);
822
+ expect(event.defaultPrevented).toBe(true);
823
+ });
824
+
825
+ it('falls back to <button disabled> for a truly disabled href Button', () => {
826
+ render(<Button label="Docs" href="https://example.com" isDisabled />);
827
+ expect(screen.queryByRole('link')).not.toBeInTheDocument();
828
+ const button = screen.getByRole('button', {name: 'Docs'});
829
+ expect(button).toBeDisabled();
830
+ });
685
831
  });
686
832
 
687
833
  describe('Button pressed state (touch)', () => {
@@ -594,26 +594,37 @@ export function Button({
594
594
  // the consumer is deliberately showing it.
595
595
  const delaySpinner = isPending || isInterruptible;
596
596
  const groupDisabled = buttonGroup?.isDisabled ?? false;
597
- // When interruptible, the loading state drives the spinner and aria-busy but
598
- // not disabled, so clicks keep landing and can interrupt the in-flight action.
599
- const buttonDisabled =
600
- isDisabled || groupDisabled || (isLoadingState && !isInterruptible);
601
- // A loading button remains non-interactive, but its spinner communicates an
602
- // active state and must retain contrast. Only explicitly disabled controls
603
- // receive the visually dimmed treatment.
604
- const visuallyDisabled = isDisabled || groupDisabled;
597
+ const isTrueDisabled = isDisabled || groupDisabled;
598
+ // Busy-only: the button can't fire again purely because an action is in
599
+ // flight, not because it's genuinely isDisabled/group-disabled. Per the API
600
+ // Conventions "Disabled vs Busy" rule, busy is visual-only (aria-busy +
601
+ // spinner) and must never take focusability away — the click-handler ref
602
+ // guard (actionInFlightRef) is what actually makes a fire-once action fire
603
+ // once, so the native disabled attribute adds nothing but a focus loss
604
+ // here. When interruptible, the loading state drives the spinner and
605
+ // aria-busy but not disabled at all, so clicks keep landing and can
606
+ // interrupt the in-flight action.
607
+ const isBusyOnlyDisabled =
608
+ !isTrueDisabled && isLoadingState && !isInterruptible;
609
+ const buttonDisabled = isTrueDisabled || isBusyOnlyDisabled;
605
610
  // isIconOnly prop is the source of truth for icon-only rendering.
606
611
  // When false (default), label is always rendered as visible text.
607
612
 
608
613
  const LinkComponent = useLinkComponent(as);
609
614
 
610
- // Render as link when href is provided and button is not disabled.
611
- // Disabled links are an accessibility anti-pattern — fall back to <button>.
612
- const renderAsLink = href != null && !buttonDisabled;
615
+ // Render as link when href is provided and the button is not TRULY
616
+ // disabled. Disabled links are an accessibility anti-pattern, so a
617
+ // genuinely isDisabled/group-disabled button falls back to <button>.
618
+ // Busy-only does NOT fall back: swapping <a> for a disabled <button>
619
+ // mid-action would drop focus the same way the native attribute does
620
+ // (credit @AKnassa, #4879), which is exactly the bug this PR fixes.
621
+ const renderAsLink = href != null && !isTrueDisabled;
613
622
 
614
- // Use aria-disabled when tooltip is present so the button remains focusable
615
- // for keyboard users to reach the tooltip. Otherwise use native disabled.
616
- const useAriaDisabled = tooltip != null && buttonDisabled;
623
+ // Use aria-disabled (button stays focusable) when busy-only, or when a
624
+ // tooltip is present so keyboard users can still reach it. A genuinely
625
+ // isDisabled/group-disabled button (not busy) keeps native disabled.
626
+ const useAriaDisabled =
627
+ buttonDisabled && (isBusyOnlyDisabled || tooltip != null);
617
628
 
618
629
  // Attach tooltip behavior via the hook rather than wrapping the button in a
619
630
  // <Tooltip> element. The hook adds hover/focus triggers to the button itself,
@@ -630,6 +641,16 @@ export function Button({
630
641
  // a re-click while pending starts a fresh action that interrupts the prior.
631
642
  if (buttonDisabled || (actionInFlightRef.current && !isInterruptible)) {
632
643
  e.preventDefault();
644
+ // A native `disabled` element never dispatches a click at all, so it
645
+ // never reaches a wrapping element's own handler either. An
646
+ // aria-disabled button (busy-only, or with a tooltip) is still a real,
647
+ // interactive element the DOM keeps dispatching clicks on —
648
+ // preventDefault alone only cancels the button's OWN default action
649
+ // (form submit, link navigation), not propagation. Without this, an
650
+ // unavailable Button inside a clickable row/card/backdrop still
651
+ // triggers that ancestor's action, which the previously native-disabled
652
+ // control never did.
653
+ e.stopPropagation();
633
654
  return;
634
655
  }
635
656
  props.onClick?.(e);
@@ -669,7 +690,7 @@ export function Button({
669
690
  isIconOnly && styles.iconOnly,
670
691
  interactionOverlayStyles.backgroundImage,
671
692
  buttonDisabled && styles.inactive,
672
- visuallyDisabled && styles.disabled,
693
+ isTrueDisabled && styles.disabled,
673
694
  useAriaDisabled && styles.ariaDisabled,
674
695
  renderAsLink && styles.link,
675
696
  !buttonGroup && styles.pressable,
@@ -797,7 +818,9 @@ export function Button({
797
818
  {...describedByProp}
798
819
  {...edgeCompAttr}
799
820
  aria-busy={isLoadingState || undefined}
800
- onClick={handleClick}>
821
+ aria-disabled={useAriaDisabled || undefined}
822
+ onClick={handleClick}
823
+ {...(handleKeyDown ? {onKeyDown: handleKeyDown} : null)}>
801
824
  {buttonContent}
802
825
  </LinkComponent>
803
826
  );
@@ -22,65 +22,4 @@
22
22
 
23
23
  import type {KnownFailure} from '@astryxdesign/a11y-spec';
24
24
 
25
- export const BUTTON_KNOWN_FAILURES: ReadonlyArray<KnownFailure> = [
26
- // ---- Button and IconButton go natively disabled while busy --------------
27
- // One defect, one record per component.
28
- // They are written out rather than generated, because a record has to name
29
- // exactly one thing that is broken — a loop would make it easy to widen this
30
- // later without anyone noticing.
31
- {
32
- expectation: 'button.focus.reachable-and-escapable',
33
- binding: 'Button',
34
- state: 'button-loading',
35
- evidenceLayer: 'real-browser',
36
- failureEquals:
37
- '10 presses of Tab from the start of the document never reached the button, so a keyboard user cannot get to this action',
38
- standardsReference:
39
- 'WCAG 2.2 2.1.1 Keyboard and 2.1.2 No Keyboard Trap (Level A)',
40
- userImpact:
41
- 'A keyboard user who activates Save and waits is dropped to the top of the document the moment the action starts, and the button leaves the tab sequence entirely — so they cannot get back to it, to see that it is busy or to interrupt it. The next Tab restarts from the beginning of the page.',
42
- reason:
43
- 'Button sets the native disabled attribute while a clickAction is pending. A natively disabled element is neither focusable nor a tab stop. Separate implementation work will turn this record into an unexpected pass.',
44
- },
45
- {
46
- expectation: 'button.focus.reachable-and-escapable',
47
- binding: 'IconButton',
48
- state: 'icon-button-loading',
49
- evidenceLayer: 'real-browser',
50
- failureEquals:
51
- '10 presses of Tab from the start of the document never reached the button, so a keyboard user cannot get to this action',
52
- standardsReference:
53
- 'WCAG 2.2 2.1.1 Keyboard and 2.1.2 No Keyboard Trap (Level A)',
54
- userImpact:
55
- 'The same drop from an icon button, where it is worse: an icon button is usually one of several in a row, so the user loses their place among them.',
56
- reason:
57
- 'IconButton is a thin wrapper over Button and inherits the behaviour exactly.',
58
- },
59
-
60
- {
61
- expectation: 'button.unavailable.inert',
62
- binding: 'Button',
63
- state: 'button-loading',
64
- evidenceLayer: 'real-browser',
65
- failureEquals:
66
- 'this state is declared focusable so its reason stays reachable, but it cannot take focus — so a keyboard user can neither read why it is unavailable nor reach it to confirm it refuses to act',
67
- standardsReference:
68
- 'Current Astryx family:buttons FR3 and WAI-ARIA APG Button unavailable-state requirement; supports WCAG 2.2 4.1.2 Name, Role, Value (Level A)',
69
- userImpact:
70
- 'The third face of the same defect: because the busy button cannot take focus, there is no way to confirm from the keyboard that it declines a second press — the user can neither reach it nor see why it is unavailable.',
71
- reason:
72
- 'Same native disabled attribute. Recorded separately because a record names exactly one outcome, and a fix that restored focus without keeping the button inert would satisfy one of these and not the other.',
73
- },
74
- {
75
- expectation: 'button.unavailable.inert',
76
- binding: 'IconButton',
77
- state: 'icon-button-loading',
78
- evidenceLayer: 'real-browser',
79
- failureEquals:
80
- 'this state is declared focusable so its reason stays reachable, but it cannot take focus — so a keyboard user can neither read why it is unavailable nor reach it to confirm it refuses to act',
81
- standardsReference:
82
- 'Current Astryx family:buttons FR3 and WAI-ARIA APG Button unavailable-state requirement; supports WCAG 2.2 4.1.2 Name, Role, Value (Level A)',
83
- userImpact: 'The same, from an icon button.',
84
- reason: 'Inherited from Button, as above.',
85
- },
86
- ];
25
+ export const BUTTON_KNOWN_FAILURES: ReadonlyArray<KnownFailure> = [];
@@ -177,16 +177,9 @@ export const BUTTON_BINDING_STATES = [
177
177
  binding: 'Button',
178
178
  summary:
179
179
  'a button waiting on the action it started: the action is unavailable, and it is meant to stay focusable so the user can see that and interrupt it',
180
- // `focusable: true` is the declaration, and the component does not deliver
181
- // it — see the known-failure records. Declaring what the component does
182
- // instead would make the expectations that catch it not-applicable, which
183
- // is how a contract quietly stops noticing a defect.
184
180
  facts: facts({operable: false, unavailable: true}),
185
181
  visibleLabel: null,
186
182
  storyId: 'a11y-button-pattern--button-loading',
187
- declaredNotDelivered: [
188
- {fact: 'focusable', owned: 'button.focus.reachable-and-escapable'},
189
- ],
190
183
  },
191
184
 
192
185
  // ---- IconButton ---------------------------------------------------------
@@ -214,9 +207,6 @@ export const BUTTON_BINDING_STATES = [
214
207
  facts: facts({operable: false, unavailable: true}),
215
208
  visibleLabel: null,
216
209
  storyId: 'a11y-button-pattern--icon-button-loading',
217
- declaredNotDelivered: [
218
- {fact: 'focusable', owned: 'button.focus.reachable-and-escapable'},
219
- ],
220
210
  },
221
211
 
222
212
  // ---- ClickableCard ------------------------------------------------------
@@ -209,6 +209,40 @@ describe('CheckboxInput', () => {
209
209
  );
210
210
  });
211
211
 
212
+ it('preserves a caller-provided id on the input and its label', () => {
213
+ render(
214
+ <CheckboxInput
215
+ id="accept-terms"
216
+ label="Accept terms"
217
+ value={false}
218
+ onChange={() => {}}
219
+ />,
220
+ );
221
+
222
+ const checkbox = screen.getByRole('checkbox');
223
+ expect(checkbox).toHaveAttribute('id', 'accept-terms');
224
+ expect(screen.getByText('Accept terms').closest('label')).toHaveAttribute(
225
+ 'for',
226
+ 'accept-terms',
227
+ );
228
+ expect(screen.getByLabelText('Accept terms')).toBe(checkbox);
229
+ });
230
+
231
+ it('generates an id the label resolves when the caller passes an empty id', () => {
232
+ render(
233
+ <CheckboxInput
234
+ id=""
235
+ label="Accept terms"
236
+ value={false}
237
+ onChange={() => {}}
238
+ />,
239
+ );
240
+
241
+ const checkbox = screen.getByRole('checkbox');
242
+ expect(checkbox.id).not.toBe('');
243
+ expect(screen.getByLabelText('Accept terms')).toBe(checkbox);
244
+ });
245
+
212
246
  it('forwards arbitrary data-* attributes to the input', () => {
213
247
  render(
214
248
  <CheckboxInput
@@ -311,6 +311,7 @@ const dynamicWidthStyles = stylex.create({
311
311
  * ```
312
312
  */
313
313
  export function CheckboxInput({
314
+ id: idProp,
314
315
  label,
315
316
  isLabelHidden = false,
316
317
  description,
@@ -340,7 +341,8 @@ export function CheckboxInput({
340
341
  // The row is the pressable: the overlay's pressed arm reads the row's
341
342
  // scope marker, the way the indicator's hover tint does.
342
343
  const pressable = usePressFeedback();
343
- const id = useId();
344
+ const generatedId = useId();
345
+ const id = idProp || generatedId;
344
346
  const descriptionID = useId();
345
347
  const statusMessageID = useId();
346
348
  // Announce the effective required state (form default included) while the