@aleph-alpha/ui-library 6.3.3 → 6.4.0

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 (105) hide show
  1. package/config.js +2 -1
  2. package/dist/system/components/UiDropdownMenu/UiDropdownMenuSubContent.vue.d.ts +102 -2
  3. package/dist/system/components/UiDropdownMenu/UiDropdownMenuViewport.vue.d.ts +23 -0
  4. package/dist/system/components/UiDropdownMenu/menu-metrics.d.ts +4 -0
  5. package/dist/system/components/UiDropdownMenu/placeMobileSubmenu.d.ts +55 -0
  6. package/dist/system/components/UiDropdownMenu/types.d.ts +3 -0
  7. package/dist/system/components/UiDropdownMenu/useMobileSubmenuPlacement.d.ts +18 -0
  8. package/dist/system/components/UiFileUploadBox/UiFileUploadBox.vue.d.ts +2 -2
  9. package/dist/system/components/UiFileUploadBox/types.d.ts +8 -5
  10. package/dist/system/components/UiResizable/UiResizablePanel.vue.d.ts +2 -2
  11. package/dist/system/components/UiStepper/context.d.ts +8 -0
  12. package/dist/system/components/UiToggle/UiToggle.vue.d.ts +2 -1
  13. package/dist/system/components/UiToggle/types.d.ts +10 -2
  14. package/dist/system/components/UiToggleGroup/UiToggleGroupItem.vue.d.ts +5 -1
  15. package/dist/system/components/UiToggleGroup/types.d.ts +12 -2
  16. package/dist/system/components/core/dropdown-menu/DropdownMenuSubContent.vue.d.ts +2 -6
  17. package/dist/system/components/core/range-calendar/RangeCalendar.vue.d.ts +24 -24
  18. package/dist/system/components/core/resizable/ResizablePanel.vue.d.ts +2 -2
  19. package/dist/system/components/core/toggle/Toggle.vue.d.ts +3 -1
  20. package/dist/system/components/core/toggle/index.d.ts +47 -2
  21. package/dist/system/components/core/toggle-group/ToggleGroup.vue.d.ts +3 -1
  22. package/dist/system/components/core/toggle-group/ToggleGroupItem.vue.d.ts +11 -1
  23. package/dist/system/components/core/toggle-group/context.d.ts +1 -0
  24. package/dist/system/components/core/toggle-group/index.d.ts +10 -2
  25. package/dist/system/icons/story-sidebar-icons.json +7 -0
  26. package/dist/system/lib.js +14114 -13755
  27. package/dist/system/patterns/UiFileUpload/UiFileUpload.vue.d.ts +2 -2
  28. package/dist/system/patterns/UiLayout/layout-shell.d.ts +379 -8
  29. package/dist/system/patterns/UiProfileCard/profile-card.d.ts +51 -1
  30. package/dist/system/patterns/UiTopBar/accessory-dropdown.d.ts +232 -0
  31. package/dist/system/story-sidebar-icons.json +7 -0
  32. package/package.json +2 -2
  33. package/src/components/UiAccordion/UiAccordion.stories.ts +1079 -0
  34. package/src/components/UiCalendar/UiCalendar.stories.ts +734 -0
  35. package/src/components/UiCalendar/__tests__/UiCalendar.test.ts +8 -5
  36. package/src/components/UiDropdownMenu/UiDropdownMenu.stories.ts +819 -31
  37. package/src/components/UiDropdownMenu/UiDropdownMenuContent.vue +4 -1
  38. package/src/components/UiDropdownMenu/UiDropdownMenuSubContent.vue +142 -1
  39. package/src/components/UiDropdownMenu/UiDropdownMenuSubTrigger.vue +28 -0
  40. package/src/components/UiDropdownMenu/UiDropdownMenuTrigger.vue +3 -1
  41. package/src/components/UiDropdownMenu/UiDropdownMenuViewport.vue +171 -0
  42. package/src/components/UiDropdownMenu/__tests__/UiDropdownMenu.test.ts +326 -0
  43. package/src/components/UiDropdownMenu/__tests__/placeMobileSubmenu.test.ts +128 -0
  44. package/src/components/UiDropdownMenu/menu-metrics.ts +5 -0
  45. package/src/components/UiDropdownMenu/placeMobileSubmenu.ts +96 -0
  46. package/src/components/UiDropdownMenu/types.ts +3 -0
  47. package/src/components/UiDropdownMenu/useMobileSubmenuPlacement.ts +163 -0
  48. package/src/components/UiFileUploadBox/UiFileUploadBox.stories.ts +389 -3
  49. package/src/components/UiFileUploadBox/UiFileUploadBox.vue +55 -75
  50. package/src/components/UiFileUploadBox/__tests__/UiFileUploadBox.test.ts +44 -0
  51. package/src/components/UiFileUploadBox/types.ts +8 -5
  52. package/src/components/UiNavigationMenu/UiNavigationMenu.stories.ts +723 -0
  53. package/src/components/UiRangeCalendar/UiRangeCalendar.stories.ts +819 -7
  54. package/src/components/UiRangeCalendar/__tests__/UiRangeCalendar.test.ts +8 -3
  55. package/src/components/UiResizable/UiResizable.stories.ts +1215 -5
  56. package/src/components/UiSnackbar/UiSnackbar.stories.ts +1089 -4
  57. package/src/components/UiSnackbar/UiSnackbar.vue +3 -2
  58. package/src/components/UiSnackbar/UiSnackbarContent.vue +1 -1
  59. package/src/components/UiSnackbar/__tests__/UiSnackbar.test.ts +3 -1
  60. package/src/components/UiStepper/UiStepper.stories.ts +566 -2
  61. package/src/components/UiStepper/UiStepper.vue +14 -1
  62. package/src/components/UiStepper/UiStepperItem.vue +22 -4
  63. package/src/components/UiStepper/__tests__/UiStepper.test.ts +66 -0
  64. package/src/components/UiStepper/context.ts +10 -0
  65. package/src/components/UiToggle/UiToggle.stories.ts +386 -261
  66. package/src/components/UiToggle/UiToggle.vue +2 -0
  67. package/src/components/UiToggle/__tests__/UiToggle.test.ts +63 -10
  68. package/src/components/UiToggle/types.ts +10 -2
  69. package/src/components/UiToggleGroup/UiToggleGroup.stories.ts +765 -30
  70. package/src/components/UiToggleGroup/UiToggleGroup.vue +2 -0
  71. package/src/components/UiToggleGroup/UiToggleGroupItem.vue +10 -1
  72. package/src/components/UiToggleGroup/__tests__/UiToggleGroup.test.ts +83 -4
  73. package/src/components/UiToggleGroup/types.ts +12 -2
  74. package/src/components/core/calendar/Calendar.vue +234 -2
  75. package/src/components/core/calendar/CalendarCellTrigger.vue +1 -1
  76. package/src/components/core/dropdown-menu/DropdownMenuContent.vue +1 -1
  77. package/src/components/core/dropdown-menu/DropdownMenuItem.vue +1 -1
  78. package/src/components/core/dropdown-menu/DropdownMenuSubContent.vue +31 -20
  79. package/src/components/core/navigation-menu/NavigationMenuList.vue +1 -1
  80. package/src/components/core/range-calendar/RangeCalendar.vue +254 -6
  81. package/src/components/core/range-calendar/RangeCalendarCellTrigger.vue +1 -1
  82. package/src/components/core/toggle/Toggle.vue +12 -5
  83. package/src/components/core/toggle/index.ts +47 -19
  84. package/src/components/core/toggle-group/ToggleGroup.vue +20 -4
  85. package/src/components/core/toggle-group/ToggleGroupItem.vue +36 -8
  86. package/src/components/core/toggle-group/context.ts +1 -0
  87. package/src/components/core/toggle-group/index.ts +10 -24
  88. package/src/patterns/UiDataTable/UiDataTableColumnFilter.vue +1 -1
  89. package/src/patterns/UiDataTable/UiDataTableFilterMenu.vue +1 -1
  90. package/src/patterns/UiDatePicker/UiDatePicker.stories.ts +846 -17
  91. package/src/patterns/UiDatePicker/UiDatePicker.vue +9 -0
  92. package/src/patterns/UiDatePicker/__tests__/UiDatePicker.test.ts +13 -8
  93. package/src/patterns/UiFileUpload/UiFileItem.stories.ts +23 -17
  94. package/src/patterns/UiFileUpload/UiFileUpload.stories.ts +138 -113
  95. package/src/patterns/UiFileUpload/UiFileUpload.vue +1 -1
  96. package/src/patterns/UiFileUpload/__tests__/UiFileUpload.test.ts +2 -2
  97. package/src/patterns/UiLayout/UiLayout.stories.ts +25 -0
  98. package/src/patterns/UiLayout/UiLayoutContent.stories.ts +359 -0
  99. package/src/patterns/UiLayout/UiLayoutContent.vue +45 -23
  100. package/src/patterns/UiLayout/UiLayoutMobile.stories.ts +13 -0
  101. package/src/patterns/UiLayout/layout-shell.ts +159 -13
  102. package/src/patterns/UiProfileCard/UiProfileCard.stories.ts +13 -6
  103. package/src/patterns/UiTopBar/UiTopBar.stories.ts +245 -36
  104. package/src/patterns/UiTopBar/UiTopBar.vue +4 -2
  105. package/src/patterns/UiTopBar/accessory-dropdown.ts +99 -0
