@aleph-alpha/ui-library 5.5.0 → 5.7.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 (41) hide show
  1. package/config.js +5 -0
  2. package/dist/system/components/UiAutocomplete/UiAutocomplete.vue.d.ts +2 -0
  3. package/dist/system/components/UiButtonGroup/UiButtonGroup.vue.d.ts +20 -0
  4. package/dist/system/components/UiButtonGroup/index.d.ts +2 -0
  5. package/dist/system/components/UiButtonGroup/types.d.ts +20 -0
  6. package/dist/system/components/UiField/types.d.ts +2 -1
  7. package/dist/system/components/core/button-group/ButtonGroup.vue.d.ts +23 -0
  8. package/dist/system/components/core/button-group/ButtonGroupSeparator.vue.d.ts +9 -0
  9. package/dist/system/components/core/button-group/ButtonGroupText.vue.d.ts +26 -0
  10. package/dist/system/components/core/button-group/index.d.ts +8 -0
  11. package/dist/system/components/index.d.ts +1 -0
  12. package/dist/system/lib.js +7855 -7732
  13. package/dist/system/story-sidebar-icons.json +3 -0
  14. package/package.json +5 -5
  15. package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +619 -0
  16. package/src/components/UiAutocomplete/UiAutocomplete.vue +28 -3
  17. package/src/components/UiAutocomplete/__tests__/UiAutocomplete.test.ts +14 -69
  18. package/src/components/UiButtonGroup/UiButtonGroup.stories.ts +690 -0
  19. package/src/components/UiButtonGroup/UiButtonGroup.vue +18 -0
  20. package/src/components/UiButtonGroup/__tests__/UiButtonGroup.test.ts +68 -0
  21. package/src/components/UiButtonGroup/index.ts +2 -0
  22. package/src/components/UiButtonGroup/types.ts +21 -0
  23. package/src/components/UiCheckbox/UiCheckbox.stories.ts +625 -74
  24. package/src/components/UiField/UiField.stories.ts +1 -1
  25. package/src/components/UiField/types.ts +2 -1
  26. package/src/components/UiRadioGroup/UiRadioGroup.stories.ts +995 -0
  27. package/src/components/UiSelect/UiSelect.stories.ts +769 -0
  28. package/src/components/UiSelect/__tests__/UiSelect.test.ts +4 -73
  29. package/src/components/UiSelect/__tests__/UiSelectItem.test.ts +3 -31
  30. package/src/components/UiSelect/__tests__/UiSelectTrigger.test.ts +14 -5
  31. package/src/components/core/button-group/ButtonGroup.vue +24 -0
  32. package/src/components/core/button-group/ButtonGroupSeparator.vue +29 -0
  33. package/src/components/core/button-group/ButtonGroupText.vue +33 -0
  34. package/src/components/core/button-group/index.ts +25 -0
  35. package/src/components/core/field/FieldDescription.vue +1 -1
  36. package/src/components/core/field/FieldLabel.vue +3 -2
  37. package/src/components/core/field/FieldTitle.vue +1 -1
  38. package/src/components/core/select/SelectTrigger.vue +1 -1
  39. package/src/components/index.ts +1 -0
  40. package/src/components/UiCheckbox/__tests__/UiCheckbox.test.ts +0 -14
  41. package/src/components/UiRadioGroup/__tests__/UiRadioGroup.test.ts +0 -412
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "components-uibutton--design-notes": "palette",
3
3
  "components-uibutton--accessibility": "accessibility",
4
+ "components-uibuttongroup--accessibility": "accessibility",
4
5
  "components-uicheckbox--design-notes": "palette",
5
6
  "components-uicheckbox--accessibility": "accessibility",
6
7
  "components-uifield--design-notes": "palette",
@@ -9,6 +10,8 @@
9
10
  "components-uiitem--accessibility": "accessibility",
10
11
  "components-uiinput--design-notes": "palette",
11
12
  "components-uiinput--accessibility": "accessibility",
