@aleph-alpha/ui-library 6.0.0 → 6.1.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 (40) hide show
  1. package/config.d.ts +28 -4
  2. package/config.js +99 -23
  3. package/dist/system/components/UiTagsInput/UiTagsInput.vue.d.ts +2 -0
  4. package/dist/system/components/UiTagsInput/UiTagsInputItemDelete.vue.d.ts +2 -1
  5. package/dist/system/components/UiTagsInput/types.d.ts +21 -2
  6. package/dist/system/components/core/tags-input/TagsInputItemDelete.vue.d.ts +5 -0
  7. package/dist/system/icons/story-sidebar-icons.json +7 -0
  8. package/dist/system/lib.js +1752 -1708
  9. package/dist/system/story-sidebar-icons.json +7 -0
  10. package/docs/public-docs/migration-guide.md +402 -0
  11. package/docs/public-docs/quick-start.md +19 -10
  12. package/package.json +4 -1
  13. package/src/components/UiAlert/UiAlert.stories.ts +732 -0
  14. package/src/components/UiAlert/__tests__/UiAlert.test.ts +57 -11
  15. package/src/components/UiChip/UiChip.stories.ts +756 -2
  16. package/src/components/UiChip/UiChip.vue +7 -6
  17. package/src/components/UiChip/__tests__/UiChip.test.ts +38 -61
  18. package/src/components/UiDrawer/UiDrawer.stories.ts +665 -0
  19. package/src/components/UiDrawer/__tests__/UiDrawer.test.ts +6 -190
  20. package/src/components/UiLabel/UiLabel.stories.ts +691 -16
  21. package/src/components/UiLabel/__tests__/UiLabel.test.ts +18 -26
  22. package/src/components/UiSheet/UiSheet.stories.ts +751 -0
  23. package/src/components/UiSheet/__tests__/UiSheet.test.ts +6 -190
  24. package/src/components/UiSlider/UiSlider.stories.ts +716 -0
  25. package/src/components/UiSlider/__tests__/UiSlider.test.ts +8 -45
  26. package/src/components/UiSwitch/UiSwitch.stories.ts +11 -5
  27. package/src/components/UiTagsInput/UiTagsInput.stories.ts +850 -4
  28. package/src/components/UiTagsInput/UiTagsInput.vue +34 -0
  29. package/src/components/UiTagsInput/UiTagsInputItemDelete.vue +4 -1
  30. package/src/components/UiTagsInput/__tests__/UiTagsInput.test.ts +113 -29
  31. package/src/components/UiTagsInput/types.ts +24 -2
  32. package/src/components/core/sheet/SheetContent.vue +6 -1
  33. package/src/components/core/switch/index.ts +8 -7
  34. package/src/components/core/tags-input/TagsInput.vue +4 -1
  35. package/src/components/core/tags-input/TagsInputItem.vue +13 -1
  36. package/src/components/core/tags-input/TagsInputItemDelete.vue +40 -7
  37. package/src/theme/Typography.stories.ts +125 -133
  38. package/tokens.json +8132 -2475
  39. package/dist/system/icons/mobile-device-frame.png +0 -0
  40. package/dist/system/mobile-device-frame.png +0 -0
@@ -1,5 +1,8 @@
1
1
  import type { Meta, StoryObj } from '@storybook/vue3-vite';
2
+ import { expect, fn, userEvent, waitFor, within } from 'storybook/test';
3
+ import { ref } from 'vue';
2
4
  import { UiAlert, UiAlertDescription, UiAlertTitle } from './index';
5
+ import { UiButton } from '../UiButton';
3
6
  import { AlertVariants } from './constants';
4
7
 
