@aleph-alpha/ui-library 7.0.0 → 7.0.2

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 (118) hide show
  1. package/dist/system/components/UiDropdownMenu/useMobileSubmenuPlacement.d.ts +1 -1
  2. package/dist/system/icons/story-sidebar-icons.json +74 -17
  3. package/dist/system/lib.js +1167 -1162
  4. package/dist/system/patterns/UiPlaceholder/types.d.ts +1 -0
  5. package/dist/system/story-sidebar-icons.json +74 -17
  6. package/package.json +8 -3
  7. package/src/components/UiAccordion/UiAccordion.guidance.md +66 -0
  8. package/src/components/UiAccordion/UiAccordion.stories.ts +131 -139
  9. package/src/components/UiAlert/UiAlert.guidance.md +66 -0
  10. package/src/components/UiAlert/UiAlert.stories.ts +167 -143
  11. package/src/components/UiAlertDialog/UiAlertDialog.guidance.md +66 -0
  12. package/src/components/UiAlertDialog/UiAlertDialog.stories.ts +136 -112
  13. package/src/components/UiAutocomplete/UiAutocomplete.guidance.md +66 -0
  14. package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +123 -99
  15. package/src/components/UiAvatar/UiAvatar.guidance.md +63 -0
  16. package/src/components/UiAvatar/UiAvatar.stories.ts +340 -0
  17. package/src/components/UiAvatar/UiAvatarImage.vue +5 -1
  18. package/src/components/UiAvatar/__tests__/UiAvatar.test.ts +14 -0
  19. package/src/components/UiBadge/UiBadge.guidance.md +65 -0
  20. package/src/components/UiBadge/UiBadge.stories.ts +325 -0
  21. package/src/components/UiBreadcrumb/UiBreadcrumb.guidance.md +67 -0
  22. package/src/components/UiBreadcrumb/UiBreadcrumb.stories.ts +165 -141
  23. package/src/components/UiButton/UiButton.stories.ts +5 -2
  24. package/src/components/UiButtonGroup/UiButtonGroup.guidance.md +63 -0
  25. package/src/components/UiButtonGroup/UiButtonGroup.stories.ts +91 -67
  26. package/src/components/UiCalendar/UiCalendar.guidance.md +65 -0
  27. package/src/components/UiCalendar/UiCalendar.stories.ts +103 -110
  28. package/src/components/UiCard/UiCard.guidance.md +65 -0
  29. package/src/components/UiCard/UiCard.stories.ts +393 -0
  30. package/src/components/UiCheckbox/UiCheckbox.guidance.md +62 -0
  31. package/src/components/UiCheckbox/UiCheckbox.stories.ts +18 -56
  32. package/src/components/UiChip/UiChip.guidance.md +64 -0
  33. package/src/components/UiChip/UiChip.stories.ts +162 -138
  34. package/src/components/UiCodeBlock/UiCodeBlock.stories.ts +291 -0
  35. package/src/components/UiCodeBlock/UiCodeBlock.vue +2 -1
  36. package/src/components/UiCodeBlock/__tests__/UiCodeBlock.test.ts +18 -0
  37. package/src/components/UiDialog/UiDialog.guidance.md +66 -0
  38. package/src/components/UiDialog/UiDialog.stories.ts +90 -66
  39. package/src/components/UiDrawer/UiDrawer.guidance.md +66 -0
  40. package/src/components/UiDrawer/UiDrawer.stories.ts +186 -162
  41. package/src/components/UiDropdownMenu/UiDropdownMenu.guidance.md +68 -0
  42. package/src/components/UiDropdownMenu/UiDropdownMenu.stories.ts +332 -85
  43. package/src/components/UiDropdownMenu/__tests__/UiDropdownMenu.test.ts +134 -0
  44. package/src/components/UiDropdownMenu/useMobileSubmenuPlacement.ts +23 -2
  45. package/src/components/UiEmpty/UiEmpty.guidance.md +66 -0
  46. package/src/components/UiEmpty/UiEmpty.stories.ts +370 -15
  47. package/src/components/UiFadeMask/UiFadeMask.stories.ts +66 -0
  48. package/src/components/UiField/UiField.guidance.md +63 -0
  49. package/src/components/UiField/UiField.stories.ts +90 -113
  50. package/src/components/UiFileType/UiFileType.stories.ts +254 -0
  51. package/src/components/UiFileUploadBox/UiFileUploadBox.stories.ts +74 -72
  52. package/src/components/UiIcon/UiIcon.stories.ts +256 -1
  53. package/src/components/UiInput/UiInput.guidance.md +64 -0
  54. package/src/components/UiInput/UiInput.stories.ts +132 -80
  55. package/src/components/UiInputGroup/UiInputGroup.guidance.md +66 -0
  56. package/src/components/UiInputGroup/UiInputGroup.stories.ts +127 -103
  57. package/src/components/UiItem/UiItem.guidance.md +66 -0
  58. package/src/components/UiItem/UiItem.stories.ts +81 -28
  59. package/src/components/UiKbd/UiKbd.guidance.md +65 -0
  60. package/src/components/UiKbd/UiKbd.stories.ts +373 -3
  61. package/src/components/UiLabel/UiLabel.guidance.md +65 -0
  62. package/src/components/UiLabel/UiLabel.stories.ts +163 -139
  63. package/src/components/UiListbox/UiListbox.stories.ts +197 -195
  64. package/src/components/UiNavigationMenu/UiNavigationMenu.guidance.md +66 -0
  65. package/src/components/UiNavigationMenu/UiNavigationMenu.stories.ts +169 -169
  66. package/src/components/UiPopover/UiPopover.guidance.md +65 -0
  67. package/src/components/UiPopover/UiPopover.stories.ts +115 -91
  68. package/src/components/UiProgress/UiProgress.guidance.md +65 -0
  69. package/src/components/UiProgress/UiProgress.stories.ts +300 -0
  70. package/src/components/UiRadioGroup/UiRadioGroup.guidance.md +66 -0
  71. package/src/components/UiRadioGroup/UiRadioGroup.stories.ts +163 -139
  72. package/src/components/UiRangeCalendar/UiRangeCalendar.stories.ts +128 -127
  73. package/src/components/UiResizable/UiResizable.guidance.md +65 -0
  74. package/src/components/UiResizable/UiResizable.stories.ts +176 -152
  75. package/src/components/UiSelect/UiSelect.guidance.md +66 -0
  76. package/src/components/UiSelect/UiSelect.stories.ts +150 -126
  77. package/src/components/UiSeparator/UiSeparator.guidance.md +64 -0
  78. package/src/components/UiSeparator/UiSeparator.stories.ts +350 -0
  79. package/src/components/UiSheet/UiSheet.guidance.md +66 -0
  80. package/src/components/UiSheet/UiSheet.stories.ts +194 -170
  81. package/src/components/UiSkeleton/UiSkeleton.guidance.md +65 -0
  82. package/src/components/UiSkeleton/UiSkeleton.stories.ts +253 -0
  83. package/src/components/UiSlider/UiSlider.guidance.md +66 -0
  84. package/src/components/UiSlider/UiSlider.stories.ts +150 -126
  85. package/src/components/UiSnackbar/UiSnackbar.guidance.md +66 -0
  86. package/src/components/UiSnackbar/UiSnackbar.stories.ts +106 -96
  87. package/src/components/UiSpinner/UiSpinner.guidance.md +65 -0
  88. package/src/components/UiSpinner/UiSpinner.stories.ts +249 -0
  89. package/src/components/UiStepper/UiStepper.guidance.md +66 -0
  90. package/src/components/UiStepper/UiStepper.stories.ts +142 -124
  91. package/src/components/UiSwitch/UiSwitch.guidance.md +66 -0
  92. package/src/components/UiSwitch/UiSwitch.stories.ts +170 -146
  93. package/src/components/UiTable/UiTable.guidance.md +66 -0
  94. package/src/components/UiTable/UiTable.stories.ts +530 -12
  95. package/src/components/UiTabs/UiTabs.guidance.md +66 -0
  96. package/src/components/UiTabs/UiTabs.stories.ts +174 -150
  97. package/src/components/UiTagsInput/UiTagsInput.stories.ts +154 -152
  98. package/src/components/UiTextarea/UiTextarea.guidance.md +66 -0
  99. package/src/components/UiTextarea/UiTextarea.stories.ts +86 -62
  100. package/src/components/UiToggle/UiToggle.guidance.md +66 -0
  101. package/src/components/UiToggle/UiToggle.stories.ts +183 -159
  102. package/src/components/UiToggleGroup/UiToggleGroup.guidance.md +64 -0
  103. package/src/components/UiToggleGroup/UiToggleGroup.stories.ts +222 -200
  104. package/src/components/UiTooltip/UiTooltip.guidance.md +66 -0
  105. package/src/components/UiTooltip/UiTooltip.stories.ts +90 -66
  106. package/src/patterns/UiDataTable/UiDataTable.guidance.md +66 -0
  107. package/src/patterns/UiDataTable/UiDataTable.stories.ts +177 -155
  108. package/src/patterns/UiDatePicker/UiDatePicker.guidance.md +66 -0
  109. package/src/patterns/UiDatePicker/UiDatePicker.stories.ts +136 -112
  110. package/src/patterns/UiFileUpload/UiFileItem.stories.ts +77 -75
  111. package/src/patterns/UiFileUpload/UiFileUpload.guidance.md +68 -0
  112. package/src/patterns/UiFileUpload/UiFileUpload.stories.ts +169 -145
  113. package/src/patterns/UiFloatActions/UiFloatActions.stories.ts +103 -101
  114. package/src/patterns/UiLayout/UiLayoutContent.stories.ts +14 -13
  115. package/src/patterns/UiLayout/UiLayoutMobile.stories.ts +65 -65
  116. package/src/patterns/UiPlaceholder/types.ts +1 -0
  117. package/src/patterns/UiProfileCard/UiProfileCard.stories.ts +74 -72
  118. package/src/patterns/UiTopBar/UiTopBar.stories.ts +84 -82