13
+ "components-uiselect--accessibility": "accessibility",
14
+ "components-uiautocomplete--accessibility": "accessibility",
12
15
  "patterns-uifloatactions--accessibility": "accessibility",
13
16
  "patterns-uidatatable--accessibility": "accessibility"
14
17
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aleph-alpha/ui-library",
3
- "version": "5.5.0",
3
+ "version": "5.7.0",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "dist/system/lib.js",
@@ -82,9 +82,9 @@
82
82
  "vue-router": "4.6.4",
83
83
  "vue-tsc": "^2.2.12",
84
84
  "wait-on": "9.0.3",
85
- "@aleph-alpha/eslint-config-frontend": "0.7.0",
86
- "@aleph-alpha/prettier-config-frontend": "2.1.0",
87
- "@aleph-alpha/tsconfig-frontend": "0.7.1"
85
+ "@aleph-alpha/eslint-config-frontend": "0.7.1",
86
+ "@aleph-alpha/prettier-config-frontend": "2.1.1",
87
+ "@aleph-alpha/tsconfig-frontend": "0.7.2"
88
88
  },
89
89
  "peerDependencies": {
90
90
  "@unocss/preset-wind4": ">=66.0.0",
@@ -117,7 +117,7 @@
117
117
  "shiki": "^3.0.0",
118
118
  "tailwind-merge": "^3.4.0",
119
119
  "vue-sonner": "^2.0.9",
120
- "@aleph-alpha/config-unocss": "0.2.0"
120
+ "@aleph-alpha/config-unocss": "0.2.1"
121
121
  },
122
122
  "jest-junit": {
123
123
  "outputDirectory": "reports/storybook",
@@ -1,4 +1,5 @@
1
1
  import type { Meta, StoryObj } from '@storybook/vue3-vite';
2
+ import { expect, userEvent, waitFor, within } from 'storybook/test';
2
3
  import { ref } from 'vue';
3
4
  import { UiBadge } from '@/components/UiBadge';
4
5
  import { UiCheckbox } from '@/components/UiCheckbox';
@@ -97,6 +98,29 @@ export const Default: Story = {
97
98
  },
98
99
  },
99
100
  },
101
+ play: async ({ canvasElement, step }) => {
102
+ // Scenario (UiAutocomplete): the closed control exposes a labelled text
103
+ // input and a suggestions toggle with popup semantics. Non-mutating checks
104
+ // only, so the story's visual snapshot stays untouched.
105
+ const canvas = within(canvasElement);
106
+
107
+ await step(
108
+ 'interaction: exposes a searchable text input with an accessible name (WCAG 4.1.2)',
109
+ async () => {
110
+ const input = canvas.getByRole('textbox', { name: 'Search fruit' });
111
+ await expect(input).toHaveAttribute('placeholder', 'Search fruit');
112
+ },
113
+ );
114
+
115
+ await step(
116
+ 'screen-reader: the suggestions toggle announces its collapsed popup state',
117
+ async () => {
118
+ const toggle = canvas.getByRole('button', { name: 'Open suggestions' });
119
+ await expect(toggle).toHaveAttribute('aria-haspopup', 'listbox');
120
+ await expect(toggle).toHaveAttribute('aria-expanded', 'false');
121
+ },
122
+ );
123
+ },
100
124
  };
101
125
 
