@aleph-alpha/ui-library 6.3.2 → 6.3.4

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 (51) hide show
  1. package/config.js +2 -0
  2. package/dist/system/components/UiFileUploadBox/types.d.ts +8 -5
  3. package/dist/system/components/UiStepper/context.d.ts +8 -0
  4. package/dist/system/components/core/range-calendar/RangeCalendar.vue.d.ts +24 -24
  5. package/dist/system/icons/story-sidebar-icons.json +7 -0
  6. package/dist/system/lib.js +14776 -14598
  7. package/dist/system/patterns/UiLayout/layout-shell.d.ts +217 -5
  8. package/dist/system/patterns/UiTopBar/accessory-dropdown.d.ts +227 -0
  9. package/dist/system/story-sidebar-icons.json +7 -0
  10. package/package.json +1 -1
  11. package/src/components/UiAccordion/UiAccordion.stories.ts +1079 -0
  12. package/src/components/UiCalendar/UiCalendar.stories.ts +734 -0
  13. package/src/components/UiCalendar/__tests__/UiCalendar.test.ts +8 -5
  14. package/src/components/UiDropdownMenu/UiDropdownMenuTrigger.vue +3 -1
  15. package/src/components/UiFileUploadBox/UiFileUploadBox.stories.ts +389 -3
  16. package/src/components/UiFileUploadBox/UiFileUploadBox.vue +55 -75
  17. package/src/components/UiFileUploadBox/__tests__/UiFileUploadBox.test.ts +44 -0
  18. package/src/components/UiFileUploadBox/types.ts +8 -5
  19. package/src/components/UiNavigationMenu/UiNavigationMenu.stories.ts +723 -0
  20. package/src/components/UiRangeCalendar/UiRangeCalendar.stories.ts +819 -7
  21. package/src/components/UiRangeCalendar/__tests__/UiRangeCalendar.test.ts +8 -3
  22. package/src/components/UiResizable/UiResizable.stories.ts +1215 -5
  23. package/src/components/UiSnackbar/UiSnackbar.stories.ts +1017 -4
  24. package/src/components/UiSnackbar/UiSnackbar.vue +3 -2
  25. package/src/components/UiSnackbar/UiSnackbarContent.vue +1 -1
  26. package/src/components/UiSnackbar/__tests__/UiSnackbar.test.ts +3 -1
  27. package/src/components/UiStepper/UiStepper.stories.ts +566 -2
  28. package/src/components/UiStepper/UiStepper.vue +14 -1
  29. package/src/components/UiStepper/UiStepperItem.vue +22 -4
  30. package/src/components/UiStepper/__tests__/UiStepper.test.ts +66 -0
  31. package/src/components/UiStepper/context.ts +10 -0
  32. package/src/components/core/calendar/Calendar.vue +234 -2
  33. package/src/components/core/calendar/CalendarCellTrigger.vue +1 -1
  34. package/src/components/core/navigation-menu/NavigationMenuList.vue +1 -1
  35. package/src/components/core/range-calendar/RangeCalendar.vue +254 -6
  36. package/src/components/core/range-calendar/RangeCalendarCellTrigger.vue +1 -1
  37. package/src/patterns/UiDatePicker/UiDatePicker.stories.ts +846 -17
  38. package/src/patterns/UiDatePicker/UiDatePicker.vue +9 -0
  39. package/src/patterns/UiDatePicker/__tests__/UiDatePicker.test.ts +13 -8
  40. package/src/patterns/UiFileUpload/UiFileItem.stories.ts +23 -17
  41. package/src/patterns/UiFileUpload/UiFileUpload.stories.ts +138 -113
  42. package/src/patterns/UiFileUpload/UiFileUpload.vue +1 -1
  43. package/src/patterns/UiFileUpload/__tests__/UiFileUpload.test.ts +2 -2
  44. package/src/patterns/UiLayout/UiLayout.stories.ts +25 -0
  45. package/src/patterns/UiLayout/UiLayoutContent.stories.ts +359 -0
  46. package/src/patterns/UiLayout/UiLayoutContent.vue +45 -23
  47. package/src/patterns/UiLayout/UiLayoutMobile.stories.ts +13 -0
  48. package/src/patterns/UiLayout/layout-shell.ts +159 -13
  49. package/src/patterns/UiTopBar/UiTopBar.stories.ts +245 -36
  50. package/src/patterns/UiTopBar/UiTopBar.vue +4 -2
  51. package/src/patterns/UiTopBar/accessory-dropdown.ts +97 -0
@@ -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 { ref, watch } from 'vue';
3
4
  import {
4
5
  UiAccordion,
@@ -52,6 +53,11 @@ export default meta;
52
53
 
53
54
  type Story = StoryObj<typeof UiAccordion>;
54
55
 
56
+ // `UiAccordion` emits `update:modelValue` when the expanded item(s) change.
57
+ // Play functions bind this module-level spy via `@update:model-value` and
58
+ // `mockClear()` it at the start of each `play`.
59
+ const onUpdate = fn();
60
+
55
61
  const defaultTemplateSource = `<script setup lang="ts">
56
62
  import {
57
63
  UiAccordion,
@@ -193,6 +199,46 @@ export const Default: Story = {
193
199
  },
194
200
  },
195
201
  },
202
+ play: async ({ canvasElement, step }) => {
203
+ // Scenario (UiAccordion): the resting accordion with its first section
204
+ // expanded — the default-open panel keeps the expanded DOM in the axe
205
+ // audit, and assistive tech reads named triggers whose aria-expanded
206
+ // mirrors the state. Non-mutating so the primary snapshot stays stable.
207
+ const canvas = within(canvasElement);
208
+ const product = canvas.getByRole('button', { name: 'Product Information' });
209
+ const shipping = canvas.getByRole('button', { name: 'Shipping Details' });
210
+ const returns = canvas.getByRole('button', { name: 'Return Policy' });
211
+
212
+ await step(
213
+ 'screen-reader: every trigger exposes a button role named by its label (WCAG 4.1.2)',
214
+ async () => {
215
+ await expect(product).toHaveAccessibleName('Product Information');
216
+ await expect(shipping).toHaveAccessibleName('Shipping Details');
217
+ await expect(returns).toHaveAccessibleName('Return Policy');
218
+ },
219
+ );
220
+
221
+ await step(
222
+ 'screen-reader: aria-expanded reflects the expanded/collapsed state (WCAG 4.1.2)',
223
+ async () => {
224
+ await expect(product).toHaveAttribute('aria-expanded', 'true');
225
+ await expect(shipping).toHaveAttribute('aria-expanded', 'false');
226
+ await expect(returns).toHaveAttribute('aria-expanded', 'false');
227
+ },
228
+ );
229
+
230
+ await step(
231
+ 'interaction: only the expanded panel is rendered, as a region labelled by its trigger',
232
+ async () => {
233
+ const regions = canvas.getAllByRole('region');
234
+ await expect(regions).toHaveLength(1);
235
+ await expect(regions[0]).toHaveAccessibleName('Product Information');
236
+ await expect(regions[0]).toHaveTextContent(
237
+ 'Our flagship product combines cutting-edge technology',
238
+ );
239
+ },
240
+ );
241
+ },
196
242
  };
197
243
 
198
244
  const multipleTemplateSource = `<script setup lang="ts">
@@ -275,6 +321,49 @@ export const Multiple: Story = {
275
321
  },
276
322
  },