5
8
  /**
@@ -27,6 +30,12 @@ export default meta;
27
30
 
28
31
  type Story = StoryObj<typeof UiAlert>;
29
32
 
33
+ // `UiAlert` has no events of its own — dismissal is composed by the consumer —
34
+ // so these module-level spies are bound to the composed actions in the test
35
+ // template and `mockClear()`ed at the start of each play function.
36
+ const onDismiss = fn();
37
+ const onShow = fn();
38
+
30
39
  const defaultTemplateSource = `<script setup lang="ts">
31
40
  import { UiAlert, UiAlertDescription, UiAlertTitle } from '@aleph-alpha/ui-library'
32
41
  </script>
@@ -69,6 +78,44 @@ export const Default: Story = {
69
78
  },
70
79
  },
71
80
  },
81
+ play: async ({ canvasElement, step }) => {
82
+ // Scenario (UiAlert + UiAlertTitle + UiAlertDescription): assistive tech
83
+ // finds a live region whose announcement carries both the title and the
84
+ // description. Nothing here mutates the DOM, so the snapshot stays valid.
85
+ const canvas = within(canvasElement);
86
+ const alert = canvas.getByRole('alert');
87
+
88
+ await step(
89
+ 'screen-reader: the message exposes an alert role (WCAG 4.1.2)',
90
+ async () => {
91
+ await expect(alert).toBeVisible();
92
+ await expect(alert).toHaveAttribute('role', 'alert');
93
+ },
94
+ );
95
+
96
+ await step(
97
+ 'screen-reader: the announcement includes the title and the description',
98
+ async () => {
99
+ await expect(alert).toHaveTextContent(
100
+ 'Success! Your changes have been saved',
101
+ );
102
+ await expect(alert).toHaveTextContent(
103
+ 'This is an alert with icon, title and description.',
104
+ );
105
+ },
106
+ );
107
+
108
+ await step(
109
+ 'interaction: the alert is a static region, not an interactive widget',
110
+ async () => {
111
+ // `role="alert"` is a live region. It must not be focusable or offer
112
+ // controls of its own — anything actionable is composed by the
113
+ // consumer, as the Dismissible story shows.
114
+ await expect(alert).not.toHaveAttribute('tabindex');
115
+ await expect(canvas.queryByRole('button')).not.toBeInTheDocument();
116
+ },
117
+ );
118
+ },
72
119
  };
73
120
 
74
121
  const destructiveTemplateSource = `<script setup lang="ts">
@@ -120,6 +167,39 @@ export const Destructive: Story = {
120
167
  },
121
168
  },
122
169
  },
170
+ play: async ({ canvasElement, step }) => {
171
+ // Scenario (UiAlert variant="destructive"): the error is announced as an
172
+ // alert, and its severity is carried by the wording rather than by the red
173
+ // styling or the icon alone. Non-mutating, so the snapshot stays valid.
174
+ const canvas = within(canvasElement);
175
+ const alert = canvas.getByRole('alert');
176
+
177
+ await step(
178
+ 'screen-reader: the destructive alert exposes an alert role (WCAG 4.1.2)',
179
+ async () => {
180
+ await expect(alert).toBeVisible();
181
+ await expect(alert).toHaveAttribute('role', 'alert');
182
+ },
183
+ );
184
+
185
+ await step(
186
+ 'screen-reader: severity is conveyed in the text, not by colour alone (WCAG 1.4.1)',
187
+ async () => {
188
+ await expect(alert).toHaveTextContent('Unable to process your payment');
189
+ },
190
+ );
191
+
192
+ await step(
193
+ 'screen-reader: the variant icon is decorative and stays out of the announcement',
194
+ async () => {
195
+ // `UiIcon` sets `aria-hidden` whenever it has no `ariaLabel`, so the
196
+ // variant glyph never adds noise to the assertive announcement.
197
+ const icon = alert.querySelector('svg');
198
+ await expect(icon).not.toBeNull();
199
+ await expect(icon).toHaveAttribute('aria-hidden', 'true');
200
+ },
201
+ );
202
+ },
123
203
  };
124
204
 
125
205
  const allVariantsTemplateSource = `<script setup lang="ts">
@@ -189,4 +269,656 @@ export const AllVariants: Story = {
189
269
  },
190
270
  },
191
271
  },
272
+ play: async ({ canvasElement, step }) => {
273
+ // Scenario (UiAlert): both variants render as separate live regions, so a
274
+ // screen reader announces each message on its own. Non-mutating.
275
+ const canvas = within(canvasElement);
276
+
277
+ await step(
278
+ 'screen-reader: each variant is announced as its own alert region (WCAG 4.1.2)',
279
+ async () => {
280
+ const alerts = canvas.getAllByRole('alert');
281
+ await expect(alerts).toHaveLength(AlertVariants.length);
282
+ for (const alert of alerts) {
283
+ await expect(alert).toBeVisible();
284
+ }
285
+ },
286
+ );
287
+ },
288
+ };
289
+
290
+ const dismissibleTemplateSource = `<script setup lang="ts">
291
+ import {
292
+ UiAlert,
293
+ UiAlertDescription,
294
+ UiAlertTitle,
295
+ UiButton,
296
+ } from '@aleph-alpha/ui-library'
297
+ import { ref } from 'vue'
298
+
299
+ const visible = ref(true)
300
+ </script>
301
+
302
+ <template>
303
+ <div class="flex flex-col gap-4">
304
+ <UiButton v-if="!visible" variant="outline" @click="visible = true">
305
+ Show alert
306
+ </UiButton>
307
+
308
+ <UiAlert v-if="visible">
309
+ <UiAlertTitle>Success! Your changes have been saved</UiAlertTitle>
310
+ <UiAlertDescription>
311
+ Your profile is now up to date.
312
+ </UiAlertDescription>
313
+ <!--
314
+ Actions live in the content column (\`col-start-2\`) so they line up
315
+ under the description instead of the icon gutter.
316
+ -->
317
+ <div class="col-start-2 mt-2 flex gap-2">
318
+ <UiButton size="sm" variant="outline" @click="visible = false">
319
+ Dismiss
320
+ </UiButton>
321
+ </div>
322
+ </UiAlert>
323
+ </div>
324
+ </template>`;
325
+
326
+ /**
327
+ * `UiAlert` has no built-in dismiss, so dismissal is composed: render the alert
328
+ * behind a flag and drop it when the action fires. Prefer a labelled text
329
+ * button over an icon-only X — it is self-describing, and at `size="sm"` it is
330
+ * 24px tall, which is exactly the minimum touch-target size.
331
+ */
332
+ export const Dismissible: Story = {
333
+ render: () => renderTestAlert(),
334
+ parameters: {
335
+ controls: { disable: true },
336
+ docs: {
337
+ source: {
338
+ code: dismissibleTemplateSource,
339
+ },
340
+ },
341
+ },
342
+ play: async ({ canvasElement, step }) => {
343
+ // Scenario (UiAlert + composed action): the message is on screen with a
344
+ // reachable, self-describing dismiss control. The dismiss flow itself lives
345
+ // in the test-only stories so this snapshot keeps showing the alert.
346
+ const canvas = within(canvasElement);
347
+ const alert = canvas.getByRole('alert');
348
+ const dismiss = canvas.getByRole('button', { name: 'Dismiss' });
349
+
350
+ await step('interaction: the alert content is visible', async () => {
351
+ await expect(alert).toBeVisible();
352
+ await expect(alert).toHaveTextContent(
353
+ 'Success! Your changes have been saved',
354
+ );
355
+ });
356
+
357
+ await step(
358
+ 'interaction: a dismiss control is offered and enabled',
359
+ async () => {
360
+ await expect(dismiss).toBeVisible();
361
+ await expect(dismiss).toBeEnabled();
362
+ },
363
+ );
364
+
365
+ await step(
366
+ 'screen-reader: the dismiss control names itself (WCAG 4.1.2)',
367
+ async () => {
368
+ await expect(dismiss).toHaveAccessibleName('Dismiss');
369
+ },
370
+ );
371
+ },
372
+ };
373
+
374
+ /**
375
+ * Accessibility guidance for announcing alerts, conveying severity without
376
+ * relying on colour, composing a dismiss control, and contrast.
377
+ */
378
+ export const Accessibility: Story = {
379
+ render: () => ({
380
+ components: {
381
+ UiAlert,
382
+ UiAlertDescription,
383
+ UiAlertTitle,
384
+ },
385
+ template: `
386
+ <section class="flex flex-col gap-6 p-4">
387
+ <div>
388
+ <h2 class="heading-m font-bold text-content-on-surface-primary">
389
+ Accessibility
390
+ </h2>
391
+ </div>
392
+
393
+ <div class="flex flex-col gap-6">
394
+ <div class="flex flex-col gap-2">
395
+ <h3 class="body-16-medium text-content-on-surface-primary">
396
+ Mount the alert to announce it
397
+ </h3>
398
+ <p class="body-16-regular text-content-on-surface-primary">
399
+ <code>UiAlert</code> renders <code>role="alert"</code>, which is
400
+ an assertive live region. Screen readers announce it when it
401
+ enters the page, so render it in response to the event it reports
402
+ rather than leaving it mounted and swapping its text. An alert
403
+ that is already on screen at page load is read as ordinary
404
+ content, not announced.
405
+ </p>
406
+ </div>
407
+
408
+ <div class="flex flex-col gap-2">
409
+ <h3 class="body-16-medium text-content-on-surface-primary">
410
+ Don't rely on colour or the icon
411
+ </h3>
412
+ <p class="body-16-regular text-content-on-surface-primary">
413
+ The variant icon is decorative — <code>UiIcon</code> marks it
414
+ <code>aria-hidden</code> unless you give it an
415
+ <code>ariaLabel</code> — and the destructive styling is colour
416
+ only. Say what happened in the text so the severity survives
417
+ without either (WCAG 1.4.1).
418
+ </p>
419
+ </div>
420
+
421
+ <div class="flex flex-col gap-2">
422
+ <h3 class="body-16-medium text-content-on-surface-primary">
423
+ Keep announcements short
424
+ </h3>
425
+ <p class="body-16-regular text-content-on-surface-primary">
426
+ An alert is atomic: the whole region is read as one
427
+ announcement, including anything interactive inside it. Keep the
428
+ title and description tight, and don't pack an alert with several
429
+ controls.
430
+ </p>
431
+ </div>
432
+
433
+ <div class="flex flex-col gap-2">
434
+ <h3 class="body-16-medium text-content-on-surface-primary">
435
+ Compose dismissal with a labelled button
436
+ </h3>
437
+ <p class="body-16-regular text-content-on-surface-primary">
438
+ There is no built-in dismiss. Add your own control in the content
439
+ column and prefer visible text such as <code>Dismiss</code> over
440
+ an icon-only X: it names itself and it is reachable with
441
+ <code>Tab</code>. Note that <code>size="sm"</code> is exactly
442
+ 24px tall — the minimum touch-target size — so don't go smaller.
443
+ See the Dismissible story.
444
+ </p>
445
+ </div>
446
+
447
+ <div class="flex flex-col gap-2">
448
+ <h3 class="body-16-medium text-content-on-surface-primary">
449
+ Enable accessibility theme
450
+ </h3>
451
+ <p class="body-16-regular text-content-on-surface-primary">
452
+ When accessibility is required, enable our accessibility theme.
453
+ This increases contrast and makes sure there are no color
454
+ contrast issues.
455
+ </p>
456
+ </div>
457
+ </div>
458
+
459
+ <div class="grid gap-4 md:grid-cols-2">
460
+ <div class="flex flex-col gap-3">
461
+ <h3 class="label-16-medium text-center text-content-on-surface-primary">
462
+ Default
463
+ </h3>
464
+ <div class="flex flex-col gap-3 border border-border-surface-default p-6">
465
+ <UiAlert>
466
+ <UiAlertTitle>Success! Your changes have been saved</UiAlertTitle>
467
+ <UiAlertDescription>
468
+ Your profile is now up to date.
469
+ </UiAlertDescription>
470
+ </UiAlert>
471
+ <UiAlert variant="destructive">
472
+ <UiAlertTitle>Unable to process your payment.</UiAlertTitle>
473
+ <UiAlertDescription>
474
+ Please verify your billing information and try again.
475
+ </UiAlertDescription>
476
+ </UiAlert>
477
+ </div>
478
+ </div>
479
+
480
+ <div class="accessible-theme flex flex-col gap-3">
481
+ <h3 class="label-16-medium text-center text-content-on-surface-primary">
482
+ Accessible
483
+ </h3>
484
+ <div class="flex flex-col gap-3 border border-border-surface-default p-6">
485
+ <UiAlert>
486
+ <UiAlertTitle>Success! Your changes have been saved</UiAlertTitle>
487
+ <UiAlertDescription>
488
+ Your profile is now up to date.
489
+ </UiAlertDescription>
490
+ </UiAlert>
491
+ <UiAlert variant="destructive">
492
+ <UiAlertTitle>Unable to process your payment.</UiAlertTitle>
493
+ <UiAlertDescription>
494
+ Please verify your billing information and try again.
495
+ </UiAlertDescription>
496
+ </UiAlert>
497
+ </div>
498
+ </div>
499
+ </div>
500
+ </section>
501
+ `,
502
+ }),
503
+ tags: ['!autodocs'],
504
+ parameters: {
505
+ a11y: { test: 'off' },
506
+ chromatic: {
507
+ disableSnapshot: true,
508
+ },
509
+ docs: {
510
+ canvas: {
511
+ sourceState: 'none',
512
+ },
513
+ },
514
+ },
515
+ };
516
+
517
+ /*
518
+ * ─────────────────────────────────────────────────────────────────────────────
519
+ * Interaction & accessibility tests (play functions)
520
+ * ─────────────────────────────────────────────────────────────────────────────
521
+ * The stories below are hidden from the sidebar and the docs page but still run
522
+ * in the Storybook test-runner on every PR, alongside the axe audit. The
523
+ * `step()` prefix is parsed into the CI report, so keep it accurate:
524
+ * • `interaction:` behaviour and guards (WCAG 4.1.2)
525
+ * • `keyboard:` focus order and activation (WCAG 2.1.1, 2.4.3)
526
+ * • `screen-reader:` names, roles and states (WCAG 4.1.2)
527
+ * • `zoom:` operable when magnified (WCAG 1.4.4)
528
+ * • `mobile:` 320px reflow and target size (WCAG 1.4.10, 2.5.8)
529
+ * The Accessibility column is filled automatically by the axe audit — never add
530
+ * an `a11y:` prefix.
531
+ *
532
+ * `UiAlert` is presentational: it has no focusable target and no dismiss of its
533
+ * own, so the `interaction:`, `keyboard:`, and `mobile:` columns are covered
534
+ * two ways. The plain-alert stories assert the *absence* of interactive
535
+ * behaviour (not a tab stop, no controls), and the stories below drive the
536
+ * composed dismiss pattern from `Dismissible`, which is the only place an
537
+ * action exists. `UiAlertTitle` and `UiAlertDescription` are covered through
538
+ * the announcement text they contribute to the region.
539
+ */
540
+
541
+ /**
542
+ * The alert the test stories drive: the `Dismissible` composition, whose flag
543
+ * lets a play function remove the alert and mount it again — the same remount
544
+ * that triggers an assertive announcement.
545
+ * @returns Vue component options for a story `render` function.
546
+ */
547
+ function renderTestAlert() {
548
+ return {
549
+ components: {
550
+ UiAlert,
551
+ UiAlertDescription,
552
+ UiAlertTitle,
553
+ UiButton,
554
+ },
555
+ setup() {
556
+ const visible = ref(true);
557
+ return { visible, onDismiss, onShow };
558
+ },
559
+ template: `
560
+ <div class="flex flex-col gap-4">
561
+ <UiButton
562
+ v-if="!visible"
563
+ variant="outline"
564
+ @click="visible = true; onShow()"
565
+ >
566
+ Show alert
567
+ </UiButton>
568
+
569
+ <UiAlert v-if="visible">
570
+ <UiAlertTitle>Success! Your changes have been saved</UiAlertTitle>
571
+ <UiAlertDescription>
572
+ Your profile is now up to date.
573
+ </UiAlertDescription>
574
+ <div class="col-start-2 mt-2 flex gap-2">
575
+ <UiButton
576
+ size="sm"
577
+ variant="outline"
578
+ @click="visible = false; onDismiss()"
579
+ >
580
+ Dismiss
581
+ </UiButton>
582
+ </div>
583
+ </UiAlert>
584
+ </div>
585
+ `,
586
+ };
587
+ }
588
+
589
+ /**
590
+ * Dismissing the alert removes it, and it can be brought back. Hidden test-only
591
+ * story.
592
+ */
593
+ export const DismissInteraction: Story = {
594
+ name: 'test - Dismiss Interaction',
595
+ tags: ['!dev', '!autodocs'],
596
+ parameters: {
597
+ // The alert is removed and remounted during the play function.
598
+ chromatic: { disableSnapshot: true },
599
+ docs: {
600
+ description: {
601
+ story:
602
+ 'Click Dismiss to remove the alert, then Show alert to mount it again.',
603
+ },
604
+ },
605
+ },
606
+ render: () => renderTestAlert(),
607
+ play: async ({ canvasElement, step }) => {
608
+ // Scenario (UiAlert + composed action): a pointer user reads the alert,
609
+ // dismisses it, and can bring it back — the remount being what makes a
610
+ // screen reader announce it again.
611
+ onDismiss.mockClear();
612
+ onShow.mockClear();
613
+ const canvas = within(canvasElement);
614
+
615
+ await step('interaction: the alert content is visible', async () => {
616
+ await expect(canvas.getByRole('alert')).toBeVisible();
617
+ });
618
+
619
+ await step(
620
+ 'interaction: the dismiss control removes the alert',
621
+ async () => {
622
+ await userEvent.click(canvas.getByRole('button', { name: 'Dismiss' }));
623
+ await expect(onDismiss).toHaveBeenCalled();
624
+ await waitFor(async () => {
625
+ await expect(canvas.queryByRole('alert')).toBeNull();
626
+ });
627
+ },
628
+ );
629
+
630
+ await step(
631
+ 'interaction: mounting the alert again restores its content',
632
+ async () => {
633
+ await userEvent.click(
634
+ canvas.getByRole('button', { name: 'Show alert' }),
635
+ );
636
+ await expect(onShow).toHaveBeenCalled();
637
+ const alert = await canvas.findByRole('alert');
638
+ await expect(alert).toHaveTextContent(
639
+ 'Success! Your changes have been saved',
640
+ );
641
+ },
642
+ );
643
+ },
644
+ };
645
+
646
+ /**
647
+ * The alert region is skipped by Tab while its composed action is reachable and
648
+ * operable from the keyboard. Hidden test-only story.
649
+ */
650
+ export const KeyboardNavigation: Story = {
651
+ name: 'test - Keyboard Navigation',
652
+ tags: ['!dev', '!autodocs'],
653
+ parameters: {
654
+ // Focus moves and the alert is removed during the play function.
655
+ chromatic: { disableSnapshot: true },
656
+ docs: {
657
+ description: {
658
+ story:
659
+ 'Press `Tab` to reach the dismiss control, then `Enter` or `Space` to activate it.',
660
+ },
661
+ },
662
+ },
663
+ render: () => renderTestAlert(),
664
+ play: async ({ canvasElement, step }) => {
665
+ // Scenario (UiAlert + composed action): a keyboard user tabs straight past
666
+ // the static region to the dismiss control, activates it with Enter, and
667
+ // brings the alert back with Space.
668
+ onDismiss.mockClear();
669
+ onShow.mockClear();
670
+ const canvas = within(canvasElement);
671
+ const alert = canvas.getByRole('alert');
672
+
673
+ await step(
674
+ 'keyboard: the static alert region is not a tab stop (WCAG 2.1.1)',
675
+ async () => {
676
+ // The first Tab lands on the composed action, which proves the live
677
+ // region itself was skipped rather than focused.
678
+ await expect(alert).not.toHaveAttribute('tabindex');
679
+ await userEvent.tab();
680
+ await expect(
681
+ canvas.getByRole('button', { name: 'Dismiss' }),
682
+ ).toHaveFocus();
683
+ },
684
+ );
685
+
686
+ await step(
687
+ 'keyboard: Enter activates the focused dismiss control',
688
+ async () => {
689
+ await userEvent.keyboard('{Enter}');
690
+ await expect(onDismiss).toHaveBeenCalled();
691
+ await waitFor(async () => {
692
+ await expect(canvas.queryByRole('alert')).toBeNull();
693
+ });
694
+ },
695
+ );
696
+
697
+ await step(
698
+ 'keyboard: the replacement control is reachable and Space activates it',
699
+ async () => {
700
+ const show = await canvas.findByRole('button', { name: 'Show alert' });
701
+ await userEvent.tab();
702
+ await expect(show).toHaveFocus();
703
+ await userEvent.keyboard(' ');
704
+ await expect(onShow).toHaveBeenCalled();
705
+ await expect(await canvas.findByRole('alert')).toBeVisible();
706
+ },
707
+ );
708
+ },
709
+ };
710
+
711
+ /**
712
+ * Screen-reader semantics: an assertive live region that announces when it
713
+ * mounts, with a decorative icon and a named action (WCAG 4.1.2). Hidden
714
+ * test-only story.
715
+ */
716
+ export const ScreenReader: Story = {
717
+ name: 'test - Screen Reader',
718
+ tags: ['!dev', '!autodocs'],
719
+ parameters: {
720
+ // The alert is removed and remounted during the play function.
721
+ chromatic: { disableSnapshot: true },
722
+ docs: {
723
+ description: {
724
+ story:
725
+ 'Verifies the alert role, its assertive live-region semantics, and the announcement fired by mounting.',
726
+ },
727
+ },
728
+ },
729
+ render: () => renderTestAlert(),
730
+ play: async ({ canvasElement, step }) => {
731
+ // Scenario (UiAlert + UiAlertTitle + UiAlertDescription): assistive tech
732
+ // reads the region as an assertive alert, hears title and description as
733
+ // one announcement, and gets a fresh announcement when it is mounted again.
734
+ const canvas = within(canvasElement);
735
+ const alert = canvas.getByRole('alert');
736
+
737
+ await step(
738
+ 'screen-reader: the region exposes an alert role (WCAG 4.1.2)',
739
+ async () => {
740
+ await expect(alert).toHaveAttribute('role', 'alert');
741
+ },
742
+ );
743
+
744
+ await step(
745
+ 'screen-reader: the region stays assertive and atomic',
746
+ async () => {
747
+ // `role="alert"` already implies `aria-live="assertive"` and
748
+ // `aria-atomic="true"`, so the only way to lose the announcement is an
749
+ // explicit override. Guard against one being introduced.
750
+ const live = alert.getAttribute('aria-live');
751
+ await expect(live === null || live === 'assertive').toBe(true);
752
+ const atomic = alert.getAttribute('aria-atomic');
753
+ await expect(atomic === null || atomic === 'true').toBe(true);
754
+ },
755
+ );
756
+
757
+ await step(
758
+ 'screen-reader: title and description are announced together',
759
+ async () => {
760
+ await expect(alert).toHaveTextContent(
761
+ 'Success! Your changes have been saved',
762
+ );
763
+ await expect(alert).toHaveTextContent(
764
+ 'Your profile is now up to date.',
765
+ );
766
+ },
767
+ );
768
+
769
+ await step(
770
+ 'screen-reader: the variant icon is hidden from the announcement',
771
+ async () => {
772
+ const icon = alert.querySelector('svg');
773
+ await expect(icon).not.toBeNull();
774
+ await expect(icon).toHaveAttribute('aria-hidden', 'true');
775
+ },
776
+ );
777
+
778
+ await step(
779
+ 'screen-reader: mounting the alert announces it assertively (WCAG 4.1.3)',
780
+ async () => {
781
+ // An assertive region is only announced when it enters the page or its
782
+ // contents change. Removing and remounting reproduces exactly what a
783
+ // screen reader reacts to; the announcement itself is verified against
784
+ // the platform SR checklist.
785
+ await userEvent.click(canvas.getByRole('button', { name: 'Dismiss' }));
786
+ await waitFor(async () => {
787
+ await expect(canvas.queryByRole('alert')).toBeNull();
788
+ });
789
+
790
+ await userEvent.click(
791
+ canvas.getByRole('button', { name: 'Show alert' }),
792
+ );
793
+ const remounted = await canvas.findByRole('alert');
794
+ await expect(remounted).toHaveAttribute('role', 'alert');
795
+ await expect(remounted).toHaveTextContent(
796
+ 'Success! Your changes have been saved',
797
+ );
798
+ },
799
+ );
800
+ },
801
+ };
802
+
803
+ /**
804
+ * Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
805
+ * try 400% reflow (WCAG 1.4.10); the alert must stay readable and operable.
806
+ * Hidden test-only story.
807
+ */
808
+ export const ZoomMagnification: Story = {
809
+ name: 'test - Zoom Magnification',
810
+ tags: ['!dev', '!autodocs'],
811
+ globals: { zoom: '200' },
812
+ parameters: {
813
+ // Zoom changes the layout scale; the accessible-reflow Chromatic mode
814
+ // already covers magnified snapshots, so skip this one.
815
+ chromatic: { disableSnapshot: true },
816
+ docs: {
817
+ description: {
818
+ story:
819
+ 'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
820
+ },
821
+ },
822
+ },
823
+ render: () => renderTestAlert(),
824
+ play: async ({ canvasElement, step }) => {
825
+ // Scenario (UiAlert + composed action): at 200% page zoom the message stays
826
+ // readable, sits inside the viewport, and its dismiss control still works.
827
+ onDismiss.mockClear();
828
+ const canvas = within(canvasElement);
829
+
830
+ await step(
831
+ 'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
832
+ async () => {
833
+ await expect(document.documentElement.style.zoom).toBe('200%');
834
+ },
835
+ );
836
+
837
+ await step('zoom: the alert stays visible and readable', async () => {
838
+ const alert = canvas.getByRole('alert');
839
+ await expect(alert).toBeVisible();
840
+ await expect(
841
+ canvas.getByText('Success! Your changes have been saved'),
842
+ ).toBeVisible();
843
+ await expect(
844
+ canvas.getByText('Your profile is now up to date.'),
845
+ ).toBeVisible();
846
+
847
+ const { left, right } = alert.getBoundingClientRect();
848
+ await expect(left).toBeGreaterThanOrEqual(0);
849
+ await expect(right).toBeLessThanOrEqual(window.innerWidth + 1);
850
+ });
851
+
852
+ await step('zoom: the dismiss control remains operable', async () => {
853
+ const dismiss = canvas.getByRole('button', { name: 'Dismiss' });
854
+ await expect(dismiss).toBeVisible();
855
+ await userEvent.click(dismiss);
856
+ await expect(onDismiss).toHaveBeenCalled();
857
+ await waitFor(async () => {
858
+ await expect(canvas.queryByRole('alert')).toBeNull();
859
+ });
860
+ });
861
+ },
862
+ };
863
+
864
+ /**
865
+ * Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
866
+ * toolbar. Stays readable, fits the viewport, and its action meets the minimum
867
+ * touch-target size (WCAG 2.5.8). Hidden test-only story.
868
+ */
869
+ export const MobileBreakpoint: Story = {
870
+ name: 'test - Mobile Breakpoint',
871
+ tags: ['!dev', '!autodocs'],
872
+ globals: { mediaBreakpoint: 'reflow' },
873
+ parameters: {
874
+ // Reflow snapshots are already covered by the accessible-reflow mode.
875
+ chromatic: { disableSnapshot: true },
876
+ docs: {
877
+ description: {
878
+ story:
879
+ 'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
880
+ },
881
+ },
882
+ },
883
+ render: () => renderTestAlert(),
884
+ play: async ({ canvasElement, step }) => {
885
+ // Scenario (UiAlert + composed action): at the 320px mobile breakpoint the
886
+ // message reflows inside the viewport and the dismiss control is big
887
+ // enough to tap.
888
+ const canvas = within(canvasElement);
889
+ const alert = canvas.getByRole('alert');
890
+
891
+ await step(
892
+ 'mobile: the alert stays readable at the 320px breakpoint',
893
+ async () => {
894
+ await expect(alert).toBeVisible();
895
+ await expect(
896
+ canvas.getByText('Success! Your changes have been saved'),
897
+ ).toBeVisible();
898
+ },
899
+ );
900
+
901
+ await step(
902
+ 'mobile: the alert fits the 320px viewport without sideways scrolling (WCAG 1.4.10 Reflow)',
903
+ async () => {
904
+ const { left, right } = alert.getBoundingClientRect();
905
+ await expect(left).toBeGreaterThanOrEqual(0);
906
+ await expect(right).toBeLessThanOrEqual(window.innerWidth + 1);
907
+ },
908
+ );
909
+
910
+ await step(
911
+ 'mobile: the dismiss control meets the minimum touch-target size (WCAG 2.5.8)',
912
+ async () => {
913
+ // `UiButton size="sm"` measures exactly 24px tall, so this sits on the
914
+ // 2.5.8 floor with no headroom: shrinking `label-12-medium` or the
915
+ // button's `py-1` would drop the documented pattern below conformance.
916
+ const { width, height } = canvas
917
+ .getByRole('button', { name: 'Dismiss' })
918
+ .getBoundingClientRect();
919
+ await expect(width).toBeGreaterThanOrEqual(24);
920
+ await expect(height).toBeGreaterThanOrEqual(24);
921
+ },
922
+ );
923
+ },
192
924
  };