@@ -1,7 +1,13 @@
1
1
  import type { Meta, StoryObj } from '@storybook/vue3-vite';
2
- import { fn } from 'storybook/test';
3
- import { ref } from 'vue';
4
- import { showSnackbar, showSnackbarPromise, UiSnackbar } from './index';
2
+ import { expect, fn, userEvent, waitFor, within } from 'storybook/test';
3
+ import { onUnmounted, ref } from 'vue';
4
+ import {
5
+ showSnackbar,
6
+ showSnackbarPromise,
7
+ toast,
8
+ UiSnackbar,
9
+ UiSnackbarContent,
10
+ } from './index';
5
11
  import { UiButton } from '../UiButton';
6
12
  import { UiDialog, UiDialogContent, UiDialogTrigger } from '../UiDialog';
7
13
 
@@ -55,6 +61,10 @@ const SNACKBAR_ACTION_TITLE = 'Event has been created';
55
61
  const SNACKBAR_DESCRIPTION = 'Sunday, December 03, 2023 at 9:00 AM';
56
62
  const SNACKBAR_ACTION_LABEL = 'Undo';
57
63
 
64
+ // Module-level spy shared by every story with a play function that asserts
65
+ // the action callback; each play clears it first so runs stay independent.
66
+ const onAction = fn();
67
+
58
68
  const defaultTemplateSource = `<script setup lang="ts">
59
69
  import { UiSnackbar, showSnackbar, UiButton } from '@aleph-alpha/ui-library'
60
70
  </script>
@@ -82,6 +92,10 @@ export const Default: Story = {
82
92
  render: (args) => ({
83
93
  components: { UiSnackbar, UiButton },
84
94
  setup() {
95
+ // The play leaves a toast mounted for the axe audit and the Chromatic
96
+ // snapshot (duration: Infinity keeps it deterministic); Sonner's
97
+ // module-level toast state is cleared again on story teardown.
98
+ onUnmounted(() => toast.dismiss());
85
99
  const toasterId = 'story-default';
86
100
  const show = () =>
87
101
  showSnackbar({
@@ -91,6 +105,7 @@ export const Default: Story = {
91
105
  actionMode: 'default',
92
106
  iconMode: 'info',
93
107
  onAction: fn(),
108
+ duration: Infinity,
94
109
  toasterId,
95
110
  });
96
111
  return { args, show, toasterId };
@@ -107,6 +122,51 @@ export const Default: Story = {
107
122
  source: { code: defaultTemplateSource },
108
123
  },
109
124
  },
125
+ play: async ({ canvasElement, step }) => {
126
+ // Scenario (UiSnackbar + showSnackbar): a pointer user triggers the
127
+ // full-featured snackbar, reads it, and dismisses it from its close
128
+ // control.
129
+ const canvas = within(canvasElement);
130
+
131
+ await step(
132
+ 'interaction: the snackbar appears with its message',
133
+ async () => {
134
+ await userEvent.click(
135
+ canvas.getByRole('button', { name: 'Show snackbar' }),
136
+ );
137
+ // The toast fades in, so wait for the entry transition before
138
+ // asserting visibility.
139
+ await waitFor(async () => {
140
+ await expect(canvas.getByText(SNACKBAR_ACTION_TITLE)).toBeVisible();
141
+ await expect(canvas.getByText(SNACKBAR_DESCRIPTION)).toBeVisible();
142
+ });
143
+ },
144
+ );
145
+
146
+ await step(
147
+ 'interaction: the dismiss control removes the snackbar',
148
+ async () => {
149
+ await userEvent.click(
150
+ canvas.getByRole('button', { name: 'Close toast' }),
151
+ );
152
+ await waitFor(async () => {
153
+ await expect(canvas.queryByText(SNACKBAR_ACTION_TITLE)).toBeNull();
154
+ });
155
+ },
156
+ );
157
+
158
+ await step(
159
+ 'interaction: the snackbar stays mounted for the accessibility audit',
160
+ async () => {
161
+ await userEvent.click(
162
+ canvas.getByRole('button', { name: 'Show snackbar' }),
163
+ );
164
+ await waitFor(async () => {
165
+ await expect(canvas.getByText(SNACKBAR_ACTION_TITLE)).toBeVisible();
166
+ });
167
+ },
168
+ );
169
+ },
110
170
  };
111
171
 
112
172
  const withDescriptionTemplateSource = `<script setup lang="ts">