277
323
  },
324
+ play: async ({ canvasElement, step }) => {
325
+ // Scenario (UiAccordion): in multiple mode several sections stay expanded
326
+ // at once, and toggling one section leaves the others untouched. The third
327
+ // section is collapsed again at the end so the snapshot stays stable.
328
+ const canvas = within(canvasElement);
329
+ const first = canvas.getByRole('button', { name: 'First Section' });
330
+ const second = canvas.getByRole('button', { name: 'Second Section' });
331
+ const third = canvas.getByRole('button', { name: 'Third Section' });
332
+
333
+ await step(
334
+ 'interaction: multiple sections stay expanded simultaneously',
335
+ async () => {
336
+ await expect(first).toHaveAttribute('aria-expanded', 'true');
337
+ await expect(second).toHaveAttribute('aria-expanded', 'true');
338
+ await expect(canvas.getAllByRole('region')).toHaveLength(2);
339
+ },
340
+ );
341
+
342
+ await step(
343
+ 'interaction: expanding another section keeps the others open',
344
+ async () => {
345
+ await userEvent.click(third);
346
+ await expect(third).toHaveAttribute('aria-expanded', 'true');
347
+ await expect(first).toHaveAttribute('aria-expanded', 'true');
348
+ await expect(second).toHaveAttribute('aria-expanded', 'true');
349
+ await waitFor(async () => {
350
+ await expect(canvas.getAllByRole('region')).toHaveLength(3);
351
+ });
352
+ },
353
+ );
354
+
355
+ await step(
356
+ 'interaction: collapsing a section hides only its own content',
357
+ async () => {
358
+ await userEvent.click(third);
359
+ await expect(third).toHaveAttribute('aria-expanded', 'false');
360
+ await expect(first).toHaveAttribute('aria-expanded', 'true');
361
+ await waitFor(async () => {
362
+ await expect(canvas.getAllByRole('region')).toHaveLength(2);
363
+ });
364
+ },
365
+ );
366
+ },
278
367
  };
279
368
 
280
369
  const nonCollapsibleTemplateSource = `<script setup lang="ts">
@@ -339,6 +428,149 @@ export const NonCollapsible: Story = {
339
428
  },
340
429
  },
341
430
  },
431
+ play: async ({ canvasElement, step }) => {
432
+ // Scenario (UiAccordion): with collapsible=false one section is always
433
+ // open — clicking the open trigger is a no-op. Ends back on the first
434
+ // section so the snapshot stays stable.
435
+ const canvas = within(canvasElement);
436
+ const alwaysOpen = canvas.getByRole('button', { name: 'Always One Open' });
437
+ const switchTo = canvas.getByRole('button', { name: 'Click to Switch' });
438
+
439
+ await step(
440
+ 'interaction: the open section cannot be collapsed when collapsible is false',
441
+ async () => {
442
+ await expect(alwaysOpen).toHaveAttribute('aria-expanded', 'true');
443
+ await userEvent.click(alwaysOpen);
444
+ await expect(alwaysOpen).toHaveAttribute('aria-expanded', 'true');
445
+ await expect(canvas.getByRole('region')).toBeVisible();
446
+ },
447
+ );
448
+
449
+ await step(
450
+ 'interaction: selecting another section switches which one is open',
451
+ async () => {
452
+ await userEvent.click(switchTo);
453
+ await expect(switchTo).toHaveAttribute('aria-expanded', 'true');
454
+ await expect(alwaysOpen).toHaveAttribute('aria-expanded', 'false');
455
+ // Restore the initial state for the visual snapshot.
456
+ await userEvent.click(alwaysOpen);
457
+ await expect(alwaysOpen).toHaveAttribute('aria-expanded', 'true');
458
+ },
459
+ );
460
+ },
461
+ };
462
+
463
+ const disabledTemplateSource = `<script setup lang="ts">
464
+ import {
465
+ UiAccordion,
466
+ UiAccordionItem,
467
+ UiAccordionTrigger,
468
+ UiAccordionContent,
469
+ } from '@aleph-alpha/ui-library'
470
+ </script>
471
+
472
+ <template>
473
+ <UiAccordion disabled type="single" collapsible default-value="item-1" class="w-full">
474
+ <UiAccordionItem value="item-1">
475
+ <UiAccordionTrigger>Item 1</UiAccordionTrigger>
476
+ <UiAccordionContent>
477
+ <p>This section stays expanded, but the whole accordion is disabled.</p>
478
+ </UiAccordionContent>
479
+ </UiAccordionItem>
480
+ <UiAccordionItem value="item-2">
481
+ <UiAccordionTrigger>Item 2</UiAccordionTrigger>
482
+ <UiAccordionContent>
483
+ <p>This content cannot be reached while the accordion is disabled.</p>
484
+ </UiAccordionContent>
485
+ </UiAccordionItem>
486
+ </UiAccordion>
487
+ </template>`;
488
+
489
+ /**
490
+ * Disable the whole accordion via the root `disabled` prop. Already expanded
491
+ * content stays visible, but no trigger can be operated — every item reports
492
+ * its disabled state. To disable a single section instead, see
493
+ * WithDisabledItem.
494
+ */
495
+ export const Disabled: Story = {
496
+ render: () => ({
497
+ components: {
498
+ UiAccordion,
499
+ UiAccordionItem,
500
+ UiAccordionTrigger,
501
+ UiAccordionContent,
502
+ },
503
+ template: `
504
+ <UiAccordion disabled type="single" collapsible default-value="item-1" class="w-full">
505
+ <UiAccordionItem value="item-1">
506
+ <UiAccordionTrigger>Item 1</UiAccordionTrigger>
507
+ <UiAccordionContent>
508
+ <p>This section stays expanded, but the whole accordion is disabled.</p>
509
+ </UiAccordionContent>
510
+ </UiAccordionItem>
511
+ <UiAccordionItem value="item-2">
512
+ <UiAccordionTrigger>Item 2</UiAccordionTrigger>
513
+ <UiAccordionContent>
514
+ <p>This content cannot be reached while the accordion is disabled.</p>
515
+ </UiAccordionContent>
516
+ </UiAccordionItem>
517
+ </UiAccordion>
518
+ `,
519
+ }),
520
+ parameters: {
521
+ docs: {
522
+ source: {
523
+ code: disabledTemplateSource,
524
+ },
525
+ },
526
+ },
527
+ play: async ({ canvasElement, step }) => {
528
+ // Scenario (UiAccordion): with the root `disabled` prop set, every item is
529
+ // inert — the expanded section stays visible but cannot be collapsed, and
530
+ // closed sections cannot be opened, even by forced clicks.
531
+ const canvas = within(canvasElement);
532
+ const openTrigger = canvas.getByRole('button', { name: 'Item 1' });
533
+ const closedTrigger = canvas.getByRole('button', { name: 'Item 2' });
534
+
535
+ await step(
536
+ 'interaction: every item exposes its disabled state (WCAG 4.1.2)',
537
+ async () => {
538
+ await expect(openTrigger).toBeDisabled();
539
+ await expect(openTrigger).toHaveAttribute('aria-disabled', 'true');
540
+ await expect(closedTrigger).toBeDisabled();
541
+ await expect(closedTrigger).toHaveAttribute('aria-disabled', 'true');
542
+ },
543
+ );
544
+
545
+ await step(
546
+ 'interaction: the expanded section stays visible but cannot be collapsed',
547
+ async () => {
548
+ await expect(openTrigger).toHaveAttribute('aria-expanded', 'true');
549
+ await expect(
550
+ canvas.getByRole('region', { name: 'Item 1' }),
551
+ ).toBeVisible();
552
+
553
+ // The disabled trigger renders with pointer-events: none, so bypass
554
+ // the pointer-events check to prove the guard itself blocks toggling.
555
+ await userEvent.click(openTrigger, { pointerEventsCheck: 0 });
556
+ await expect(openTrigger).toHaveAttribute('aria-expanded', 'true');
557
+ await expect(
558
+ canvas.getByRole('region', { name: 'Item 1' }),
559
+ ).toBeVisible();
560
+ },
561
+ );
562
+
563
+ await step(
564
+ 'interaction: a closed section does not open, even on forced clicks',
565
+ async () => {
566
+ await userEvent.click(closedTrigger, { pointerEventsCheck: 0 });
567
+ await expect(closedTrigger).toHaveAttribute('aria-expanded', 'false');
568
+ await expect(
569
+ canvas.queryByRole('region', { name: 'Item 2' }),
570
+ ).not.toBeInTheDocument();
571
+ },
572
+ );
573
+ },
342
574
  };
343
575
 
344
576
  const withDisabledItemTemplateSource = `<script setup lang="ts">