@@ -1,4 +1,5 @@
1
1
  import type { Meta, StoryObj } from '@storybook/vue3-vite';
2
+ import { expect, fn, userEvent, waitFor, within } from 'storybook/test';
2
3
  import {
3
4
  UiTable,
4
5
  UiTableHeader,
@@ -20,6 +21,16 @@ import {
20
21
  } from '../UiDropdownMenu';
21
22
  import { UiButton } from '../UiButton';
22
23
  import { UiIcon } from '../UiIcon';
24
+ import { MoreHorizontalIcon } from '@/icons/lucide';
25
+ import {
26
+ accessibilityStory,
27
+ designNotesStory,
28
+ guidanceLinks,
29
+ parseGuidance,
30
+ } from '../../../.storybook/guidance';
31
+ import guidanceMarkdown from './UiTable.guidance.md?raw';
32
+
33
+ const guidance = parseGuidance(guidanceMarkdown);
23
34
 
24
35
  /**
25
36
  * The UiTable primitives are low-level components used to build accessible and styled tables.
@@ -33,6 +44,7 @@ const meta = {
33
44
  tags: ['autodocs'],
34
45
  parameters: {
35
46
  docs: {
47
+ links: guidanceLinks(guidance),
36
48
  description: {
37
49
  component:
38
50
  'The `UiTable` primitives are low-level components used to build accessible and styled tables. They correspond directly to standard HTML table elements (`table`, `thead`, `tbody`, `tr`, `td`, `th`, `caption`) but come with pre-configured styles. Use these when you need full control over the table layout or for static content. For complex data-driven tables with sorting and pagination, use `UiDataTable`.',
@@ -45,6 +57,8 @@ const meta = {
45
57
  export default meta;
46
58
  type Story = StoryObj<typeof meta>;
47
59
 
60
+ const onCopyPaymentId = fn();
61
+
48
62
  const invoices = [
49
63
  {
50
64
  invoice: 'INV001',
@@ -130,7 +144,7 @@ const invoices = [
130
144
  </UiTableBody>
131
145
  <UiTableFooter>
132
146
  <UiTableRow>
133
- <UiTableCell colspan="3">Total</UiTableCell>
147
+ <UiTableCell :colspan="3">Total</UiTableCell>
134
148
  <UiTableCell class="text-right">€2,500.00</UiTableCell>
135
149
  </UiTableRow>
136
150
  </UiTableFooter>
@@ -158,7 +172,7 @@ const basicTemplate = `
158
172
  </UiTableBody>
159
173
  <UiTableFooter>
160
174
  <UiTableRow>
161
- <UiTableCell colspan="3">Total</UiTableCell>
175
+ <UiTableCell :colspan="3">Total</UiTableCell>
162
176
  <UiTableCell class="text-right">€2,500.00</UiTableCell>
163
177
  </UiTableRow>
164
178
  </UiTableFooter>
@@ -196,6 +210,85 @@ export const Basic: Story = {
196
210
  },
197
211
  template: basicTemplate,
198
212
  }),
213
+ play: async ({ canvasElement, step }) => {
214
+ // Scenario (UiTable): the primitives render a real data table, named by
215
+ // its caption, with one column header per column.
216
+ const canvas = within(canvasElement);
217
+ const table = canvas.getByRole('table', {
218
+ name: 'A list of your recent invoices.',
219
+ });
220
+
221
+ await step('interaction: the caption names the table', async () => {
222
+ await expect(table).toBeVisible();
223
+ });
224
+
225
+ await step(
226
+ 'interaction: header cells are column headers scoped to their column',
227
+ async () => {
228
+ const headers = within(table).getAllByRole('columnheader');
229
+ await expect(
230
+ headers.map((header) => header.textContent?.trim()),
231
+ ).toEqual(['Invoice', 'Status', 'Method', 'Amount']);
232
+ for (const header of headers) {
233
+ await expect(header).toHaveAttribute('scope', 'col');
234
+ }
235
+ },
236
+ );
237
+
238
+ await step(
239
+ 'interaction: renders a header row, one row per invoice, and a footer row',
240
+ async () => {
241
+ await expect(within(table).getAllByRole('row')).toHaveLength(
242
+ invoices.length + 2,
243
+ );
244
+ },
245
+ );
246
+ },
247
+ };
248
+
249
+ /**
250
+ * Usage, guidelines, and do's and don'ts from the Figma documentation.
251
+ */
252
+ export const DesignNotes: Story = {
253
+ ...designNotesStory(guidance),
254
+ tags: ['!autodocs'],
255
+ };
256
+
257
+ /**
258
+ * Accessibility guidance from the Figma documentation, with the component in
259
+ * the default and accessible themes.
260
+ */
261
+ export const Accessibility: Story = {
262
+ ...accessibilityStory({
263
+ requirements: guidance.accessibility,
264
+ example: {
265
+ components: {
266
+ UiTable,
267
+ UiTableBody,
268
+ UiTableCell,
269
+ UiTableHead,
270
+ UiTableHeader,
271
+ UiTableRow,
272
+ },
273
+ template: `
274
+ <UiTable>
275
+ <UiTableHeader>
276
+ <UiTableRow>
277
+ <UiTableHead>Invoice</UiTableHead>
278
+ <UiTableHead>Status</UiTableHead>
279
+ </UiTableRow>
280
+ </UiTableHeader>
281
+ <UiTableBody>
282
+ <UiTableRow>
283
+ <UiTableCell>INV001</UiTableCell>
284
+ <UiTableCell>Paid</UiTableCell>
285
+ </UiTableRow>
286
+ </UiTableBody>
287
+ </UiTable>
288
+ `,
289
+ },
290
+ }),
291
+ tags: ['!autodocs'],
199
292
  };
200
293
 
201
294
  const withRowActionsTemplateSource = `<script setup lang="ts">
@@ -246,7 +339,7 @@ const invoices = [
246
339
  <UiDropdownMenu>
247
340
  <UiDropdownMenuTrigger as-child>
248
341
  <UiButton variant="ghost" size="icon" class="h-8 w-8 p-0">
249
- <span class="sr-only">Open menu</span>
342
+ <span class="sr-only">Open menu for {{ invoice.invoice }}</span>
250
343
  <UiIcon :name="MoreHorizontalIcon" :size="16" />
251
344
  </UiButton>
252
345
  </UiDropdownMenuTrigger>
@@ -287,13 +380,13 @@ const withRowActionsTemplate = `
287
380
  <UiDropdownMenu>
288
381
  <UiDropdownMenuTrigger as-child>
289
382
  <UiButton variant="ghost" size="icon" class="h-8 w-8 p-0">
290
- <span class="sr-only">Open menu</span>
383
+ <span class="sr-only">Open menu for {{ invoice.invoice }}</span>
291
384
  <UiIcon :name="MoreHorizontalIcon" :size="16" />
292
385
  </UiButton>
293
386
  </UiDropdownMenuTrigger>
294
387
  <UiDropdownMenuContent align="end">
295
388
  <UiDropdownMenuLabel>Actions</UiDropdownMenuLabel>
296
- <UiDropdownMenuItem @click="() => {}">Copy payment ID</UiDropdownMenuItem>
389
+ <UiDropdownMenuItem @click="onCopyPaymentId(invoice.invoice)">Copy payment ID</UiDropdownMenuItem>
297
390
  <UiDropdownMenuSeparator />
298
391
  <UiDropdownMenuItem>View customer</UiDropdownMenuItem>
299
392
  <UiDropdownMenuItem>View payment details</UiDropdownMenuItem>
@@ -338,10 +431,57 @@ export const WithRowActions: Story = {
338
431
  UiIcon,
339
432
  },
340
433
  setup() {
341
- return { invoices };
434
+ return { invoices, MoreHorizontalIcon, onCopyPaymentId };
342
435
  },
343
436
  template: withRowActionsTemplate,
344
437
  }),