@@ -133,11 +193,16 @@ export const WithDescription: Story = {
133
193
  render: (args) => ({
134
194
  components: { UiSnackbar, UiButton },
135
195
  setup() {
196
+ // The play leaves a toast mounted for the axe audit and the Chromatic
197
+ // snapshot (duration: Infinity keeps it deterministic); Sonner's
198
+ // module-level toast state is cleared again on story teardown.
199
+ onUnmounted(() => toast.dismiss());
136
200
  const toasterId = 'story-description';
137
201
  const show = () =>
138
202
  showSnackbar({
139
203
  title: 'Event has been created',
140
204
  description: 'Sunday, December 03, 2023 at 9:00 AM',
205
+ duration: Infinity,
141
206
  toasterId,
142
207
  });
143
208
  return { args, show, toasterId };
@@ -154,6 +219,57 @@ export const WithDescription: Story = {
154
219
  source: { code: withDescriptionTemplateSource },
155
220
  },
156
221
  },
222
+ play: async ({ canvasElement, step }) => {
223
+ // Scenario (UiSnackbar + showSnackbar): the text-only snackbar (Sonner's
224
+ // native rendering path) announces title and description, and dismisses
225
+ // from the native close control.
226
+ const canvas = within(canvasElement);
227
+
228
+ await step(
229
+ 'interaction: the snackbar appears with its title and description',
230
+ async () => {
231
+ await userEvent.click(
232
+ canvas.getByRole('button', { name: 'Show snackbar' }),
233
+ );
234
+ // The toast fades in, so wait for the entry transition before
235
+ // asserting visibility.
236
+ await waitFor(async () => {
237
+ await expect(
238
+ canvas.getByText('Event has been created'),
239
+ ).toBeVisible();
240
+ await expect(
241
+ canvas.getByText('Sunday, December 03, 2023 at 9:00 AM'),
242
+ ).toBeVisible();
243
+ });
244
+ },
245
+ );
246
+
247
+ await step(
248
+ 'interaction: the dismiss control removes the snackbar',
249
+ async () => {
250
+ await userEvent.click(
251
+ canvas.getByRole('button', { name: 'Close toast' }),
252
+ );
253
+ await waitFor(async () => {
254
+ await expect(canvas.queryByText('Event has been created')).toBeNull();
255
+ });
256
+ },
257
+ );
258
+
259
+ await step(
260
+ 'interaction: the snackbar stays mounted for the accessibility audit',
261
+ async () => {
262
+ await userEvent.click(
263
+ canvas.getByRole('button', { name: 'Show snackbar' }),
264
+ );
265
+ await waitFor(async () => {
266
+ await expect(
267
+ canvas.getByText('Event has been created'),
268
+ ).toBeVisible();
269
+ });
270
+ },
271
+ );
272
+ },
157
273
  };
158
274
 
159
275
  const withIconModesTemplateSource = `<script setup lang="ts">
@@ -227,6 +343,233 @@ export const IconModes: Story = {
227
343
  },
228
344
  };
229
345
 
346
+ type ShowSnackbarStoryOptions = Parameters<typeof showSnackbar>[0];
347
+
348
+ /**
349
+ * Render factory for the individual state stories: one trigger that opens a
350
+ * single snackbar with the given options. The play leaves the toast mounted
351
+ * so Chromatic and the axe audit check the rendered state (`duration:
352
+ * Infinity` keeps it deterministic); Sonner's module-level toast state is
353
+ * cleared again on story teardown.
354
+ * @param toasterId Unique Sonner toaster id so stories do not share toasts.
355
+ * @param options `showSnackbar` options for the rendered state.
356
+ */
357
+ function renderStateSnackbar(
358
+ toasterId: string,
359
+ options: Omit<ShowSnackbarStoryOptions, 'toasterId' | 'duration'>,
360
+ ) {
361
+ return (args: Story['args']) => ({
362
+ components: { UiSnackbar, UiButton },
363
+ setup() {
364
+ onUnmounted(() => toast.dismiss());
365
+ const show = () =>
366
+ showSnackbar({ ...options, duration: Infinity, toasterId });
367
+ return { args, show, toasterId };
368
+ },
369
+ template: `
370
+ <div>
371
+ <UiButton @click="show">Show snackbar</UiButton>
372
+ <UiSnackbar v-bind="args" :id="toasterId" />
373
+ </div>
374
+ `,
375
+ });
376
+ }
377
+
378
+ /**
379
+ * Opens a state story's snackbar and waits for its message, leaving the toast
380
+ * mounted for the Chromatic snapshot and the axe audit.
381
+ * @param canvas Testing-library queries scoped to the story canvas.
382
+ */
383
+ async function openStateSnackbar(canvas: ReturnType<typeof within>) {
384
+ await userEvent.click(canvas.getByRole('button', { name: 'Show snackbar' }));
385
+ // The toast fades in, so wait for the entry transition.
386
+ await waitFor(async () => {
387
+ await expect(canvas.getByText(SNACKBAR_ACTION_TITLE)).toBeVisible();
388
+ });
389
+ }
390
+
391
+ const successTemplateSource = `<script setup lang="ts">
392
+ import { UiSnackbar, showSnackbar, UiButton } from '@aleph-alpha/ui-library'
393
+ </script>
394
+
395
+ <template>
396
+ <UiButton
397
+ @click="showSnackbar({
398
+ title: '${SNACKBAR_ACTION_TITLE}',
399
+ iconMode: 'success',
400
+ })"
401
+ >
402
+ Show snackbar
403
+ </UiButton>
404
+ <UiSnackbar />
405
+ </template>`;
406
+
407
+ /**
408
+ * Success state with its status icon, rendered mounted so visual and
409
+ * accessibility checks exercise it independently of the grouped `IconModes`
410
+ * demo.
411
+ */
412
+ export const Success: Story = {
413
+ render: renderStateSnackbar('story-success', {
414
+ title: SNACKBAR_ACTION_TITLE,
415
+ iconMode: 'success',
416
+ }),
417
+ parameters: {
418
+ docs: {
419
+ source: { code: successTemplateSource },
420
+ },
421
+ },
422
+ play: async ({ canvasElement, step }) => {
423
+ const canvas = within(canvasElement);
424
+ await step(
425
+ 'interaction: the success snackbar renders its labelled status icon',
426
+ async () => {
427
+ await openStateSnackbar(canvas);
428
+ await expect(
429
+ canvas.getByRole('img', { name: 'Success' }),
430
+ ).toHaveAttribute('data-mode', 'success');
431
+ },
432
+ );
433
+ },
434
+ };
435
+
436
+ const warningTemplateSource = `<script setup lang="ts">
437
+ import { UiSnackbar, showSnackbar, UiButton } from '@aleph-alpha/ui-library'
438
+ </script>
439
+
440
+ <template>
441
+ <UiButton
442
+ @click="showSnackbar({
443
+ title: '${SNACKBAR_ACTION_TITLE}',
444
+ iconMode: 'warning',
445
+ })"
446
+ >
447
+ Show snackbar
448
+ </UiButton>
449
+ <UiSnackbar />
450
+ </template>`;
451
+
452
+ /**
453
+ * Warning state with its status icon, rendered mounted so visual and
454
+ * accessibility checks exercise it independently of the grouped `IconModes`
455
+ * demo.
456
+ */
457
+ export const Warning: Story = {
458
+ render: renderStateSnackbar('story-warning', {
459
+ title: SNACKBAR_ACTION_TITLE,
460
+ iconMode: 'warning',
461
+ }),
462
+ parameters: {
463
+ docs: {
464
+ source: { code: warningTemplateSource },
465
+ },
466
+ },
467
+ play: async ({ canvasElement, step }) => {
468
+ const canvas = within(canvasElement);
469
+ await step(
470
+ 'interaction: the warning snackbar renders its labelled status icon',
471
+ async () => {
472
+ await openStateSnackbar(canvas);
473
+ await expect(
474
+ canvas.getByRole('img', { name: 'Warning' }),
475
+ ).toHaveAttribute('data-mode', 'warning');
476
+ },
477
+ );
478
+ },
479
+ };
480
+
481
+ const errorTemplateSource = `<script setup lang="ts">
482
+ import { UiSnackbar, showSnackbar, UiButton } from '@aleph-alpha/ui-library'
483
+ </script>
484
+
485
+ <template>
486
+ <UiButton
487
+ @click="showSnackbar({
488
+ title: '${SNACKBAR_ACTION_TITLE}',
489
+ iconMode: 'error',
490
+ })"
491
+ >
492
+ Show snackbar
493
+ </UiButton>
494
+ <UiSnackbar />
495
+ </template>`;
496
+
497
+ /**
498
+ * Error state with its status icon, rendered mounted so visual and
499
+ * accessibility checks exercise it independently of the grouped `IconModes`
500
+ * demo.
501
+ */
502
+ export const ErrorState: Story = {
503
+ name: 'Error',
504
+ render: renderStateSnackbar('story-error', {
505
+ title: SNACKBAR_ACTION_TITLE,
506
+ iconMode: 'error',
507
+ }),
508
+ parameters: {
509
+ docs: {
510
+ source: { code: errorTemplateSource },
511
+ },
512
+ },
513
+ play: async ({ canvasElement, step }) => {
514
+ const canvas = within(canvasElement);
515
+ await step(
516
+ 'interaction: the error snackbar renders its labelled status icon',
517
+ async () => {
518
+ await openStateSnackbar(canvas);
519
+ await expect(
520
+ canvas.getByRole('img', { name: 'Error' }),
521
+ ).toHaveAttribute('data-mode', 'error');
522
+ },
523
+ );
524
+ },
525
+ };
526
+
527
+ const loadingTemplateSource = `<script setup lang="ts">
528
+ import { UiSnackbar, showSnackbar, UiButton } from '@aleph-alpha/ui-library'
529
+ </script>
530
+
531
+ <template>
532
+ <UiButton
533
+ @click="showSnackbar({
534
+ title: '${SNACKBAR_ACTION_TITLE}',
535
+ iconMode: 'loading',
536
+ })"
537
+ >
538
+ Show snackbar
539
+ </UiButton>
540
+ <UiSnackbar />
541
+ </template>`;
542
+
543
+ /**
544
+ * Loading state with its spinner, rendered mounted so visual and
545
+ * accessibility checks exercise it independently of the grouped `IconModes`
546
+ * and transient `Promise` demos. The spinner is a `status` role so assistive
547
+ * technology announces the ongoing operation.
548
+ */
549
+ export const Loading: Story = {
550
+ render: renderStateSnackbar('story-loading', {
551
+ title: SNACKBAR_ACTION_TITLE,
552
+ iconMode: 'loading',
553
+ }),
554
+ parameters: {
555
+ docs: {
556
+ source: { code: loadingTemplateSource },
557
+ },
558
+ },
559
+ play: async ({ canvasElement, step }) => {
560
+ const canvas = within(canvasElement);
561
+ await step(
562
+ 'interaction: the loading snackbar renders its announced spinner',
563
+ async () => {
564
+ await openStateSnackbar(canvas);
565
+ await expect(
566
+ canvas.getByRole('status', { name: 'Loading' }),
567
+ ).toHaveAttribute('data-mode', 'loading');
568
+ },
569
+ );
570
+ },
571
+ };
572
+
230
573
  const withActionModesTemplateSource = `<script setup lang="ts">