@@ -414,6 +646,187 @@ export const WithDisabledItem: Story = {
414
646
  },
415
647
  },
416
648
  },
649
+ play: async ({ canvasElement, step }) => {
650
+ // Scenario (UiAccordion): a disabled item stays visible but inert — it
651
+ // reports its disabled state and even forced clicks do not expand it.
652
+ const canvas = within(canvasElement);
653
+ const disabledTrigger = canvas.getByRole('button', {
654
+ name: 'Disabled Item',
655
+ });
656
+
657
+ await step(
658
+ 'interaction: the disabled item exposes its disabled state (WCAG 4.1.2)',
659
+ async () => {
660
+ await expect(disabledTrigger).toBeDisabled();
661
+ await expect(disabledTrigger).toHaveAttribute('aria-disabled', 'true');
662
+ },
663
+ );
664
+
665
+ await step(
666
+ 'interaction: a disabled item does not toggle, even on forced clicks',
667
+ async () => {
668
+ // The disabled trigger renders with pointer-events: none, so bypass
669
+ // the pointer-events check to prove the guard itself blocks toggling.
670
+ await userEvent.click(disabledTrigger, { pointerEventsCheck: 0 });
671
+ await expect(disabledTrigger).toHaveAttribute('aria-expanded', 'false');
672
+ await expect(
673
+ canvas.queryByRole('region', { name: 'Disabled Item' }),
674
+ ).not.toBeInTheDocument();
675
+ },
676
+ );
677
+ },
678
+ };
679
+
680
+ const horizontalTemplateSource = `<script setup lang="ts">
681
+ import {
682
+ UiAccordion,
683
+ UiAccordionItem,
684
+ UiAccordionTrigger,
685
+ UiAccordionContent,
686
+ } from '@aleph-alpha/ui-library'
687
+ </script>
688
+
689
+ <template>
690
+ <UiAccordion type="single" collapsible orientation="horizontal" class="w-full">
691
+ <UiAccordionItem value="shipping">
692
+ <UiAccordionTrigger>Shipping</UiAccordionTrigger>
693
+ <UiAccordionContent>
694
+ <p>Standard delivery takes 3-5 business days.</p>
695
+ </UiAccordionContent>
696
+ </UiAccordionItem>
697
+ <UiAccordionItem value="payment" :disabled="true">
698
+ <UiAccordionTrigger>Payment</UiAccordionTrigger>
699
+ <UiAccordionContent>
700
+ <p>Payment options are currently unavailable.</p>
701
+ </UiAccordionContent>
702
+ </UiAccordionItem>
703
+ <UiAccordionItem value="returns">
704
+ <UiAccordionTrigger>Returns</UiAccordionTrigger>
705
+ <UiAccordionContent>
706
+ <p>Items can be returned within 30 days.</p>
707
+ </UiAccordionContent>
708
+ </UiAccordionItem>
709
+ </UiAccordion>
710
+ </template>`;
711
+
712
+ /**
713
+ * Set `orientation="horizontal"` to move between triggers with
714
+ * `ArrowLeft`/`ArrowRight` instead of `ArrowUp`/`ArrowDown`. Orientation only
715
+ * changes the keyboard navigation direction — the visual layout stays
716
+ * vertical. Use it when the accordion sits in a horizontally arranged
717
+ * context where left/right arrows are the expected movement.
718
+ */
719
+ export const Horizontal: Story = {
720
+ render: () => ({
721
+ components: {
722
+ UiAccordion,
723
+ UiAccordionItem,
724
+ UiAccordionTrigger,
725
+ UiAccordionContent,
726
+ },
727
+ template: `
728
+ <UiAccordion type="single" collapsible orientation="horizontal" class="w-full">
729
+ <UiAccordionItem value="shipping">
730
+ <UiAccordionTrigger>Shipping</UiAccordionTrigger>
731
+ <UiAccordionContent>
732
+ <p>Standard delivery takes 3-5 business days.</p>
733
+ </UiAccordionContent>
734
+ </UiAccordionItem>
735
+ <UiAccordionItem value="payment" :disabled="true">
736
+ <UiAccordionTrigger>Payment</UiAccordionTrigger>
737
+ <UiAccordionContent>
738
+ <p>Payment options are currently unavailable.</p>
739
+ </UiAccordionContent>
740
+ </UiAccordionItem>
741
+ <UiAccordionItem value="returns">
742
+ <UiAccordionTrigger>Returns</UiAccordionTrigger>
743
+ <UiAccordionContent>
744
+ <p>Items can be returned within 30 days.</p>
745
+ </UiAccordionContent>
746
+ </UiAccordionItem>
747
+ </UiAccordion>
748
+ `,
749
+ }),
750
+ parameters: {
751
+ // Focus moves during the play function; skip the visual snapshot so the
752
+ // focus ring doesn't register as a Chromatic diff.
753
+ chromatic: { disableSnapshot: true },
754
+ docs: {
755
+ source: {
756
+ code: horizontalTemplateSource,
757
+ },
758
+ },
759
+ },
760
+ play: async ({ canvasElement, step }) => {
761
+ // Scenario (UiAccordion): with orientation="horizontal" a keyboard user
762
+ // moves between triggers with ArrowLeft/ArrowRight (skipping the disabled
763
+ // one, looping at the ends) while the vertical arrows are ignored.
764
+ const canvas = within(canvasElement);
765
+ const shipping = canvas.getByRole('button', { name: 'Shipping' });
766
+ const payment = canvas.getByRole('button', { name: 'Payment' });
767
+ const returns = canvas.getByRole('button', { name: 'Returns' });
768
+
769
+ await step(
770
+ 'keyboard: Tab reaches the first trigger (WCAG 2.1.1 Keyboard)',
771
+ async () => {
772
+ await userEvent.tab();
773
+ await expect(shipping).toHaveFocus();
774
+ },
775
+ );
776
+
777
+ await step(
778
+ 'keyboard: ArrowRight moves to the next trigger, skipping disabled ones',
779
+ async () => {
780
+ await userEvent.keyboard('{ArrowRight}');
781
+ await expect(returns).toHaveFocus();
782
+ await expect(payment).not.toHaveFocus();
783
+ },
784
+ );
785
+
786
+ await step(
787
+ 'keyboard: ArrowLeft moves back to the previous enabled trigger',
788
+ async () => {
789
+ await userEvent.keyboard('{ArrowLeft}');
790
+ await expect(shipping).toHaveFocus();
791
+ },
792
+ );
793
+
794
+ await step(
795
+ 'keyboard: vertical arrows do not move focus in horizontal mode',
796
+ async () => {
797
+ await userEvent.keyboard('{ArrowDown}');
798
+ await expect(shipping).toHaveFocus();
799
+ await userEvent.keyboard('{ArrowUp}');
800
+ await expect(shipping).toHaveFocus();
801
+ },
802
+ );
803
+
804
+ await step(
805
+ 'keyboard: horizontal arrow navigation loops around the ends',
806
+ async () => {
807
+ await userEvent.keyboard('{ArrowLeft}');
808
+ await expect(returns).toHaveFocus();
809
+ await userEvent.keyboard('{ArrowRight}');
810
+ await expect(shipping).toHaveFocus();
811
+ },
812
+ );
813
+
814
+ await step(
815
+ 'keyboard: Enter still toggles the focused section',
816
+ async () => {
817
+ await userEvent.keyboard('{Enter}');
818
+ await expect(shipping).toHaveAttribute('aria-expanded', 'true');
819
+ await waitFor(async () => {
820
+ await expect(
821
+ canvas.getByRole('region', { name: 'Shipping' }),
822
+ ).toBeVisible();
823
+ });
824
+ // Collapse again so the story rests in its default state.
825
+ await userEvent.keyboard('{Enter}');
826
+ await expect(shipping).toHaveAttribute('aria-expanded', 'false');
827
+ },
828
+ );
829
+ },
417
830
  };