438
+ play: async ({ canvasElement, step }) => {
439
+ // Scenario (UiTable): each row has its own named actions menu; choosing an
440
+ // action runs it for that row and closes the menu.
441
+ onCopyPaymentId.mockClear();
442
+ const canvas = within(canvasElement);
443
+ const body = within(document.body);
444
+ const trigger = canvas.getByRole('button', {
445
+ name: 'Open menu for INV002',
446
+ });
447
+
448
+ await step(
449
+ 'interaction: every row trigger has a distinct name (WCAG 2.4.6)',
450
+ async () => {
451
+ for (const { invoice } of invoices) {
452
+ await expect(
453
+ canvas.getByRole('button', { name: `Open menu for ${invoice}` }),
454
+ ).toHaveAttribute('aria-haspopup', 'menu');
455
+ }
456
+ },
457
+ );
458
+
459
+ await step(
460
+ 'interaction: clicking a row trigger opens its menu',
461
+ async () => {
462
+ await userEvent.click(trigger);
463
+ const menu = await body.findByRole('menu');
464
+ await waitFor(async () => {
465
+ await expect(menu).toBeVisible();
466
+ });
467
+ await expect(trigger).toHaveAttribute('aria-expanded', 'true');
468
+ },
469
+ );
470
+
471
+ await step(
472
+ 'interaction: choosing an action runs it for that row and closes the menu',
473
+ async () => {
474
+ await userEvent.click(
475
+ body.getByRole('menuitem', { name: 'Copy payment ID' }),
476
+ );
477
+ await expect(onCopyPaymentId).toHaveBeenCalledWith('INV002');
478
+ await waitFor(async () => {
479
+ await expect(body.queryByRole('menu')).not.toBeInTheDocument();
480
+ });
481
+ await expect(trigger).toHaveAttribute('aria-expanded', 'false');
482
+ },
483
+ );
484
+ },
345
485
  };