231
574
  import { UiSnackbar, showSnackbar, UiButton } from '@aleph-alpha/ui-library'
232
575
  </script>
@@ -299,6 +642,62 @@ export const ActionModes: Story = {
299
642
  },
300
643
  };
301
644
 
645
+ const secondaryActionTemplateSource = `<script setup lang="ts">
646
+ import { UiSnackbar, showSnackbar, UiButton } from '@aleph-alpha/ui-library'
647
+ </script>
648
+
649
+ <template>
650
+ <UiButton
651
+ @click="showSnackbar({
652
+ title: '${SNACKBAR_ACTION_TITLE}',
653
+ actionLabel: '${SNACKBAR_ACTION_LABEL}',
654
+ actionMode: 'secondary',
655
+ onAction: () => {},
656
+ })"
657
+ >
658
+ Show snackbar
659
+ </UiButton>
660
+ <UiSnackbar />
661
+ </template>`;
662
+
663
+ /**
664
+ * Secondary action button mode, rendered mounted so visual and accessibility
665
+ * checks exercise it independently of the grouped `ActionModes` demo. For the
666
+ * default action mode see `WithAction`.
667
+ */
668
+ export const SecondaryAction: Story = {
669
+ render: renderStateSnackbar('story-secondary-action', {
670
+ title: SNACKBAR_ACTION_TITLE,
671
+ actionLabel: SNACKBAR_ACTION_LABEL,
672
+ actionMode: 'secondary',
673
+ onAction: () => onAction(),
674
+ }),
675
+ parameters: {
676
+ docs: {
677
+ source: {
678
+ code: secondaryActionTemplateSource,
679
+ },
680
+ },
681
+ },
682
+ play: async ({ canvasElement, step }) => {
683
+ onAction.mockClear();
684
+ const canvas = within(canvasElement);
685
+ await step(
686
+ 'interaction: the secondary action renders and invokes its handler',
687
+ async () => {
688
+ await openStateSnackbar(canvas);
689
+ const undo = canvas.getByRole('button', {
690
+ name: SNACKBAR_ACTION_LABEL,
691
+ });
692
+ await expect(undo).toBeVisible();
693
+ await userEvent.click(undo);
694
+ await expect(onAction).toHaveBeenCalledTimes(1);
695
+ await expect(canvas.getByText(SNACKBAR_ACTION_TITLE)).toBeVisible();
696
+ },
697
+ );
698
+ },
699
+ };
700
+
302
701
  const withActionTemplateSource = `<script setup lang="ts">
303
702
  import { UiSnackbar, showSnackbar, UiButton } from '@aleph-alpha/ui-library'
304
703
  </script>
@@ -325,13 +724,18 @@ export const WithAction: Story = {
325
724
  render: (args) => ({
326
725
  components: { UiSnackbar, UiButton },
327
726
  setup() {
727
+ // The play leaves a toast mounted for the axe audit and the Chromatic
728
+ // snapshot (duration: Infinity keeps it deterministic); Sonner's
729
+ // module-level toast state is cleared again on story teardown.
730
+ onUnmounted(() => toast.dismiss());
328
731
  const toasterId = 'story-action';
329
732
  const show = () =>
330
733
  showSnackbar({
331
734
  title: SNACKBAR_ACTION_TITLE,
332
735
  actionLabel: SNACKBAR_ACTION_LABEL,
333
736
  actionMode: 'default',
334
- onAction: fn(),
737
+ onAction: () => onAction(),
738
+ duration: Infinity,
335
739
  toasterId,
336
740
  });
337
741
  return { args, show, toasterId };
@@ -348,6 +752,104 @@ export const WithAction: Story = {
348
752
  source: { code: withActionTemplateSource },
349
753
  },
350
754
  },
755
+ play: async ({ canvasElement, step }) => {
756
+ // Scenario (UiSnackbar + showSnackbar + UiSnackbarContent): a pointer
757
+ // user triggers the action snackbar, invokes Undo, and dismisses the
758
+ // snackbar from its embedded close control.
759
+ onAction.mockClear();
760
+ const canvas = within(canvasElement);
761
+
762
+ await step(
763
+ 'interaction: the built-in action invokes its handler',
764
+ async () => {
765
+ await userEvent.click(
766
+ canvas.getByRole('button', { name: 'Show snackbar' }),
767
+ );
768
+ // The toast fades in, so wait for the entry transition before
769
+ // asserting visibility.
770
+ await waitFor(async () => {
771
+ await expect(canvas.getByText(SNACKBAR_ACTION_TITLE)).toBeVisible();
772
+ });
773
+
774
+ await userEvent.click(
775
+ canvas.getByRole('button', { name: SNACKBAR_ACTION_LABEL }),
776
+ );
777
+ await expect(onAction).toHaveBeenCalledTimes(1);
778
+ },
779
+ );
780
+
781
+ await step(
782
+ 'interaction: the action snackbar dismisses from its own close control',
783
+ async () => {
784
+ await userEvent.click(
785
+ canvas.getByRole('button', { name: 'Close toast' }),
786
+ );
787
+ await waitFor(async () => {
788
+ await expect(canvas.queryByText(SNACKBAR_ACTION_TITLE)).toBeNull();
789
+ });
790
+ },
791
+ );
792
+
793
+ await step(
794
+ 'interaction: the snackbar stays mounted for the accessibility audit',
795
+ async () => {
796
+ await userEvent.click(
797
+ canvas.getByRole('button', { name: 'Show snackbar' }),
798
+ );
799
+ await waitFor(async () => {
800
+ await expect(canvas.getByText(SNACKBAR_ACTION_TITLE)).toBeVisible();
801
+ });
802
+ },
803
+ );
804
+ },
805
+ };
806
+
807
+ const withoutCloseButtonTemplateSource = `<script setup lang="ts">
808
+ import { UiSnackbar, showSnackbar, UiButton } from '@aleph-alpha/ui-library'
809
+ </script>
810
+
811
+ <template>
812
+ <UiButton
813
+ @click="showSnackbar({
814
+ title: '${SNACKBAR_ACTION_TITLE}',
815
+ closeButton: false,
816
+ })"
817
+ >
818
+ Show snackbar
819
+ </UiButton>
820
+ <UiSnackbar />
821
+ </template>`;
822
+
823
+ /**
824
+ * Snackbar without a dismiss control (`closeButton: false`), rendered mounted
825
+ * so visual and accessibility checks exercise it independently. Reserve this
826
+ * for auto-dismissing confirmations; keep the close control whenever the
827
+ * message carries an action or stays longer.
828
+ */
829
+ export const WithoutCloseButton: Story = {
830
+ render: renderStateSnackbar('story-no-close', {
831
+ title: SNACKBAR_ACTION_TITLE,
832
+ closeButton: false,
833
+ }),
834
+ parameters: {
835
+ docs: {
836
+ source: {
837
+ code: withoutCloseButtonTemplateSource,
838
+ },
839
+ },
840
+ },
841
+ play: async ({ canvasElement, step }) => {
842
+ const canvas = within(canvasElement);
843
+ await step(
844
+ 'interaction: the snackbar renders without a dismiss control',
845
+ async () => {
846
+ await openStateSnackbar(canvas);
847
+ await expect(
848
+ canvas.queryByRole('button', { name: 'Close toast' }),
849
+ ).toBeNull();
850
+ },
851
+ );
852
+ },
351
853
  };
352
854
 
353
855
  const promiseTemplateSource = `<script setup lang="ts">