418
831
 
419
832
  const controlledTemplateSource = `<script setup lang="ts">
@@ -535,4 +948,670 @@ export const Controlled: Story = {
535
948
  },
536
949
  },
537
950
  },
951
+ play: async ({ canvasElement, step }) => {
952
+ // Scenario (UiAccordion): a bound v-model expands the matching section.
953
+ // Programmatic switching is covered by the hidden ExpandCollapseBehavior
954
+ // story, so this snapshot stays on Overview.
955
+ const canvas = within(canvasElement);
956
+ const overview = canvas.getByRole('button', { name: 'Overview' });
957
+ const details = canvas.getByRole('button', { name: 'Details' });
958
+
959
+ await step(
960
+ 'interaction: the bound value expands the matching section',
961
+ async () => {
962
+ await expect(overview).toHaveAttribute('aria-expanded', 'true');
963
+ await expect(canvas.getByRole('region')).toHaveTextContent(
964
+ 'Overview content goes here.',
965
+ );
966
+ await expect(canvas.getByText('overview')).toBeVisible();
967
+ },
968
+ );
969
+ await step(
970
+ 'interaction: parent-driven updates switch the expanded section',
971
+ async () => {
972
+ await userEvent.click(
973
+ canvas.getByRole('button', { name: 'Go to Details' }),
974
+ );
975
+ await expect(details).toHaveAttribute('aria-expanded', 'true');
976
+ await expect(overview).toHaveAttribute('aria-expanded', 'false');
977
+ await expect(canvas.getByText('details')).toBeVisible();
978
+ await waitFor(async () => {
979
+ await expect(canvas.getAllByRole('region')).toHaveLength(1);
980
+ await expect(
981
+ canvas.getByRole('region', { name: 'Details' }),
982
+ ).toHaveTextContent('Detailed information goes here.');
983
+ });
984
+ },
985
+ );
986
+ await step(
987
+ 'interaction: clearing the bound value closes all sections',
988
+ async () => {
989
+ await userEvent.click(
990
+ canvas.getByRole('button', { name: 'Close All' }),
991
+ );
992
+ await expect(details).toHaveAttribute('aria-expanded', 'false');
993
+ await expect(overview).toHaveAttribute('aria-expanded', 'false');
994
+ await expect(canvas.getByText('none')).toBeVisible();
995
+ await waitFor(async () => {
996
+ await expect(canvas.queryByRole('region')).not.toBeInTheDocument();
997
+ });
998
+ },
999
+ );
1000
+ await step(
1001
+ 'interaction: trigger activation updates the bound value',
1002
+ async () => {
1003
+ await userEvent.click(overview);
1004
+ await expect(overview).toHaveAttribute('aria-expanded', 'true');
1005
+ await expect(canvas.getByText('overview')).toBeVisible();
1006
+ await waitFor(async () => {
1007
+ await expect(
1008
+ canvas.getByRole('region', { name: 'Overview' }),
1009
+ ).toHaveTextContent('Overview content goes here.');
1010
+ });
1011
+ },
1012
+ );
1013
+ },
1014
+ };
1015
+
1016
+ /**
1017
+ * Accessibility guidance for accordions: visible focus states, state changes
1018
+ * that survive without colour, contrast across all trigger states, comfortable
1019
+ * touch targets, logical heading order, and subtle motion — shown side by side
1020
+ * in the default and accessible themes.
1021
+ */
1022
+ export const Accessibility: Story = {
1023
+ tags: ['!autodocs'],
1024
+ parameters: {
1025
+ a11y: { test: 'off' },
1026
+ chromatic: { disableSnapshot: true },
1027
+ docs: {
1028
+ canvas: {
1029
+ sourceState: 'none',
1030
+ },
1031
+ },
1032
+ },
1033
+ render: () => ({
1034
+ components: {
1035
+ UiAccordion,
1036
+ UiAccordionItem,
1037
+ UiAccordionTrigger,
1038
+ UiAccordionContent,
1039
+ },
1040
+ template: `
1041
+ <section class="flex flex-col gap-6 p-4">
1042
+ <div>
1043
+ <h2 class="heading-m font-bold text-content-on-surface-primary">
1044
+ Accessibility
1045
+ </h2>
1046
+ </div>
1047
+
1048
+ <div class="flex flex-col gap-6">
1049
+ <div class="flex flex-col gap-2">
1050
+ <h3 class="body-16-medium text-content-on-surface-primary">
1051
+ Requirements
1052
+ </h3>
1053
+ <ul class="body-16-regular flex list-disc flex-col gap-1 pl-6 text-content-on-surface-primary">
1054
+ <li>
1055
+ Every header has a visible focus state that stands clear of the
1056
+ surface behind it
1057
+ </li>
1058
+ <li>
1059
+ Open and closed differ in shape and weight, never in colour
1060
+ alone
1061
+ </li>
1062
+ <li>
1063
+ Header text and chevron hold their contrast in all four states:
1064
+ default, hover, focus and pressed
1065
+ </li>
1066
+ <li>
1067
+ Header rows are a comfortable target for touch as well as
1068
+ pointer
1069
+ </li>
1070
+ <li>
1071
+ Heading order runs top to bottom, so open content sits directly
1072
+ beneath its own header
1073
+ </li>
1074
+ <li>
1075
+ Expand and collapse motion stays short and subtle, so the page
1076
+ does not jump under the reader
1077
+ </li>
1078
+ </ul>
1079
+ </div>
1080
+
1081
+ <div class="flex flex-col gap-2">
1082
+ <h3 class="body-16-medium text-content-on-surface-primary">
1083
+ Enable accessibility theme
1084
+ </h3>
1085
+ <p class="body-16-regular text-content-on-surface-primary">
1086
+ When accessibility is required, enable our accessibility theme.
1087
+ This increases contrast and ensures there are no color contrast
1088
+ issues.
1089
+ </p>
1090
+ </div>
1091
+ </div>
1092
+
1093
+ <div class="grid gap-4 md:grid-cols-2">
1094
+ <div class="flex flex-col gap-3">
1095
+ <h3 class="label-16-medium text-center text-content-on-surface-primary">
1096
+ Default
1097
+ </h3>
1098
+ <div class="flex min-h-20 items-center justify-center border border-border-surface-default p-6">
1099
+ <UiAccordion type="single" collapsible class="w-full">
1100
+ <UiAccordionItem value="item-1">
1101
+ <UiAccordionTrigger>Trigger Text</UiAccordionTrigger>
1102
+ <UiAccordionContent>
1103
+ <p>Section content.</p>
1104
+ </UiAccordionContent>
1105
+ </UiAccordionItem>
1106
+ <UiAccordionItem value="item-2">
1107
+ <UiAccordionTrigger>Trigger Text</UiAccordionTrigger>
1108
+ <UiAccordionContent>
1109
+ <p>Section content.</p>
1110
+ </UiAccordionContent>
1111
+ </UiAccordionItem>
1112
+ <UiAccordionItem value="item-3">
1113
+ <UiAccordionTrigger>Trigger Text</UiAccordionTrigger>
1114
+ <UiAccordionContent>
1115
+ <p>Section content.</p>
1116
+ </UiAccordionContent>
1117
+ </UiAccordionItem>
1118
+ </UiAccordion>
1119
+ </div>
1120
+ </div>
1121
+
1122
+ <div class="accessible-theme flex flex-col gap-3">
1123
+ <h3 class="label-16-medium text-center text-content-on-surface-primary">
1124
+ Accessible
1125
+ </h3>
1126
+ <div class="flex min-h-20 items-center justify-center border border-border-surface-default p-6">
1127
+ <UiAccordion type="single" collapsible class="w-full">
1128
+ <UiAccordionItem value="item-1">
1129
+ <UiAccordionTrigger>Trigger Text</UiAccordionTrigger>
1130
+ <UiAccordionContent>
1131
+ <p>Section content.</p>
1132
+ </UiAccordionContent>
1133
+ </UiAccordionItem>
1134
+ <UiAccordionItem value="item-2">
1135
+ <UiAccordionTrigger>Trigger Text</UiAccordionTrigger>
1136
+ <UiAccordionContent>
1137
+ <p>Section content.</p>
1138
+ </UiAccordionContent>
1139
+ </UiAccordionItem>
1140
+ <UiAccordionItem value="item-3">
1141
+ <UiAccordionTrigger>Trigger Text</UiAccordionTrigger>
1142
+ <UiAccordionContent>
1143
+ <p>Section content.</p>
1144
+ </UiAccordionContent>
1145
+ </UiAccordionItem>
1146
+ </UiAccordion>
1147
+ </div>
1148
+ </div>
1149
+ </div>
1150
+ </section>
1151
+ `,
1152
+ }),
1153
+ };
1154
+
1155
+ // Test-only stories drive the test-runner (interactive/a11y checks) but are
1156
+ // hidden from the Storybook sidebar and docs via the `!dev` / `!autodocs`
1157
+ // tags. They keep the implicit `test` tag, so they still run in CI and appear
1158
+ // in the automated report under their `test - …` name. `name`/`tags` must be
1159
+ // literal properties so Storybook's static CSF indexer can read them.
1160
+
1161
+ // Shared render for the test-only scenarios: a single/collapsible accordion
1162
+ // whose second item is disabled, so one fixture covers expand/collapse, the
1163
+ // disabled guard, arrow-key skipping, and Home/End (first and last items stay
1164
+ // enabled because Home/End target them directly).
1165
+ function renderTestAccordion(defaultValue?: string) {
1166
+ return () => ({
1167
+ components: {
1168
+ UiAccordion,
1169
+ UiAccordionItem,
1170
+ UiAccordionTrigger,
1171
+ UiAccordionContent,
1172
+ },
1173
+ setup() {
1174
+ const activeItem = ref<string | undefined>(defaultValue);
1175
+ return { activeItem, onUpdate };
1176
+ },
1177
+ template: `
1178
+ <UiAccordion
1179
+ v-model="activeItem"
1180
+ type="single"
1181
+ collapsible
1182
+ class="w-full"
1183
+ @update:model-value="onUpdate"
1184
+ >
1185
+ <UiAccordionItem value="shipping">
1186
+ <UiAccordionTrigger>Shipping</UiAccordionTrigger>
1187
+ <UiAccordionContent>
1188
+ <p>Standard delivery takes 3-5 business days.</p>
1189
+ </UiAccordionContent>
1190
+ </UiAccordionItem>
1191
+ <UiAccordionItem value="payment" :disabled="true">
1192
+ <UiAccordionTrigger>Payment</UiAccordionTrigger>
1193
+ <UiAccordionContent>
1194
+ <p>Payment options are currently unavailable.</p>
1195
+ </UiAccordionContent>
1196
+ </UiAccordionItem>
1197
+ <UiAccordionItem value="returns">
1198
+ <UiAccordionTrigger>Returns</UiAccordionTrigger>
1199
+ <UiAccordionContent>
1200
+ <p>Items can be returned within 30 days.</p>
1201
+ </UiAccordionContent>
1202
+ </UiAccordionItem>
1203
+ <UiAccordionItem value="warranty">
1204
+ <UiAccordionTrigger>Warranty</UiAccordionTrigger>
1205
+ <UiAccordionContent>
1206
+ <p>All products include a two-year warranty.</p>
1207
+ </UiAccordionContent>
1208
+ </UiAccordionItem>
1209
+ </UiAccordion>
1210
+ `,
1211
+ });
1212
+ }
1213
+
1214
+ /**
1215
+ * Expand/collapse behaviour: clicking a trigger reveals its content and emits
1216
+ * `update:modelValue`, expanding another section collapses the first in
1217
+ * single mode, collapsing hides the content, and a disabled item stays inert.
1218
+ */
1219
+ export const ExpandCollapseBehavior: Story = {
1220
+ name: 'test - Expand Collapse Behavior',
1221
+ tags: ['!dev', '!autodocs'],
1222
+ parameters: {
1223
+ chromatic: { disableSnapshot: true },
1224
+ docs: {
1225
+ description: {
1226
+ story:
1227
+ 'Expand and collapse sections with the pointer and confirm the disabled guard holds.',
1228
+ },
1229
+ },
1230
+ },
1231
+ render: renderTestAccordion(),
1232
+ play: async ({ canvasElement, step }) => {
1233
+ // Scenario (UiAccordion): a pointer user expands a section, switches to
1234
+ // another (single mode closes the first), collapses it again, and cannot
1235
+ // toggle the disabled item.
1236
+ onUpdate.mockClear();
1237
+ const canvas = within(canvasElement);
1238
+ const shipping = canvas.getByRole('button', { name: 'Shipping' });
1239
+ const payment = canvas.getByRole('button', { name: 'Payment' });
1240
+ const returns = canvas.getByRole('button', { name: 'Returns' });
1241
+
1242
+ await step(
1243
+ 'interaction: expanding a section reveals its content and emits update:modelValue',
1244
+ async () => {
1245
+ await userEvent.click(shipping);
1246
+ await expect(shipping).toHaveAttribute('aria-expanded', 'true');
1247
+ await expect(onUpdate).toHaveBeenLastCalledWith('shipping');
1248
+ await waitFor(async () => {
1249
+ await expect(
1250
+ canvas.getByRole('region', { name: 'Shipping' }),
1251
+ ).toHaveTextContent('Standard delivery takes 3-5 business days.');
1252
+ });
1253
+ },
1254
+ );
1255
+
1256
+ await step(
1257
+ 'interaction: expanding another section collapses the first (single mode)',
1258
+ async () => {
1259
+ await userEvent.click(returns);
1260
+ await expect(returns).toHaveAttribute('aria-expanded', 'true');
1261
+ await expect(shipping).toHaveAttribute('aria-expanded', 'false');
1262
+ await expect(onUpdate).toHaveBeenLastCalledWith('returns');
1263
+ await waitFor(async () => {
1264
+ await expect(canvas.getAllByRole('region')).toHaveLength(1);
1265
+ });
1266
+ },
1267
+ );
1268
+
1269
+ await step(
1270
+ 'interaction: collapsing the open section hides its content',
1271
+ async () => {
1272
+ await userEvent.click(returns);
1273
+ await expect(returns).toHaveAttribute('aria-expanded', 'false');
1274
+ await expect(onUpdate).toHaveBeenLastCalledWith(undefined);
1275
+ await waitFor(async () => {
1276
+ await expect(canvas.queryByRole('region')).not.toBeInTheDocument();
1277
+ });
1278
+ },
1279
+ );
1280
+
1281
+ await step('interaction: a disabled item does not toggle', async () => {
1282
+ onUpdate.mockClear();
1283
+ await expect(payment).toBeDisabled();
1284
+ // The disabled trigger renders with pointer-events: none, so bypass the
1285
+ // pointer-events check to prove the guard itself blocks toggling.
1286
+ await userEvent.click(payment, { pointerEventsCheck: 0 });
1287
+ await expect(payment).toHaveAttribute('aria-expanded', 'false');
1288
+ await expect(onUpdate).not.toHaveBeenCalled();
1289
+ });
1290
+ },
1291
+ };
1292
+
1293
+ /**
1294
+ * `UiAccordion` is fully keyboard operable: `Tab` reaches each trigger,
1295
+ * `Enter`/`Space` toggle the focused section, `ArrowDown`/`ArrowUp` move
1296
+ * between triggers (skipping disabled ones and looping at the ends), and
1297
+ * `Home`/`End` jump to the first and last trigger.
1298
+ */
1299
+ export const KeyboardNavigation: Story = {
1300
+ name: 'test - Keyboard Navigation',
1301
+ tags: ['!dev', '!autodocs'],
1302
+ parameters: {
1303
+ // Focus moves during the play function; skip the visual snapshot so the
1304
+ // focus ring doesn't register as a Chromatic diff.
1305
+ chromatic: { disableSnapshot: true },
1306
+ docs: {
1307
+ description: {
1308
+ story:
1309
+ 'Press `Tab` to reach a trigger, `Enter` or `Space` to toggle it, and `ArrowDown`/`ArrowUp`/`Home`/`End` to move between triggers.',
1310
+ },
1311
+ },
1312
+ },
1313
+ render: renderTestAccordion(),
1314
+ play: async ({ canvasElement, step }) => {
1315
+ // Scenario (UiAccordion): a keyboard user tabs to the first trigger,
1316
+ // toggles it with Enter and Space, then moves between triggers with the
1317
+ // arrow keys (skipping the disabled one, looping at the ends) and jumps
1318
+ // with Home/End.
1319
+ onUpdate.mockClear();
1320
+ const canvas = within(canvasElement);
1321
+ const shipping = canvas.getByRole('button', { name: 'Shipping' });
1322
+ const payment = canvas.getByRole('button', { name: 'Payment' });
1323
+ const returns = canvas.getByRole('button', { name: 'Returns' });
1324
+ const warranty = canvas.getByRole('button', { name: 'Warranty' });
1325
+
1326
+ await step(
1327
+ 'keyboard: Tab reaches the first trigger (WCAG 2.1.1 Keyboard)',
1328
+ async () => {
1329
+ await userEvent.tab();
1330
+ await expect(shipping).toHaveFocus();
1331
+ await expect(shipping).toHaveAttribute('aria-expanded', 'false');
1332
+ },
1333
+ );
1334
+
1335
+ await step('keyboard: Enter toggles the focused section', async () => {
1336
+ await userEvent.keyboard('{Enter}');
1337
+ await expect(shipping).toHaveAttribute('aria-expanded', 'true');
1338
+ await waitFor(async () => {
1339
+ await expect(
1340
+ canvas.getByRole('region', { name: 'Shipping' }),
1341
+ ).toBeVisible();
1342
+ });
1343
+ await userEvent.keyboard('{Enter}');
1344
+ await expect(shipping).toHaveAttribute('aria-expanded', 'false');
1345
+ });
1346
+
1347
+ await step('keyboard: Space toggles the focused section', async () => {
1348
+ await userEvent.keyboard(' ');
1349
+ await expect(shipping).toHaveAttribute('aria-expanded', 'true');
1350
+ await userEvent.keyboard(' ');
1351
+ await expect(shipping).toHaveAttribute('aria-expanded', 'false');
1352
+ await waitFor(async () => {
1353
+ await expect(canvas.queryByRole('region')).not.toBeInTheDocument();
1354
+ });
1355
+ });
1356
+
1357
+ await step(
1358
+ 'keyboard: ArrowDown moves to the next trigger, skipping disabled ones',
1359
+ async () => {
1360
+ await userEvent.keyboard('{ArrowDown}');
1361
+ await expect(returns).toHaveFocus();
1362
+ await expect(payment).not.toHaveFocus();
1363
+ },
1364
+ );
1365
+
1366
+ await step(
1367
+ 'keyboard: ArrowUp moves back to the previous enabled trigger',
1368
+ async () => {
1369
+ await userEvent.keyboard('{ArrowUp}');
1370
+ await expect(shipping).toHaveFocus();
1371
+ },
1372
+ );
1373
+
1374
+ await step(
1375
+ 'keyboard: Home and End jump to the first and last trigger (WCAG 2.4.3)',
1376
+ async () => {
1377
+ await userEvent.keyboard('{End}');
1378
+ await expect(warranty).toHaveFocus();
1379
+ await userEvent.keyboard('{Home}');
1380
+ await expect(shipping).toHaveFocus();
1381
+ },
1382
+ );
1383
+
1384
+ await step('keyboard: arrow navigation loops around the ends', async () => {
1385
+ await userEvent.keyboard('{ArrowUp}');
1386
+ await expect(warranty).toHaveFocus();
1387
+ await userEvent.keyboard('{ArrowDown}');
1388
+ await expect(shipping).toHaveFocus();
1389
+ });
1390
+
1391
+ await step(
1392
+ 'keyboard: the disabled trigger is skipped by Tab (WCAG 2.1.1)',
1393
+ async () => {
1394
+ await userEvent.tab();
1395
+ await expect(returns).toHaveFocus();
1396
+ await expect(payment).not.toHaveFocus();
1397
+ },
1398
+ );
1399
+ },
1400
+ };
1401
+
1402
+ /**
1403
+ * Screen-reader semantics: triggers are buttons named by their labels and
1404
+ * wrapped in headings, aria-expanded announces the state, the expanded panel
1405
+ * is a region labelled by its trigger, and the disabled item announces its
1406
+ * disabled state.
1407
+ */
1408
+ export const ScreenReader: Story = {
1409
+ name: 'test - Screen Reader',
1410
+ tags: ['!dev', '!autodocs'],
1411
+ parameters: {
1412
+ chromatic: { disableSnapshot: true },
1413
+ docs: {
1414
+ description: {
1415
+ story:
1416
+ 'Verifies the roles, names, and states that assistive technology announces.',
1417
+ },
1418
+ },
1419
+ },
1420
+ render: renderTestAccordion('shipping'),
1421
+ play: async ({ canvasElement, step }) => {
1422
+ // Scenario (UiAccordion): assistive tech reads each trigger as a button
1423
+ // inside a heading, hears whether it is expanded or collapsed, finds the
1424
+ // open panel as a region named by its trigger, and is told the disabled
1425
+ // item is unavailable.
1426
+ const canvas = within(canvasElement);
1427
+ const shipping = canvas.getByRole('button', { name: 'Shipping' });
1428
+ const payment = canvas.getByRole('button', { name: 'Payment' });
1429
+ const returns = canvas.getByRole('button', { name: 'Returns' });
1430
+
1431
+ await step(
1432
+ 'screen-reader: every trigger exposes a button role named by its label (WCAG 4.1.2)',
1433
+ async () => {
1434
+ await expect(shipping).toHaveAccessibleName('Shipping');
1435
+ await expect(payment).toHaveAccessibleName('Payment');
1436
+ await expect(returns).toHaveAccessibleName('Returns');
1437
+ },
1438
+ );
1439
+
1440
+ await step(
1441
+ 'screen-reader: triggers are wrapped in headings so the structure is announced (WCAG 1.3.1)',
1442
+ async () => {
1443
+ await expect(canvas.getAllByRole('heading', { level: 3 })).toHaveLength(
1444
+ 4,
1445
+ );
1446
+ },
1447
+ );
1448
+
1449
+ await step(
1450
+ 'screen-reader: expanded and collapsed states are announced via aria-expanded (WCAG 4.1.2)',
1451
+ async () => {
1452
+ await expect(shipping).toHaveAttribute('aria-expanded', 'true');
1453
+ await expect(returns).toHaveAttribute('aria-expanded', 'false');
1454
+ },
1455
+ );
1456
+
1457
+ await step(
1458
+ 'screen-reader: the expanded panel is a region labelled by its trigger (WCAG 1.3.1)',
1459
+ async () => {
1460
+ const region = canvas.getByRole('region', { name: 'Shipping' });
1461
+ await expect(region).toHaveAttribute(
1462
+ 'aria-labelledby',
1463
+ shipping.getAttribute('id') as string,
1464
+ );
1465
+ },
1466
+ );
1467
+
1468
+ await step(
1469
+ 'screen-reader: the disabled item announces its disabled state (WCAG 4.1.2)',
1470
+ async () => {
1471
+ await expect(payment).toBeDisabled();
1472
+ await expect(payment).toHaveAttribute('aria-disabled', 'true');
1473
+ },
1474
+ );
1475
+
1476
+ await step(
1477
+ 'screen-reader: the announced state follows expansion (WCAG 4.1.2)',
1478
+ async () => {
1479
+ await userEvent.click(returns);
1480
+ await expect(returns).toHaveAttribute('aria-expanded', 'true');
1481
+ await expect(shipping).toHaveAttribute('aria-expanded', 'false');
1482
+ await waitFor(async () => {
1483
+ await expect(
1484
+ canvas.getByRole('region', { name: 'Returns' }),
1485
+ ).toBeVisible();
1486
+ });
1487
+ },
1488
+ );
1489
+ },
1490
+ };
1491
+
1492
+ /**
1493
+ * Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
1494
+ * try 400% reflow (WCAG 1.4.10); the accordion must stay visible, readable,
1495
+ * and operable.
1496
+ */
1497
+ export const ZoomMagnification: Story = {
1498
+ name: 'test - Zoom Magnification',
1499
+ tags: ['!dev', '!autodocs'],
1500
+ globals: { zoom: '200' },
1501
+ parameters: {
1502
+ // Zoom changes the layout scale; the accessible-reflow Chromatic mode
1503
+ // already covers magnified snapshots, so skip this one.
1504
+ chromatic: { disableSnapshot: true },
1505
+ docs: {
1506
+ description: {
1507
+ story:
1508
+ 'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
1509
+ },
1510
+ },
1511
+ },
1512
+ render: renderTestAccordion('shipping'),
1513
+ play: async ({ canvasElement, step }) => {
1514
+ // Scenario (UiAccordion): at 200% page zoom every trigger stays on screen
1515
+ // with its label, the expanded content stays readable, and sections can
1516
+ // still be toggled.
1517
+ const canvas = within(canvasElement);
1518
+
1519
+ await step(
1520
+ 'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
1521
+ async () => {
1522
+ await expect(document.documentElement.style.zoom).toBe('200%');
1523
+ },
1524
+ );
1525
+
1526
+ await step(
1527
+ 'zoom: every trigger stays visible with a readable label when magnified',
1528
+ async () => {
1529
+ for (const trigger of canvas.getAllByRole('button')) {
1530
+ await expect(trigger).toBeVisible();
1531
+ await expect(trigger).toHaveAccessibleName();
1532
+ }
1533
+ await expect(
1534
+ canvas.getByRole('region', { name: 'Shipping' }),
1535
+ ).toBeVisible();
1536
+ },
1537
+ );
1538
+
1539
+ await step('zoom: remains operable when magnified', async () => {
1540
+ const returns = canvas.getByRole('button', { name: 'Returns' });
1541
+ await userEvent.click(returns);
1542
+ await expect(returns).toHaveAttribute('aria-expanded', 'true');
1543
+ await waitFor(async () => {
1544
+ await expect(
1545
+ canvas.getByRole('region', { name: 'Returns' }),
1546
+ ).toHaveTextContent('Items can be returned within 30 days.');
1547
+ });
1548
+ });
1549
+ },
1550
+ };
1551
+
1552
+ /**
1553
+ * Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
1554
+ * toolbar. The accordion stays usable and triggers meet the minimum
1555
+ * touch-target size (WCAG 2.5.8).
1556
+ */
1557
+ export const MobileBreakpoint: Story = {
1558
+ name: 'test - Mobile Breakpoint',
1559
+ tags: ['!dev', '!autodocs'],
1560
+ globals: { mediaBreakpoint: 'reflow' },
1561
+ parameters: {
1562
+ // Reflow snapshots are already covered by the accessible-reflow mode.
1563
+ chromatic: { disableSnapshot: true },
1564
+ docs: {
1565
+ description: {
1566
+ story:
1567
+ 'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
1568
+ },
1569
+ },
1570
+ },
1571
+ render: renderTestAccordion('shipping'),
1572
+ play: async ({ canvasElement, step }) => {
1573
+ // Scenario (UiAccordion): at the 320px mobile breakpoint the accordion
1574
+ // fits the viewport, every trigger is big enough to tap, and a tap still
1575
+ // toggles its section.
1576
+ onUpdate.mockClear();
1577
+ const canvas = within(canvasElement);
1578
+
1579
+ await step(
1580
+ 'mobile: the accordion fits the 320px viewport without sideways scrolling (WCAG 1.4.10 Reflow)',
1581
+ async () => {
1582
+ await expect(canvasElement.scrollWidth).toBeLessThanOrEqual(
1583
+ window.innerWidth,
1584
+ );
1585
+ for (const trigger of canvas.getAllByRole('button')) {
1586
+ await expect(trigger).toBeVisible();
1587
+ }
1588
+ },
1589
+ );
1590
+
1591
+ await step(
1592
+ 'mobile: triggers meet the minimum touch-target size (WCAG 2.5.8)',
1593
+ async () => {
1594
+ for (const trigger of canvas.getAllByRole('button')) {
1595
+ const { width, height } = trigger.getBoundingClientRect();
1596
+ await expect(width).toBeGreaterThanOrEqual(24);
1597
+ await expect(height).toBeGreaterThanOrEqual(24);
1598
+ }
1599
+ },
1600
+ );
1601
+
1602
+ await step(
1603
+ 'mobile: tapping a trigger toggles its section at the 320px breakpoint',
1604
+ async () => {
1605
+ const returns = canvas.getByRole('button', { name: 'Returns' });
1606
+ await userEvent.click(returns);
1607
+ await expect(returns).toHaveAttribute('aria-expanded', 'true');
1608
+ await expect(onUpdate).toHaveBeenLastCalledWith('returns');
1609
+ await waitFor(async () => {
1610
+ await expect(
1611
+ canvas.getByRole('region', { name: 'Returns' }),
1612
+ ).toBeVisible();
1613
+ });
1614
+ },
1615
+ );
1616
+ },
538
1617
  };