346
486
 
347
487
  const emptyStateTemplateSource = `<script setup lang="ts">
@@ -430,8 +570,8 @@ import {
430
570
  <UiTable>
431
571
  <UiTableHeader>
432
572
  <UiTableRow>
433
- <UiTableHead colspan="2">Product Info</UiTableHead>
434
- <UiTableHead colspan="2">Pricing</UiTableHead>
573
+ <UiTableHead :colspan="2" scope="colgroup">Product Info</UiTableHead>
574
+ <UiTableHead :colspan="2" scope="colgroup">Pricing</UiTableHead>
435
575
  </UiTableRow>
436
576
  <UiTableRow>
437
577
  <UiTableHead>Name</UiTableHead>
@@ -461,8 +601,8 @@ const colSpanTemplate = `
461
601
  <UiTable>
462
602
  <UiTableHeader>
463
603
  <UiTableRow>
464
- <UiTableHead colspan="2">Product Info</UiTableHead>
465
- <UiTableHead colspan="2">Pricing</UiTableHead>
604
+ <UiTableHead :colspan="2" scope="colgroup">Product Info</UiTableHead>
605
+ <UiTableHead :colspan="2" scope="colgroup">Pricing</UiTableHead>
466
606
  </UiTableRow>
467
607
  <UiTableRow>