@@ -532,3 +1034,586 @@ export const WithDialog: Story = {
532
1034
  },
533
1035
  },
534
1036
  };
1037
+
1038
+ /**
1039
+ * Accessibility guidance for conveying outcomes without relying on colour,
1040
+ * comfortable targets, generous timing, and the accessible theme.
1041
+ */
1042
+ export const Accessibility: Story = {
1043
+ render: () => ({
1044
+ components: { UiSnackbarContent },
1045
+ setup() {
1046
+ const noop = () => {};
1047
+ return { noop };
1048
+ },
1049
+ template: `
1050
+ <section class="flex w-full flex-col gap-6 p-4">
1051
+ <h2 class="heading-m font-bold text-content-on-surface-primary">
1052
+ Accessibility
1053
+ </h2>
1054
+
1055
+ <div class="flex flex-col gap-2">
1056
+ <h3 class="body-16-medium text-content-on-surface-primary">
1057
+ Requirements
1058
+ </h3>
1059
+ <ul class="body-16-regular flex list-disc flex-col gap-1 pl-6 text-content-on-surface-primary">
1060
+ <li>The outcome is carried by the icon and the words, so colour is never the only signal</li>
1061
+ <li>Success, error and warning are distinguishable by icon shape, not only by hue</li>
1062
+ <li>Text holds contrast against the snackbar's own surface, which sits over arbitrary content</li>
1063
+ <li>The action is a comfortable target and keeps a visible focus state</li>
1064
+ <li>The snackbar stays long enough to be read unhurriedly, and longer when it carries an action</li>
1065
+ <li>Anything important is also available in the interface, since a snackbar is easy to miss</li>
1066
+ </ul>
1067
+ </div>
1068
+
1069
+ <div class="flex flex-col gap-2">
1070
+ <h3 class="body-16-medium text-content-on-surface-primary">
1071
+ Enable accessibility theme
1072
+ </h3>
1073
+ <p class="body-16-regular text-content-on-surface-primary">
1074
+ When accessibility is required, enable our accessibility theme.
1075
+ This increases contrast and ensures there are no color contrast
1076
+ issues.
1077
+ </p>
1078
+ </div>
1079
+
1080
+ <div class="grid gap-4 md:grid-cols-2">
1081
+ <div class="flex flex-col gap-3">
1082
+ <h3 class="label-16-medium text-center text-content-on-surface-primary">
1083
+ Default
1084
+ </h3>
1085
+ <div class="flex justify-center border border-border-surface-default p-6">
1086
+ <div class="flex w-full max-w-sm items-center rounded border border-border-surface-default bg-background-surface-floating p-4 pl-5 shadow-[0px_4px_24px_0px_#00000033]">
1087
+ <UiSnackbarContent
1088
+ embedded
1089
+ title="Title Text"
1090
+ description="This is a toast description."
1091
+ icon-mode="success"
1092
+ action-label="Undo"
1093
+ :on-close-toast="noop"
1094
+ />
1095
+ </div>
1096
+ </div>
1097
+ </div>
1098
+
1099
+ <div class="accessible-theme flex flex-col gap-3">
1100
+ <h3 class="label-16-medium text-center text-content-on-surface-primary">
1101
+ Accessible
1102
+ </h3>
1103
+ <div class="flex justify-center border border-border-surface-default p-6">
1104
+ <div class="flex w-full max-w-sm items-center rounded border border-border-surface-default bg-background-surface-floating p-4 pl-5 shadow-[0px_4px_24px_0px_#00000033]">
1105
+ <UiSnackbarContent
1106
+ embedded
1107
+ title="Title Text"
1108
+ description="This is a toast description."
1109
+ icon-mode="success"
1110
+ action-label="Undo"
1111
+ :on-close-toast="noop"
1112
+ />
1113
+ </div>
1114
+ </div>
1115
+ </div>
1116
+ </div>
1117
+ </section>
1118
+ `,
1119
+ }),
1120
+ tags: ['!autodocs'],
1121
+ parameters: {
1122
+ a11y: { test: 'off' },
1123
+ chromatic: {
1124
+ disableSnapshot: true,
1125
+ },
1126
+ docs: {
1127
+ canvas: {
1128
+ sourceState: 'none',
1129
+ },
1130
+ },
1131
+ },
1132
+ };
1133
+
1134
+ /*
1135
+ * ─────────────────────────────────────────────────────────────────────────────
1136
+ * Interaction & accessibility tests (play functions)
1137
+ * ─────────────────────────────────────────────────────────────────────────────
1138
+ * The stories below are hidden from the sidebar and the docs page but still run
1139
+ * in the Storybook test-runner on every PR, alongside the axe audit. The
1140
+ * `interaction:` checks (message, dismissal, action callback, state rendering)
1141
+ * are co-located on the visible stories above, per TESTING.md; only the
1142
+ * keyboard, screen-reader, zoom, and mobile flows live here. The `step()`
1143
+ * prefix is parsed into the CI report, so keep it accurate:
1144
+ * • `interaction:` behaviour and guards (WCAG 4.1.2)
1145
+ * • `keyboard:` focus order and activation (WCAG 2.1.1, 2.4.3)
1146
+ * • `screen-reader:` names, roles and states (WCAG 4.1.2)
1147
+ * • `zoom:` operable when magnified (WCAG 1.4.4)
1148
+ * • `mobile:` 320px reflow and target size (WCAG 1.4.10, 2.5.8)
1149
+ * The Accessibility column is filled automatically by the axe audit — never add
1150
+ * an `a11y:` prefix.
1151
+ *
1152
+ * Snackbars are status messages: the toast region is a *polite* live region
1153
+ * (`aria-live="polite"`), so messages wait for the screen reader to finish
1154
+ * speaking. Assertive, interrupt-now messaging belongs to `UiAlert`
1155
+ * (`role="alert"`), which is why no story here asserts assertive semantics.
1156
+ * The test runner's `postVisit` hook runs the axe audit on whatever the play
1157
+ * leaves rendered, so every play ends by reopening both rendering paths
1158
+ * (Sonner's native toast and the custom `UiSnackbarContent`) after the
1159
+ * dismissal assertions — otherwise the audit would only ever see an empty
1160
+ * toaster. The fixture dismisses all toasts again on story teardown.
1161
+ */
1162
+
1163
+ /**
1164
+ * The fixture the test stories drive: one trigger for a text-only snackbar
1165
+ * (Sonner's native close control) and one for a custom snackbar with a status
1166
+ * icon and an Undo action (`UiSnackbarContent`'s embedded close control).
1167
+ * `duration: Infinity` keeps auto-dismiss out of the assertions — the plays
1168
+ * dismiss explicitly and leave reopened toasts mounted for the axe audit, so
1169
+ * the fixture clears Sonner's module-level toast state on story teardown to
1170
+ * keep stories independent.
1171
+ * @param toasterId Unique Sonner toaster id so stories do not share toasts.
1172
+ * @returns Vue component options for a story `render` function.
1173
+ */
1174
+ function renderTestSnackbar(toasterId: string) {
1175
+ return {
1176
+ components: { UiSnackbar, UiButton },
1177
+ setup() {
1178
+ // Teardown, not pre-audit cleanup: toasts stay mounted when the play
1179
+ // returns so the postVisit axe audit checks rendered snackbar content.
1180
+ onUnmounted(() => toast.dismiss());
1181
+ const showMessage = () =>
1182
+ showSnackbar({
1183
+ title: 'Draft saved',
1184
+ description: 'Stored in your workspace just now.',
1185
+ duration: Infinity,
1186
+ toasterId,
1187
+ });
1188
+ const showActionSnackbar = () =>
1189
+ showSnackbar({
1190
+ title: 'Event has been created',
1191
+ iconMode: 'success',
1192
+ actionLabel: 'Undo',
1193
+ onAction: () => onAction(),
1194
+ duration: Infinity,
1195
+ toasterId,
1196
+ });
1197
+ return { showMessage, showActionSnackbar, toasterId };
1198
+ },
1199
+ template: `
1200
+ <div class="flex flex-wrap items-center gap-2">
1201
+ <UiButton @click="showMessage">Show message</UiButton>
1202
+ <UiButton @click="showActionSnackbar">Show action snackbar</UiButton>
1203
+ <UiSnackbar :id="toasterId" />
1204
+ </div>
1205
+ `,
1206
+ };
1207
+ }
1208
+
1209
+ /**
1210
+ * Reopens both snackbar rendering paths — the native text-only toast and the
1211
+ * custom `UiSnackbarContent` with icon and action — and waits for them, so the
1212
+ * axe audit that the test runner's `postVisit` hook performs after the play
1213
+ * checks rendered snackbar content instead of an empty toaster. The fixture
1214
+ * dismisses them again on story teardown.
1215
+ * @param canvas Testing-library queries scoped to the story canvas.
1216
+ */
1217
+ async function leaveSnackbarsMountedForAudit(
1218
+ canvas: ReturnType<typeof within>,
1219
+ ) {
1220
+ await userEvent.click(canvas.getByRole('button', { name: 'Show message' }));
1221
+ await userEvent.click(
1222
+ canvas.getByRole('button', { name: 'Show action snackbar' }),
1223
+ );
1224
+ await waitFor(async () => {
1225
+ await expect(canvas.getByText('Draft saved')).toBeVisible();
1226
+ await expect(canvas.getByText('Event has been created')).toBeVisible();
1227
+ });
1228
+ }
1229
+
1230
+ /**
1231
+ * Presses Tab until the given element has focus, proving it is reachable from
1232
+ * the keyboard regardless of where Sonner restores focus after a dismissal.
1233
+ * @param element Element that must receive focus.
1234
+ * @param maxTabs Upper bound of Tab presses before failing.
1235
+ */
1236
+ async function tabTo(element: HTMLElement, maxTabs = 6) {
1237
+ for (let i = 0; i < maxTabs; i += 1) {
1238
+ await userEvent.tab();
1239
+ if (document.activeElement === element) return;
1240
+ }
1241
+ throw new Error('Element was not reached with Tab');
1242
+ }
1243
+
1244
+ /**
1245
+ * The dismiss control and the built-in action are reachable with Tab and
1246
+ * operable with Enter and Space. Hidden test-only story.
1247
+ */
1248
+ export const KeyboardNavigation: Story = {
1249
+ name: 'test - Keyboard Navigation',
1250
+ tags: ['!dev', '!autodocs'],
1251
+ parameters: {
1252
+ // Focus moves and toasts appear and disappear during the play function.
1253
+ chromatic: { disableSnapshot: true },
1254
+ docs: {
1255
+ description: {
1256
+ story:
1257
+ 'Press `Tab` to reach the snackbar and its dismiss control, then `Enter` or `Space` to activate it.',
1258
+ },
1259
+ },
1260
+ },
1261
+ render: () => renderTestSnackbar('test-keyboard'),
1262
+ play: async ({ canvasElement, step }) => {
1263
+ // Scenario (UiSnackbar + showSnackbar + UiSnackbarContent): a keyboard user
1264
+ // triggers a snackbar, tabs into it, dismisses it with Enter, and drives
1265
+ // the Undo action and the embedded close control of a second one.
1266
+ onAction.mockClear();
1267
+ const canvas = within(canvasElement);
1268
+
1269
+ await step(
1270
+ 'keyboard: Tab reaches the trigger and Enter shows the snackbar',
1271
+ async () => {
1272
+ await userEvent.tab();
1273
+ await expect(
1274
+ canvas.getByRole('button', { name: 'Show message' }),
1275
+ ).toHaveFocus();
1276
+ await userEvent.keyboard('{Enter}');
1277
+ await waitFor(async () => {
1278
+ await expect(canvas.getByText('Draft saved')).toBeVisible();
1279
+ });
1280
+ },
1281
+ );
1282
+
1283
+ await step(
1284
+ 'keyboard: the dismiss control is reachable with Tab (WCAG 2.1.1)',
1285
+ async () => {
1286
+ const close = canvas.getByRole('button', { name: 'Close toast' });
1287
+ await tabTo(close);
1288
+ await expect(close).toHaveFocus();
1289
+ },
1290
+ );
1291
+
1292
+ await step(
1293
+ 'keyboard: Enter on the dismiss control removes the snackbar',
1294
+ async () => {
1295
+ await userEvent.keyboard('{Enter}');
1296
+ await waitFor(async () => {
1297
+ await expect(canvas.queryByText('Draft saved')).toBeNull();
1298
+ });
1299
+ },
1300
+ );
1301
+
1302
+ await step(
1303
+ 'keyboard: the action snackbar opens and its action activates with Enter',
1304
+ async () => {
1305
+ const actionTrigger = canvas.getByRole('button', {
1306
+ name: 'Show action snackbar',
1307
+ });
1308
+ await tabTo(actionTrigger);
1309
+ await userEvent.keyboard(' ');
1310
+ await waitFor(async () => {
1311
+ await expect(
1312
+ canvas.getByText('Event has been created'),
1313
+ ).toBeVisible();
1314
+ });
1315
+
1316
+ const undo = canvas.getByRole('button', { name: 'Undo' });
1317
+ await tabTo(undo);
1318
+ await userEvent.keyboard('{Enter}');
1319
+ await expect(onAction).toHaveBeenCalled();
1320
+ },
1321
+ );
1322
+
1323
+ await step(
1324
+ 'keyboard: Space on the embedded dismiss control removes the snackbar',
1325
+ async () => {
1326
+ const close = canvas.getByRole('button', { name: 'Close toast' });
1327
+ await userEvent.tab();
1328
+ await expect(close).toHaveFocus();
1329
+ await userEvent.keyboard(' ');
1330
+ await userEvent.keyboard(' ');
1331
+ await waitFor(async () => {
1332
+ await expect(canvas.queryByText('Event has been created')).toBeNull();
1333
+ });
1334
+ },
1335
+ );
1336
+
1337
+ await step(
1338
+ 'interaction: both rendering paths stay mounted for the accessibility audit',
1339
+ async () => {
1340
+ await leaveSnackbarsMountedForAudit(canvas);
1341
+ },
1342
+ );
1343
+ },
1344
+ };
1345
+
1346
+ /**
1347
+ * Screen-reader semantics: a polite live region announcing messages as status
1348
+ * (not alert), a named dismiss control, and a status icon that keeps the
1349
+ * outcome off colour alone. Hidden test-only story.
1350
+ */
1351
+ export const ScreenReader: Story = {
1352
+ name: 'test - Screen Reader',
1353
+ tags: ['!dev', '!autodocs'],
1354
+ parameters: {
1355
+ // Toasts appear and disappear during the play function.
1356
+ chromatic: { disableSnapshot: true },
1357
+ docs: {
1358
+ description: {
1359
+ story:
1360
+ 'Verifies polite live-region semantics (status rather than alert), the named dismiss control, and the announced status icon.',
1361
+ },
1362
+ },
1363
+ },
1364
+ render: () => renderTestSnackbar('test-screen-reader'),
1365
+ play: async ({ canvasElement, step }) => {
1366
+ // Scenario (UiSnackbar + showSnackbar + UiSnackbarContent + UiSnackbarIcon):
1367
+ // assistive tech hears new snackbars politely once the current speech
1368
+ // finishes, finds a named dismiss control, and gets the outcome from the
1369
+ // labelled status icon as well as the words.
1370
+ const canvas = within(canvasElement);
1371
+ const region = canvas.getByLabelText(/Notifications/);
1372
+
1373
+ await step(
1374
+ 'screen-reader: the toast region is a polite live region — status, not alert (WCAG 4.1.3)',
1375
+ async () => {
1376
+ // Snackbars report outcomes that already happened, so they must not
1377
+ // interrupt. Assertive, interrupt-now messaging is UiAlert's job.
1378
+ await expect(region).toHaveAttribute('aria-live', 'polite');
1379
+ await expect(region).toHaveAttribute('aria-relevant', 'additions text');
1380
+ },
1381
+ );
1382
+
1383
+ await step(
1384
+ 'screen-reader: the message is announced from inside the live region',
1385
+ async () => {
1386
+ await userEvent.click(
1387
+ canvas.getByRole('button', { name: 'Show message' }),
1388
+ );
1389
+ const title = await canvas.findByText('Draft saved');
1390
+ await expect(region.contains(title)).toBe(true);
1391
+ await waitFor(async () => {
1392
+ await expect(
1393
+ canvas.getByText('Stored in your workspace just now.'),
1394
+ ).toBeVisible();
1395
+ });
1396
+ },
1397
+ );
1398
+
1399
+ await step(
1400
+ 'screen-reader: the dismiss control has an accessible name (WCAG 4.1.2)',
1401
+ async () => {
1402
+ const close = canvas.getByRole('button', { name: 'Close toast' });
1403
+ await expect(close).toBeVisible();
1404
+ await userEvent.click(close);
1405
+ await waitFor(async () => {
1406
+ await expect(canvas.queryByText('Draft saved')).toBeNull();
1407
+ });
1408
+ },
1409
+ );
1410
+
1411
+ await step(
1412
+ 'screen-reader: the status icon is announced, so the outcome is not colour-only (WCAG 1.4.1)',
1413
+ async () => {
1414
+ await userEvent.click(
1415
+ canvas.getByRole('button', { name: 'Show action snackbar' }),
1416
+ );
1417
+ await canvas.findByText('Event has been created');
1418
+ const icon = canvas.getByRole('img', { name: 'Success' });
1419
+ await expect(icon).toHaveAttribute('data-mode', 'success');
1420
+ await waitFor(async () => {
1421
+ await expect(
1422
+ canvas.getByRole('button', { name: 'Undo' }),
1423
+ ).toBeVisible();
1424
+ });
1425
+ },
1426
+ );
1427
+
1428
+ await step(
1429
+ 'screen-reader: dismissing removes the message from the live region',
1430
+ async () => {
1431
+ await userEvent.click(
1432
+ canvas.getByRole('button', { name: 'Close toast' }),
1433
+ );
1434
+ await waitFor(async () => {
1435
+ await expect(canvas.queryByText('Event has been created')).toBeNull();
1436
+ });
1437
+ },
1438
+ );
1439
+
1440
+ await step(
1441
+ 'interaction: both rendering paths stay mounted for the accessibility audit',
1442
+ async () => {
1443
+ await leaveSnackbarsMountedForAudit(canvas);
1444
+ },
1445
+ );
1446
+ },
1447
+ };
1448
+
1449
+ /**
1450
+ * Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
1451
+ * try 400% reflow (WCAG 1.4.10); the snackbar must stay readable and its
1452
+ * dismiss control operable. Hidden test-only story.
1453
+ */
1454
+ export const ZoomMagnification: Story = {
1455
+ name: 'test - Zoom Magnification',
1456
+ tags: ['!dev', '!autodocs'],
1457
+ globals: { zoom: '200' },
1458
+ parameters: {
1459
+ // Zoom changes the layout scale; the accessible-reflow Chromatic mode
1460
+ // already covers magnified snapshots, so skip this one.
1461
+ chromatic: { disableSnapshot: true },
1462
+ docs: {
1463
+ description: {
1464
+ story:
1465
+ 'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
1466
+ },
1467
+ },
1468
+ },
1469
+ render: () => renderTestSnackbar('test-zoom'),
1470
+ play: async ({ canvasElement, step }) => {
1471
+ // Scenario (UiSnackbar + showSnackbar): at 200% page zoom the snackbar
1472
+ // stays inside the viewport, its message stays readable, and the dismiss
1473
+ // control still works.
1474
+ const canvas = within(canvasElement);
1475
+
1476
+ await step(
1477
+ 'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
1478
+ async () => {
1479
+ await expect(document.documentElement.style.zoom).toBe('200%');
1480
+ },
1481
+ );
1482
+
1483
+ await step(
1484
+ 'zoom: the snackbar stays visible and inside the viewport',
1485
+ async () => {
1486
+ await userEvent.click(
1487
+ canvas.getByRole('button', { name: 'Show message' }),
1488
+ );
1489
+ await waitFor(async () => {
1490
+ await expect(canvas.getByText('Draft saved')).toBeVisible();
1491
+ });
1492
+
1493
+ const toast = canvasElement.querySelector('[data-sonner-toast]');
1494
+ await expect(toast).not.toBeNull();
1495
+ const { left, right } = (toast as HTMLElement).getBoundingClientRect();
1496
+ await expect(left).toBeGreaterThanOrEqual(0);
1497
+ await expect(right).toBeLessThanOrEqual(window.innerWidth + 1);
1498
+ },
1499
+ );
1500
+
1501
+ await step('zoom: the dismiss control remains operable', async () => {
1502
+ await userEvent.click(
1503
+ canvas.getByRole('button', { name: 'Close toast' }),
1504
+ );
1505
+ await waitFor(async () => {
1506
+ await expect(canvas.queryByText('Draft saved')).toBeNull();
1507
+ });
1508
+ });
1509
+
1510
+ await step(
1511
+ 'interaction: both rendering paths stay mounted for the accessibility audit',
1512
+ async () => {
1513
+ await leaveSnackbarsMountedForAudit(canvas);
1514
+ },
1515
+ );
1516
+ },
1517
+ };
1518
+
1519
+ /**
1520
+ * Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
1521
+ * toolbar. The snackbar fits the viewport and its dismiss and action controls
1522
+ * meet the minimum touch-target size (WCAG 2.5.8). Hidden test-only story.
1523
+ */
1524
+ export const MobileBreakpoint: Story = {
1525
+ name: 'test - Mobile Breakpoint',
1526
+ tags: ['!dev', '!autodocs'],
1527
+ globals: { mediaBreakpoint: 'reflow' },
1528
+ parameters: {
1529
+ // Reflow snapshots are already covered by the accessible-reflow mode.
1530
+ chromatic: { disableSnapshot: true },
1531
+ docs: {
1532
+ description: {
1533
+ story:
1534
+ 'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
1535
+ },
1536
+ },
1537
+ },
1538
+ render: () => renderTestSnackbar('test-mobile'),
1539
+ play: async ({ canvasElement, step }) => {
1540
+ // Scenario (UiSnackbar + showSnackbar + UiSnackbarContent): on a 320px
1541
+ // viewport the snackbar reflows inside the screen and both the Undo action
1542
+ // and the dismiss control are big enough to tap.
1543
+ const canvas = within(canvasElement);
1544
+
1545
+ await step(
1546
+ 'mobile: the snackbar fits the 320px viewport without sideways scrolling (WCAG 1.4.10 Reflow)',
1547
+ async () => {
1548
+ await userEvent.click(
1549
+ canvas.getByRole('button', { name: 'Show action snackbar' }),
1550
+ );
1551
+ await waitFor(async () => {
1552
+ await expect(
1553
+ canvas.getByText('Event has been created'),
1554
+ ).toBeVisible();
1555
+ });
1556
+
1557
+ const toast = canvasElement.querySelector('[data-sonner-toast]');
1558
+ await expect(toast).not.toBeNull();
1559
+ const { left, right } = (toast as HTMLElement).getBoundingClientRect();
1560
+ await expect(left).toBeGreaterThanOrEqual(0);
1561
+ await expect(right).toBeLessThanOrEqual(window.innerWidth + 1);
1562
+ },
1563
+ );
1564
+
1565
+ await step(
1566
+ 'mobile: dismiss and action meet the minimum touch-target size (WCAG 2.5.8)',
1567
+ async () => {
1568
+ // The close control measures exactly 24px (`size-6`), the 2.5.8 floor:
1569
+ // shrinking it again would drop the dismiss below conformance.
1570
+ for (const name of ['Close toast', 'Undo']) {
1571
+ const { width, height } = canvas
1572
+ .getByRole('button', { name })
1573
+ .getBoundingClientRect();
1574
+ await expect(width).toBeGreaterThanOrEqual(24);
1575
+ await expect(height).toBeGreaterThanOrEqual(24);
1576
+ }
1577
+ },
1578
+ );
1579
+
1580
+ await step(
1581
+ 'mobile: tapping the dismiss control removes the snackbar',
1582
+ async () => {
1583
+ await userEvent.click(
1584
+ canvas.getByRole('button', { name: 'Close toast' }),
1585
+ );
1586
+ await waitFor(async () => {
1587
+ await expect(canvas.queryByText('Event has been created')).toBeNull();
1588
+ });
1589
+ },
1590
+ );
1591
+
1592
+ await step(
1593
+ 'mobile: the native dismiss control is at least 24px and remains operable',
1594
+ async () => {
1595
+ await userEvent.click(
1596
+ canvas.getByRole('button', { name: 'Show message' }),
1597
+ );
1598
+ await waitFor(async () => {
1599
+ await expect(canvas.getByText('Draft saved')).toBeVisible();
1600
+ });
1601
+ const close = canvas.getByRole('button', { name: 'Close toast' });
1602
+ const { width, height } = close.getBoundingClientRect();
1603
+ await expect(width).toBeGreaterThanOrEqual(24);
1604
+ await expect(height).toBeGreaterThanOrEqual(24);
1605
+ await userEvent.click(close);
1606
+ await waitFor(async () => {
1607
+ await expect(canvas.queryByText('Draft saved')).toBeNull();
1608
+ });
1609
+ },
1610
+ );
1611
+
1612
+ await step(
1613
+ 'interaction: both rendering paths stay mounted for the accessibility audit',
1614
+ async () => {
1615
+ await leaveSnackbarsMountedForAudit(canvas);
1616
+ },
1617
+ );
1618
+ },
1619
+ };