102
126
  const multipleTemplateSource = `<script setup lang="ts">
@@ -157,6 +181,70 @@ export const Multiple: Story = {
157
181
  },
158
182
  };
159
183
 
184
+ const statesTemplateSource = `<script setup lang="ts">
185
+ import { ref } from 'vue'
186
+ import { UiAutocomplete } from '@aleph-alpha/ui-library'
187
+
188
+ const options = [{ value: 'banana', label: 'Banana' }]
189
+
190
+ const emptyValue = ref('')
191
+ const filledValue = ref('banana')
192
+ const disabledValue = ref('')
193
+ </script>
194
+
195
+ <template>
196
+ <div class="flex flex-col gap-4">
197
+ <!-- Default: input surface with muted placeholder text -->
198
+ <UiAutocomplete v-model="emptyValue" :options="options" placeholder="Placeholder" class="w-[220px]" />
199
+
200
+ <!-- Filled: same surface, value rendered in regular text -->
201
+ <UiAutocomplete v-model="filledValue" :options="options" placeholder="Placeholder" class="w-[220px]" />
202
+
203
+ <!-- Disabled -->
204
+ <UiAutocomplete v-model="disabledValue" :options="options" placeholder="Placeholder" disabled class="w-[220px]" />
205
+ </div>
206
+ </template>`;
207
+
208
+ /**
209
+ * The autocomplete's visual states: Default (placeholder), Filled (a chosen
210
+ * value), and Disabled. Default and Filled share the same input surface —
211
+ * only the muted placeholder text switches to regular value text.
212
+ */
213
+ export const States: Story = {
214
+ render: () => ({
215
+ components: { UiAutocomplete },
216
+ setup() {
217
+ const emptyValue = ref('');
218
+ const filledValue = ref('banana');
219
+ const disabledValue = ref('');
220
+ return { emptyValue, filledValue, disabledValue, fruits };
221
+ },
222
+ template: `
223
+ <div class="grid w-fit grid-cols-[auto_220px] items-center gap-x-6 gap-y-4">
224
+ <span class="label-14-medium text-content-on-surface-primary text-right">Default</span>
225
+ <UiAutocomplete v-model="emptyValue" :options="fruits" placeholder="Placeholder" />
226
+
227
+ <span class="label-14-medium text-content-on-surface-primary text-right">Filled</span>
228
+ <UiAutocomplete v-model="filledValue" :options="fruits" placeholder="Placeholder" />
229
+
230
+ <span class="label-14-medium text-content-on-surface-primary text-right">Disabled</span>
231
+ <UiAutocomplete v-model="disabledValue" :options="fruits" placeholder="Placeholder" disabled />
232
+ </div>
233
+ `,
234
+ }),
235
+ parameters: {
236
+ docs: {
237
+ description: {
238
+ story:
239
+ 'Default, Filled, and Disabled states side by side. The focus state is not shown here — it appears on keyboard focus and while the suggestions are open.',
240
+ },
241
+ source: {
242
+ code: statesTemplateSource,
243
+ },
244
+ },
245
+ },
246
+ };
247
+
160
248
  export const WithSlots: Story = {
161
249
  render: () => ({
162
250
  components: { UiAutocomplete },
@@ -307,3 +395,534 @@ export const WithExternalItems: Story = {
307
395
  },
308
396
  },
309
397
  };
398
+
399
+ // Test-only stories drive the test-runner (interactive/a11y checks) but are
400
+ // hidden from the Storybook sidebar and docs via the `!dev` / `!autodocs`
401
+ // tags. They keep the implicit `test` tag, so they still run in CI and appear
402
+ // in the automated report under their `test - …` name. `name`/`tags` must be
403
+ // literal properties so Storybook's static CSF indexer can read them.
404
+
405
+ // Options for the test scenarios, including a disabled one.
406
+ const testOptions = [
407
+ { value: 'apple', label: 'Apple' },
408
+ { value: 'banana', label: 'Banana' },
409
+ { value: 'orange', label: 'Orange' },
410
+ { value: 'mango', label: 'Mango (sold out)', disabled: true },
411
+ ];
412
+
413
+ // Shared render for the test scenarios.
414
+ function renderTestAutocomplete() {
415
+ return {
416
+ components: { UiAutocomplete },
417
+ setup() {
418
+ const value = ref('');
419
+ return { value, testOptions };
420
+ },
421
+ template: `
422
+ <UiAutocomplete
423
+ v-model="value"
424
+ :options="testOptions"
425
+ placeholder="Search fruit"
426
+ class="w-[260px]"
427
+ />
428
+ `,
429
+ };
430
+ }
431
+
432
+ // Reads the selected-value display rendered inside the input shell.
433
+ function selectionDisplay(canvasElement: HTMLElement) {
434
+ return canvasElement.querySelector('[data-slot="autocomplete-value"]');
435
+ }
436
+
437
+ // The suggestions panel fades in (and may remount on slow machines), so
438
+ // re-query on every retry until a visible listbox appears.
439
+ async function findOpenListbox(body: ReturnType<typeof within>) {
440
+ await waitFor(
441
+ async () => {
442
+ await expect(body.getByRole('listbox')).toBeVisible();
443
+ },
444
+ { timeout: 3000 },
445
+ );
446
+ return body.getByRole('listbox');
447
+ }
448
+
449
+ /**
450
+ * Accessibility guidance for the autocomplete: a labelled input and visible
451
+ * disabled options — shown side by side in the default and accessible themes.
452
+ */
453
+ export const Accessibility: Story = {
454
+ tags: ['!autodocs'],
455
+ parameters: {
456
+ a11y: { test: 'off' },
457
+ chromatic: { disableSnapshot: true },
458
+ docs: {
459
+ canvas: {
460
+ sourceState: 'none',
461
+ },
462
+ },
463
+ },
464
+ render: () => ({
465
+ components: { UiAutocomplete },
466
+ setup() {
467
+ const defaultValue = ref('');
468
+ const accessibleValue = ref('');
469
+ return { defaultValue, accessibleValue, fruits };
470
+ },
471
+ template: `
472
+ <section class="flex flex-col gap-6 p-4">
473
+ <div>
474
+ <h2 class="heading-m font-bold text-content-on-surface-primary">
475
+ Accessibility
476
+ </h2>
477
+ </div>
478
+
479
+ <div class="flex flex-col gap-6">
480
+ <div class="flex flex-col gap-2">
481
+ <h3 class="body-16-medium text-content-on-surface-primary">
482
+ Give the input an accessible name
483
+ </h3>
484
+ <p class="body-16-regular text-content-on-surface-primary">
485
+ Placeholders disappear while typing, so they are not labels.
486
+ Pair the field with a visible label or set the
487
+ <code>ariaLabel</code> prop.
488
+ </p>
489
+ </div>
490
+
491
+ <div class="flex flex-col gap-2">
492
+ <h3 class="body-16-medium text-content-on-surface-primary">
493
+ Keep disabled options visible
494
+ </h3>
495
+ <p class="body-16-regular text-content-on-surface-primary">
496
+ A disabled option stays in the results so users see the full set
497
+ of choices. When possible, explain why it is unavailable in its
498
+ label.
499
+ </p>
500
+ </div>
501
+
502
+ <div class="flex flex-col gap-2">
503
+ <h3 class="body-16-medium text-content-on-surface-primary">
504
+ Enable accessibility theme
505
+ </h3>
506
+ <p class="body-16-regular text-content-on-surface-primary">
507
+ When accessibility is required, enable our accessibility theme.
508
+ This increases contrast and makes sure there are no color
509
+ contrast issues.
510
+ </p>
511
+ </div>
512
+ </div>
513
+
514
+ <div class="grid gap-4 md:grid-cols-2">
515
+ <div class="flex flex-col gap-3">
516
+ <h3 class="label-16-medium text-center text-content-on-surface-primary">
517
+ Default
518
+ </h3>
519
+ <div class="flex min-h-20 items-center justify-center border border-border-surface-default p-6">
520
+ <UiAutocomplete
521
+ v-model="defaultValue"
522
+ :options="fruits"
523
+ placeholder="Search fruit"
524
+ class="w-[220px]"
525
+ />
526
+ </div>
527
+ </div>
528
+
529
+ <div class="accessible-theme flex flex-col gap-3">
530
+ <h3 class="label-16-medium text-center text-content-on-surface-primary">
531
+ Accessible
532
+ </h3>
533
+ <div class="flex min-h-20 items-center justify-center border border-border-surface-default p-6">
534
+ <UiAutocomplete
535
+ v-model="accessibleValue"
536
+ :options="fruits"
537
+ placeholder="Search fruit"
538
+ class="w-[220px]"
539
+ />
540
+ </div>
541
+ </div>
542
+ </div>
543
+ </section>
544
+ `,
545
+ }),
546
+ };
547
+
548
+ /**
549
+ * Full interaction flow: focusing the input opens the suggestions, typing
550
+ * filters them, choosing an option fills the field and closes the list, and
551
+ * disabled options cannot be chosen.
552
+ */
553
+ export const FilterAndSelect: Story = {
554
+ name: 'test - Filter And Select',
555
+ tags: ['!dev', '!autodocs'],
556
+ parameters: {
557
+ // The play opens the list and moves focus; skip the visual snapshot.
558
+ chromatic: { disableSnapshot: true },
559
+ docs: {
560
+ description: {
561
+ story:
562
+ 'Focus the input to open the suggestions, type to filter, choose a value, and try the disabled option.',
563
+ },
564
+ },
565
+ },
566
+ render: renderTestAutocomplete,
567
+ play: async ({ canvasElement, step }) => {
568
+ // Scenario (UiAutocomplete): a pointer user opens the suggestions by
569
+ // focusing the input, narrows them by typing, picks "Banana" (which fills
570
+ // the field and closes the list), then reopens and fails to choose the
571
+ // disabled option.
572
+ const canvas = within(canvasElement);
573
+ const body = within(document.body);
574
+ const input = canvas.getByRole('textbox', { name: 'Search fruit' });
575
+
576
+ await step(
577
+ 'interaction: focusing the input opens the suggestions',
578
+ async () => {
579
+ await userEvent.click(input);
580
+ await findOpenListbox(body);
581
+ },
582
+ );
583
+
584
+ await step('interaction: typing filters the options', async () => {
585
+ await userEvent.type(input, 'ban');
586
+ await waitFor(async () => {
587
+ const options = body.getAllByRole('option');
588
+ await expect(options).toHaveLength(1);
589
+ await expect(options[0]).toHaveTextContent('Banana');
590
+ });
591
+ });
592
+
593
+ await step(
594
+ 'interaction: choosing an option fills the field and closes the list',
595
+ async () => {
596
+ await userEvent.click(body.getByRole('option', { name: 'Banana' }));
597
+ await waitFor(async () => {
598
+ await expect(selectionDisplay(canvasElement)).toHaveTextContent(
599
+ 'Banana',
600
+ );
601
+ await expect(body.queryByRole('listbox')).not.toBeInTheDocument();
602
+ });
603
+ },
604
+ );
605
+
606
+ await step(
607
+ 'interaction: a disabled option cannot be chosen (WCAG 4.1.2)',
608
+ async () => {
609
+ await userEvent.click(input);
610
+ const disabledOption = await body.findByRole('option', {
611
+ name: 'Mango (sold out)',
612
+ });
613
+ await expect(disabledOption).toHaveAttribute('aria-disabled', 'true');
614
+ // Disabled options render with pointer-events: none, so bypass the
615
+ // check and assert the click is still a no-op.
616
+ await userEvent.click(disabledOption, { pointerEventsCheck: 0 });
617
+ await expect(selectionDisplay(canvasElement)).toHaveTextContent(
618
+ 'Banana',
619
+ );
620
+ await findOpenListbox(body);
621
+ // Close again so the end-of-play axe audit sees the resting state.
622
+ await userEvent.keyboard('{Escape}');
623
+ await waitFor(async () => {
624
+ await expect(body.queryByRole('listbox')).not.toBeInTheDocument();
625
+ });
626
+ },
627
+ );
628
+ },
629
+ };
630
+
631
+ /**
632
+ * `UiAutocomplete` is fully keyboard operable: `Tab` reaches the input, arrow
633
+ * keys open the list and move the highlight, `Enter` selects, and `Escape`
634
+ * dismisses while keeping focus in the input.
635
+ */
636
+ export const KeyboardNavigation: Story = {
637
+ name: 'test - Keyboard Navigation',
638
+ tags: ['!dev', '!autodocs'],
639
+ parameters: {
640
+ // Focus moves during the play function; skip the visual snapshot.
641
+ chromatic: { disableSnapshot: true },
642
+ docs: {
643
+ description: {
644
+ story:
645
+ 'Press `Tab` to focus the input, arrow keys to open and navigate, `Enter` to select, and `Escape` to dismiss.',
646
+ },
647
+ },
648
+ },
649
+ render: renderTestAutocomplete,
650
+ play: async ({ canvasElement, step }) => {
651
+ // Scenario (UiAutocomplete): a keyboard user tabs into the input (which
652
+ // opens the suggestions), arrows through the options, selects with Enter,
653
+ // and dismisses a reopened list with Escape without losing focus.
654
+ const canvas = within(canvasElement);
655
+ const body = within(document.body);
656
+ const input = canvas.getByRole('textbox', { name: 'Search fruit' });
657
+
658
+ await step(
659
+ 'keyboard: the input is reachable via Tab and opens the suggestions (WCAG 2.1.1 Keyboard)',
660
+ async () => {
661
+ await userEvent.tab();
662
+ await expect(input).toHaveFocus();
663
+ await findOpenListbox(body);
664
+ },
665
+ );
666
+
667
+ await step(
668
+ 'keyboard: arrow keys move the highlighted option (WCAG 2.4.3)',
669
+ async () => {
670
+ await userEvent.keyboard('{ArrowDown}');
671
+ await expect(
672
+ body.getByRole('option', { name: 'Apple' }),
673
+ ).toHaveAttribute('data-highlighted');
674
+ await userEvent.keyboard('{ArrowDown}');
675
+ await expect(
676
+ body.getByRole('option', { name: 'Banana' }),
677
+ ).toHaveAttribute('data-highlighted');
678
+ },
679
+ );
680
+
681
+ await step(
682
+ 'keyboard: Enter selects the highlighted option and closes the list (WCAG 2.1.1)',
683
+ async () => {
684
+ await userEvent.keyboard('{Enter}');
685
+ await waitFor(async () => {
686
+ await expect(selectionDisplay(canvasElement)).toHaveTextContent(
687
+ 'Banana',
688
+ );
689
+ await expect(body.queryByRole('listbox')).not.toBeInTheDocument();
690
+ });
691
+ await expect(input).toHaveFocus();
692
+ },
693
+ );
694
+
695
+ await step(
696
+ 'keyboard: Escape dismisses a reopened list and keeps focus in the input',
697
+ async () => {
698
+ await userEvent.keyboard('{ArrowDown}');
699
+ await findOpenListbox(body);
700
+ await userEvent.keyboard('{Escape}');
701
+ await waitFor(async () => {
702
+ await expect(body.queryByRole('listbox')).not.toBeInTheDocument();
703
+ });
704
+ await expect(input).toHaveFocus();
705
+ },
706
+ );
707
+ },
708
+ };
709
+
710
+ /**
711
+ * Screen-reader semantics: the input is a labelled textbox, the toggle exposes
712
+ * popup state, the results are a listbox, and options announce selected and
713
+ * disabled states.
714
+ */
715
+ export const ScreenReader: Story = {
716
+ name: 'test - Screen Reader',
717
+ tags: ['!dev', '!autodocs'],
718
+ parameters: {
719
+ // The play opens the list and changes the selection.
720
+ chromatic: { disableSnapshot: true },
721
+ docs: {
722
+ description: {
723
+ story:
724
+ 'Verifies the roles, names, and states that assistive technology announces.',
725
+ },
726
+ },
727
+ },
728
+ render: renderTestAutocomplete,
729
+ play: async ({ canvasElement, step }) => {
730
+ // Scenario (UiAutocomplete): assistive tech reads a labelled text input,
731
+ // hears the toggle's popup state flip when the list opens, finds a
732
+ // labelled listbox, and hears selected/disabled states on the options.
733
+ const canvas = within(canvasElement);
734
+ const body = within(document.body);
735
+ const input = canvas.getByRole('textbox', { name: 'Search fruit' });
736
+ const toggle = canvas.getByRole('button', { name: 'Open suggestions' });
737
+
738
+ await step(
739
+ 'screen-reader: the input exposes a textbox role with an accessible name (WCAG 4.1.2)',
740
+ async () => {
741
+ await expect(input).toHaveAccessibleName('Search fruit');
742
+ },
743
+ );
744
+
745
+ await step(
746
+ 'screen-reader: the toggle announces its popup and expanded state',
747
+ async () => {
748
+ await expect(toggle).toHaveAttribute('aria-haspopup', 'listbox');
749
+ await expect(toggle).toHaveAttribute('aria-expanded', 'false');
750
+ await userEvent.click(input);
751
+ await findOpenListbox(body);
752
+ await expect(
753
+ canvas.getByRole('button', { name: 'Close suggestions' }),
754
+ ).toHaveAttribute('aria-expanded', 'true');
755
+ },
756
+ );
757
+
758
+ await step(
759
+ 'screen-reader: the results are exposed as a labelled listbox (WCAG 1.3.1)',
760
+ async () => {
761
+ const listbox = body.getByRole('listbox', { name: 'Options' });
762
+ await expect(listbox).toHaveAttribute('aria-multiselectable', 'false');
763
+ },
764
+ );
765
+
766
+ await step(
767
+ 'screen-reader: a disabled option announces its disabled state (WCAG 4.1.2)',
768
+ async () => {
769
+ await expect(
770
+ body.getByRole('option', { name: 'Mango (sold out)' }),
771
+ ).toHaveAttribute('aria-disabled', 'true');
772
+ },
773
+ );
774
+
775
+ await step(
776
+ 'screen-reader: the chosen option announces its selected state (WCAG 4.1.2)',
777
+ async () => {
778
+ await userEvent.click(body.getByRole('option', { name: 'Apple' }));
779
+ await waitFor(async () => {
780
+ await expect(selectionDisplay(canvasElement)).toHaveTextContent(
781
+ 'Apple',
782
+ );
783
+ });
784
+ await userEvent.click(input);
785
+ const apple = await body.findByRole('option', { name: 'Apple' });
786
+ await expect(apple).toHaveAttribute('aria-selected', 'true');
787
+ await expect(
788
+ body.getByRole('option', { name: 'Banana' }),
789
+ ).toHaveAttribute('aria-selected', 'false');
790
+ // Close again so the end-of-play axe audit sees the resting state.
791
+ await userEvent.keyboard('{Escape}');
792
+ await waitFor(async () => {
793
+ await expect(body.queryByRole('listbox')).not.toBeInTheDocument();
794
+ });
795
+ },
796
+ );
797
+ },
798
+ };
799
+
800
+ /**
801
+ * Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
802
+ * try 400% reflow (WCAG 1.4.10); the input and the open list must stay
803
+ * visible and operable.
804
+ */
805
+ export const ZoomMagnification: Story = {
806
+ name: 'test - Zoom Magnification',
807
+ tags: ['!dev', '!autodocs'],
808
+ globals: { zoom: '200' },
809
+ parameters: {
810
+ // The accessible-reflow Chromatic mode already covers magnified snapshots.
811
+ chromatic: { disableSnapshot: true },
812
+ docs: {
813
+ description: {
814
+ story:
815
+ 'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
816
+ },
817
+ },
818
+ },
819
+ render: renderTestAutocomplete,
820
+ play: async ({ canvasElement, step }) => {
821
+ // Scenario (UiAutocomplete): at 200% page zoom the input keeps its
822
+ // accessible name and the suggestions still open, filter, and accept a
823
+ // selection.
824
+ const canvas = within(canvasElement);
825
+ const body = within(document.body);
826
+ const input = canvas.getByRole('textbox', { name: 'Search fruit' });
827
+
828
+ await step(
829
+ 'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
830
+ async () => {
831
+ await expect(document.documentElement.style.zoom).toBe('200%');
832
+ },
833
+ );
834
+
835
+ await step(
836
+ 'zoom: the input stays visible with its accessible name',
837
+ async () => {
838
+ await expect(input).toBeVisible();
839
+ await expect(input).toHaveAccessibleName('Search fruit');
840
+ },
841
+ );
842
+
843
+ await step(
844
+ 'zoom: the open list remains visible and operable when magnified',
845
+ async () => {
846
+ await userEvent.click(input);
847
+ await findOpenListbox(body);
848
+ await userEvent.click(body.getByRole('option', { name: 'Banana' }));
849
+ await waitFor(async () => {
850
+ await expect(selectionDisplay(canvasElement)).toHaveTextContent(
851
+ 'Banana',
852
+ );
853
+ });
854
+ },
855
+ );
856
+ },
857
+ };
858
+
859
+ /**
860
+ * Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
861
+ * toolbar. The control and the options stay operable and meet the minimum
862
+ * touch-target size (WCAG 2.5.8).
863
+ */
864
+ export const MobileBreakpoint: Story = {
865
+ name: 'test - Mobile Breakpoint',
866
+ tags: ['!dev', '!autodocs'],
867
+ globals: { mediaBreakpoint: 'reflow' },
868
+ parameters: {
869
+ // Reflow snapshots are already covered by the accessible-reflow mode.
870
+ chromatic: { disableSnapshot: true },
871
+ docs: {
872
+ description: {
873
+ story:
874
+ 'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
875
+ },
876
+ },
877
+ },
878
+ render: renderTestAutocomplete,
879
+ play: async ({ canvasElement, step }) => {
880
+ // Scenario (UiAutocomplete): at the 320px mobile breakpoint the control
881
+ // stays usable and the input shell and options meet the minimum
882
+ // touch-target size.
883
+ const canvas = within(canvasElement);
884
+ const body = within(document.body);
885
+ const input = canvas.getByRole('textbox', { name: 'Search fruit' });
886
+
887
+ await step(
888
+ 'mobile: the input shell meets the minimum touch-target size (WCAG 2.5.8)',
889
+ async () => {
890
+ const shell = canvasElement.querySelector(
891
+ '[data-slot="autocomplete-trigger"]',
892
+ ) as HTMLElement;
893
+ const { width, height } = shell.getBoundingClientRect();
894
+ await expect(width).toBeGreaterThanOrEqual(24);
895
+ await expect(height).toBeGreaterThanOrEqual(24);
896
+ },
897
+ );
898
+
899
+ await step(
900
+ 'mobile: the list opens and options stay operable at the 320px breakpoint (WCAG 1.4.10 Reflow)',
901
+ async () => {
902
+ await userEvent.click(input);
903
+ await findOpenListbox(body);
904
+ await userEvent.click(body.getByRole('option', { name: 'Orange' }));
905
+ await waitFor(async () => {
906
+ await expect(selectionDisplay(canvasElement)).toHaveTextContent(
907
+ 'Orange',
908
+ );
909
+ });
910
+ },
911
+ );
912
+
913
+ await step(
914
+ 'mobile: options meet the minimum touch-target size (WCAG 2.5.8)',
915
+ async () => {
916
+ await userEvent.click(input);
917
+ const option = await body.findByRole('option', { name: 'Apple' });
918
+ const { height } = option.getBoundingClientRect();
919
+ await expect(height).toBeGreaterThanOrEqual(24);
920
+ // Close again so the end-of-play axe audit sees the resting state.
921
+ await userEvent.keyboard('{Escape}');
922
+ await waitFor(async () => {
923
+ await expect(body.queryByRole('listbox')).not.toBeInTheDocument();
924
+ });
925
+ },
926
+ );
927
+ },
928
+ };