468
608
  <UiTableHead>Name</UiTableHead>
@@ -489,14 +629,14 @@ const colSpanTemplate = `
489
629
  `;
490
630
 
491
631
  /**
492
- * Use the colspan attribute on UiTableHead or UiTableCell to create grouped headers.
632
+ * Use the colspan prop on UiTableHead or UiTableCell to create grouped headers.
493
633
  */
494
634
  export const WithColSpan: Story = {
495
635
  parameters: {
496
636
  docs: {
497
637
  description: {
498
638
  story:
499
- 'Use the `colspan` attribute on `UiTableHead` or `UiTableCell` to create grouped headers or cells that span multiple columns.',
639
+ 'Use the `colspan` prop on `UiTableHead` or `UiTableCell` to create grouped headers or cells that span multiple columns. Set `scope="colgroup"` on a header that spans columns so screen readers announce it for every column in the group.',
500
640
  },
501
641
  source: {
502
642
  code: colSpanTemplateSource,
@@ -514,4 +654,382 @@ export const WithColSpan: Story = {
514
654
  },
515
655
  template: colSpanTemplate,
516
656
  }),
657
+ play: async ({ canvasElement, step }) => {
658
+ // Scenario (UiTable): grouped headers span their columns and are scoped to
659
+ // the column group, so each cell is announced with both of its headers.
660
+ const canvas = within(canvasElement);
661
+
662
+ await step('interaction: group headers span two columns each', async () => {
663
+ for (const name of ['Product Info', 'Pricing']) {
664
+ const header = canvas.getByRole('columnheader', { name });
665
+ await expect(header).toHaveAttribute('colspan', '2');
666
+ await expect(header).toHaveAttribute('scope', 'colgroup');
667
+ }
668
+ });
669
+
670
+ await step(
671
+ 'interaction: leaf headers stay scoped to one column',
672
+ async () => {
673
+ for (const name of ['Name', 'Category', 'Price', 'Discount']) {
674
+ await expect(
675
+ canvas.getByRole('columnheader', { name }),
676
+ ).toHaveAttribute('scope', 'col');
677
+ }
678
+ },
679
+ );
680
+ },
681
+ };
682
+
683
+ const testTableTemplate = withRowActionsTemplate.replace(
684
+ '<UiTable>',
685
+ '<UiTable>\n <UiTableCaption>Recent invoices</UiTableCaption>',
686
+ );
687
+
688
+ const renderTestTable = () => ({
689
+ components: {
690
+ UiButton,
691
+ UiDropdownMenu,
692
+ UiDropdownMenuContent,
693
+ UiDropdownMenuItem,
694
+ UiDropdownMenuLabel,
695
+ UiDropdownMenuSeparator,
696
+ UiDropdownMenuTrigger,
697
+ UiIcon,
698
+ UiTable,
699
+ UiTableBody,
700
+ UiTableCaption,
701
+ UiTableCell,
702
+ UiTableHead,
703
+ UiTableHeader,
704
+ UiTableRow,
705
+ },
706
+ setup() {
707
+ return {
708
+ invoices: invoices.slice(0, 2),
709
+ MoreHorizontalIcon,
710
+ onCopyPaymentId,
711
+ };
712
+ },
713
+ template: testTableTemplate,
714
+ });
715
+
716
+ const openRowMenu = async (trigger: HTMLElement) => {
717
+ await userEvent.click(trigger);
718
+ const menu = await within(document.body).findByRole('menu');
719
+ await waitFor(async () => {
720
+ await expect(menu).toBeVisible();
721
+ });
722
+ return menu;
723
+ };
724
+
725
+ // The open menu marks the story root aria-hidden; wait until it is gone so the
726
+ // post-play axe audit doesn't see a hidden root with focusable rows.
727
+ const waitForMenuClosed = async (canvasElement: HTMLElement) => {
728
+ await waitFor(async () => {
729
+ await expect(
730
+ within(document.body).queryByRole('menu'),
731
+ ).not.toBeInTheDocument();
732
+ await expect(canvasElement.closest('[aria-hidden="true"]')).toBeNull();
733
+ });
734
+ };
735
+
736
+ /**
737
+ * Focus moves through the row actions in reading order, skipping the cells;
738
+ * each menu opens from the keyboard and Escape returns focus to its trigger
739
+ * (WCAG 2.1.1, 2.4.3). Hidden test-only story.
740
+ */
741
+ export const KeyboardNavigation: Story = {
742
+ name: 'test - Keyboard Navigation',
743
+ tags: ['!dev', '!autodocs'],
744
+ parameters: {
745
+ // Focus moves during the play function.
746
+ chromatic: { disableSnapshot: true },
747
+ docs: {
748
+ description: {
749
+ story:
750
+ 'Press `Tab` to move between the row menus, `Enter` to open one, and `Escape` to close it.',
751
+ },
752
+ },
753
+ },
754
+ render: renderTestTable,
755
+ play: async ({ canvasElement, step }) => {
756
+ // Scenario (UiTable): a keyboard user tabs row by row through the action
757
+ // menus, opens one, and closes it again without losing their place.
758
+ const canvas = within(canvasElement);
759
+ const body = within(document.body);
760
+ const first = canvas.getByRole('button', { name: 'Open menu for INV001' });
761
+ const second = canvas.getByRole('button', { name: 'Open menu for INV002' });
762
+
763
+ await step(
764
+ 'keyboard: Tab skips the cells and lands on the first row action',
765
+ async () => {
766
+ await userEvent.tab();
767
+ await expect(first).toHaveFocus();
768
+ },
769
+ );
770
+
771
+ await step(
772
+ 'keyboard: Enter opens the row menu and moves focus into it',
773
+ async () => {
774
+ await userEvent.keyboard('{Enter}');
775
+ const menu = await body.findByRole('menu');
776
+ await waitFor(async () => {
777
+ await expect(menu).toBeVisible();
778
+ await expect(menu.contains(document.activeElement)).toBe(true);
779
+ });
780
+ },
781
+ );
782
+
783
+ await step(
784
+ 'keyboard: Escape closes the menu and returns focus to its trigger (WCAG 2.1.2)',
785
+ async () => {
786
+ await userEvent.keyboard('{Escape}');
787
+ await waitFor(async () => {
788
+ await expect(body.queryByRole('menu')).not.toBeInTheDocument();
789
+ });
790
+ await waitFor(async () => {
791
+ await expect(first).toHaveFocus();
792
+ });
793
+ },
794
+ );
795
+
796
+ await step(
797
+ 'keyboard: Tab follows row order to the next action, then leaves the table',
798
+ async () => {
799
+ await userEvent.tab();
800
+ await expect(second).toHaveFocus();
801
+ await userEvent.tab();
802
+ await expect(canvasElement.contains(document.activeElement)).toBe(
803
+ false,
804
+ );
805
+ },
806
+ );
807
+ },
808
+ };
809
+
810
+ /**
811
+ * What assistive technology reads: a captioned table, column headers for
812
+ * every column (including the visually hidden actions header), and a
813
+ * distinctly named menu per row (WCAG 1.3.1, 4.1.2). Hidden test-only story.
814
+ */
815
+ export const ScreenReader: Story = {
816
+ name: 'test - Screen Reader',
817
+ tags: ['!dev', '!autodocs'],
818
+ parameters: {
819
+ // A menu opens during the play function.
820
+ chromatic: { disableSnapshot: true },
821
+ docs: {
822
+ description: {
823
+ story:
824
+ 'Verifies the table name, header semantics, and row-action names that assistive technology announces.',
825
+ },
826
+ },
827
+ },
828
+ render: renderTestTable,
829
+ play: async ({ canvasElement, step }) => {
830
+ // Scenario (UiTable): a screen-reader user can find the table by name,
831
+ // hear each cell with its column header, and tell the row menus apart.
832
+ const canvas = within(canvasElement);
833
+ const body = within(document.body);
834
+ const table = canvas.getByRole('table', { name: 'Recent invoices' });
835
+
836
+ await step('screen-reader: the caption names the table', async () => {
837
+ await expect(table).toHaveAccessibleName('Recent invoices');
838
+ });
839
+
840
+ await step(
841
+ 'screen-reader: every column has a header, including the actions column',
842
+ async () => {
843
+ const headers = within(table).getAllByRole('columnheader');
844
+ await expect(headers).toHaveLength(5);
845
+ await expect(
846
+ within(table).getByRole('columnheader', { name: 'Actions' }),
847
+ ).toHaveAttribute('scope', 'col');
848
+ },
849
+ );
850
+
851
+ await step(
852
+ 'screen-reader: each body row has one cell per column header',
853
+ async () => {
854
+ const [, ...bodyRows] = within(table).getAllByRole('row');
855
+ await expect(bodyRows).toHaveLength(2);
856
+ for (const row of bodyRows) {
857
+ await expect(within(row).getAllByRole('cell')).toHaveLength(5);
858
+ }
859
+ },
860
+ );
861
+
862
+ await step(
863
+ 'screen-reader: row menus are distinctly named and report their state',
864
+ async () => {
865
+ for (const invoice of ['INV001', 'INV002']) {
866
+ const trigger = canvas.getByRole('button', {
867
+ name: `Open menu for ${invoice}`,
868
+ });
869
+ await expect(trigger).toHaveAttribute('aria-haspopup', 'menu');
870
+ await expect(trigger).toHaveAttribute('aria-expanded', 'false');
871
+ }
872
+ },
873
+ );
874
+
875
+ await step(
876
+ 'screen-reader: an open menu exposes named menu items',
877
+ async () => {
878
+ await openRowMenu(
879
+ canvas.getByRole('button', { name: 'Open menu for INV001' }),
880
+ );
881
+ for (const name of [
882
+ 'Copy payment ID',
883
+ 'View customer',
884
+ 'View payment details',
885
+ ]) {
886
+ await expect(body.getByRole('menuitem', { name })).toBeVisible();
887
+ }
888
+ await userEvent.keyboard('{Escape}');
889
+ await waitFor(async () => {
890
+ await expect(body.queryByRole('menu')).not.toBeInTheDocument();
891
+ });
892
+ },
893
+ );
894
+ },
895
+ };
896
+
897
+ /**
898
+ * Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
899
+ * try 400% reflow (WCAG 1.4.10). Hidden test-only story.
900
+ */
901
+ export const ZoomMagnification: Story = {
902
+ name: 'test - Zoom Magnification',
903
+ tags: ['!dev', '!autodocs'],
904
+ globals: { zoom: '200' },
905
+ parameters: {
906
+ // Zoom changes the layout scale; the accessible-reflow Chromatic mode
907
+ // already covers magnified snapshots, so skip this one.
908
+ chromatic: { disableSnapshot: true },
909
+ docs: {
910
+ description: {
911
+ story:
912
+ 'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
913
+ },
914
+ },
915
+ },
916
+ render: renderTestTable,
917
+ play: async ({ canvasElement, step }) => {
918
+ // Scenario (UiTable): at 200% page zoom the headers and cells stay
919
+ // readable, the table scrolls inside its own container rather than the
920
+ // page, and the row actions still work.
921
+ onCopyPaymentId.mockClear();
922
+ const canvas = within(canvasElement);
923
+ const body = within(document.body);
924
+
925
+ await step(
926
+ 'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
927
+ async () => {
928
+ await expect(document.documentElement.style.zoom).toBe('200%');
929
+ },
930
+ );
931
+
932
+ await step('zoom: headers and cells stay readable', async () => {
933
+ await expect(
934
+ canvas.getByRole('columnheader', { name: 'Invoice' }),
935
+ ).toBeVisible();
936
+ await expect(canvas.getByText('INV001')).toBeVisible();
937
+ });
938
+
939
+ await step(
940
+ 'zoom: wide content scrolls inside the table, not the page',
941
+ async () => {
942
+ const { scrollWidth, clientWidth } = document.documentElement;
943
+ await expect(scrollWidth).toBeLessThanOrEqual(clientWidth + 1);
944
+ },
945
+ );
946
+
947
+ await step('zoom: row actions remain operable when magnified', async () => {
948
+ await openRowMenu(
949
+ canvas.getByRole('button', { name: 'Open menu for INV001' }),
950
+ );
951
+ await userEvent.click(
952
+ body.getByRole('menuitem', { name: 'Copy payment ID' }),
953
+ );
954
+ await expect(onCopyPaymentId).toHaveBeenCalledWith('INV001');
955
+ await waitForMenuClosed(canvasElement);
956
+ });
957
+ },
958
+ };
959
+
960
+ /**
961
+ * Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
962
+ * toolbar. Data tables are exempt from single-column reflow (WCAG 1.4.10),
963
+ * so the table scrolls inside its container. Hidden test-only story.
964
+ */
965
+ export const MobileBreakpoint: Story = {
966
+ name: 'test - Mobile Breakpoint',
967
+ tags: ['!dev', '!autodocs'],
968
+ globals: { mediaBreakpoint: 'reflow' },
969
+ parameters: {
970
+ // Reflow snapshots are already covered by the accessible-reflow mode.
971
+ chromatic: { disableSnapshot: true },
972
+ docs: {
973
+ description: {
974
+ story:
975
+ 'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
976
+ },
977
+ },
978
+ },
979
+ render: renderTestTable,
980
+ play: async ({ canvasElement, step }) => {
981
+ // Scenario (UiTable): at the 320px mobile breakpoint the table container
982
+ // fits the viewport and scrolls the columns, and the row menus are big
983
+ // enough to tap.
984
+ onCopyPaymentId.mockClear();
985
+ const canvas = within(canvasElement);
986
+ const body = within(document.body);
987
+
988
+ await step(
989
+ 'mobile: the table renders at the 320px breakpoint',
990
+ async () => {
991
+ await expect(
992
+ canvas.getByRole('table', { name: 'Recent invoices' }),
993
+ ).toBeInTheDocument();
994
+ await expect(canvas.getByText('INV002')).toBeVisible();
995
+ },
996
+ );
997
+
998
+ await step(
999
+ 'mobile: the table scroller stays inside the viewport (WCAG 1.4.10 Reflow)',
1000
+ async () => {
1001
+ // The table itself may be wider than 320px; its container is the
1002
+ // element that has to fit, and it scrolls the columns sideways.
1003
+ const container = canvasElement.querySelector(
1004
+ '[data-slot="table-container"]',
1005
+ );
1006
+ if (!container) throw new Error('UiTable rendered no container');
1007
+ const { left, right } = container.getBoundingClientRect();
1008
+ await expect(left).toBeGreaterThanOrEqual(0);
1009
+ await expect(right).toBeLessThanOrEqual(window.innerWidth + 1);
1010
+ },
1011
+ );
1012
+
1013
+ await step(
1014
+ 'mobile: row actions meet the minimum target size (WCAG 2.5.8)',
1015
+ async () => {
1016
+ for (const trigger of canvas.getAllByRole('button')) {
1017
+ const { width, height } = trigger.getBoundingClientRect();
1018
+ await expect(width).toBeGreaterThanOrEqual(24);
1019
+ await expect(height).toBeGreaterThanOrEqual(24);
1020
+ }
1021
+ },
1022
+ );
1023
+
1024
+ await step('mobile: a row action works by tap', async () => {
1025
+ await openRowMenu(
1026
+ canvas.getByRole('button', { name: 'Open menu for INV002' }),
1027
+ );
1028
+ await userEvent.click(
1029
+ body.getByRole('menuitem', { name: 'Copy payment ID' }),
1030
+ );
1031
+ await expect(onCopyPaymentId).toHaveBeenCalledWith('INV002');
1032
+ await waitForMenuClosed(canvasElement);
1033
+ });
1034
+ },
517
1035
  };