@aleph-alpha/ui-library 5.4.0 → 5.6.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 (59) hide show
  1. package/config.d.ts +9 -0
  2. package/config.js +12 -3
  3. package/dist/system/components/UiAutocomplete/UiAutocomplete.vue.d.ts +2 -0
  4. package/dist/system/components/UiButtonGroup/UiButtonGroup.vue.d.ts +20 -0
  5. package/dist/system/components/UiButtonGroup/index.d.ts +2 -0
  6. package/dist/system/components/UiButtonGroup/types.d.ts +20 -0
  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 +8878 -8692
  13. package/dist/system/patterns/UiFloatActions/UiFloatActionItems.vue.d.ts +173 -2
  14. package/dist/system/patterns/UiFloatActions/floatActionItemContext.d.ts +15 -1
  15. package/dist/system/patterns/UiFloatActions/types.d.ts +25 -1
  16. package/dist/system/story-sidebar-icons.json +8 -1
  17. package/package.json +5 -3
  18. package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +620 -0
  19. package/src/components/UiAutocomplete/UiAutocomplete.vue +28 -3
  20. package/src/components/UiAutocomplete/__tests__/UiAutocomplete.test.ts +14 -69
  21. package/src/components/UiButton/UiButton.stories.ts +9 -9
  22. package/src/components/UiButtonGroup/UiButtonGroup.stories.ts +690 -0
  23. package/src/components/UiButtonGroup/UiButtonGroup.vue +18 -0
  24. package/src/components/UiButtonGroup/__tests__/UiButtonGroup.test.ts +68 -0
  25. package/src/components/UiButtonGroup/index.ts +2 -0
  26. package/src/components/UiButtonGroup/types.ts +21 -0
  27. package/src/components/UiCheckbox/UiCheckbox.stories.ts +253 -0
  28. package/src/components/UiCheckbox/__tests__/UiCheckbox.test.ts +3 -18
  29. package/src/components/UiField/UiField.stories.ts +608 -1
  30. package/src/components/UiField/UiFieldDescription.vue +7 -2
  31. package/src/components/UiInput/UiInput.stories.ts +336 -2
  32. package/src/components/UiInput/__tests__/UiInput.test.ts +20 -28
  33. package/src/components/UiItem/UiItem.stories.ts +236 -1
  34. package/src/components/UiItem/__tests__/UiItem.test.ts +11 -72
  35. package/src/components/UiSelect/UiSelect.stories.ts +769 -0
  36. package/src/components/UiSelect/__tests__/UiSelect.test.ts +4 -73
  37. package/src/components/UiSelect/__tests__/UiSelectItem.test.ts +3 -31
  38. package/src/components/UiSelect/__tests__/UiSelectTrigger.test.ts +14 -5
  39. package/src/components/UiSnackbar/UiSnackbar.stories.ts +6 -6
  40. package/src/components/UiSnackbar/UiSnackbar.vue +4 -4
  41. package/src/components/UiSnackbar/UiSnackbarContent.vue +4 -4
  42. package/src/components/core/button-group/ButtonGroup.vue +24 -0
  43. package/src/components/core/button-group/ButtonGroupSeparator.vue +29 -0
  44. package/src/components/core/button-group/ButtonGroupText.vue +33 -0
  45. package/src/components/core/button-group/index.ts +25 -0
  46. package/src/components/core/checkbox/Checkbox.vue +0 -1
  47. package/src/components/core/select/SelectTrigger.vue +1 -1
  48. package/src/components/core/tabs/TabsTrigger.vue +1 -1
  49. package/src/components/index.ts +1 -0
  50. package/src/patterns/UiDataTable/UiDataTable.stories.ts +495 -8
  51. package/src/patterns/UiDataTable/UiDataTableFilterMenu.vue +1 -1
  52. package/src/patterns/UiDataTable/__tests__/UiDataTable.test.ts +7 -184
  53. package/src/patterns/UiFloatActions/UiFloatActionItems.vue +138 -11
  54. package/src/patterns/UiFloatActions/UiFloatActions.stories.ts +890 -3
  55. package/src/patterns/UiFloatActions/__tests__/UiFloatActionItems.test.ts +46 -24
  56. package/src/patterns/UiFloatActions/floatActionItemContext.ts +16 -1
  57. package/src/patterns/UiFloatActions/types.ts +28 -1
  58. package/src/components/UiField/__tests__/UiFieldError.test.ts +0 -39
  59. package/src/patterns/UiFloatActions/__tests__/UiFloatActions.a11y.test.ts +0 -152
@@ -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 {
4
5
  UiSelect,
@@ -109,6 +110,29 @@ export const Default: Story = {
109
110
  },
110
111
  },
111
112
  },
113
+ play: async ({ canvasElement, step }) => {
114
+ // Scenario (UiSelect): the closed trigger exposes combobox semantics and
115
+ // shows its placeholder until a value is chosen. Non-mutating checks only,
116
+ // so the story's visual snapshot stays untouched.
117
+ const canvas = within(canvasElement);
118
+ const trigger = canvas.getByRole('combobox', { name: 'Select option' });
119
+
120
+ await step(
121
+ 'interaction: exposes a combobox trigger with an accessible name (WCAG 4.1.2)',
122
+ async () => {
123
+ await expect(trigger).toHaveAccessibleName('Select option');
124
+ await expect(trigger).toHaveAttribute('aria-expanded', 'false');
125
+ },
126
+ );
127
+
128
+ await step(
129
+ 'interaction: shows the placeholder while nothing is chosen',
130
+ async () => {
131
+ await expect(trigger).toHaveTextContent('Select a fruit');
132
+ await expect(trigger).toHaveAttribute('data-placeholder');
133
+ },
134
+ );
135
+ },
112
136
  };
113
137
 
114
138
  const withGroupsTemplateSource = `<script setup lang="ts">
@@ -423,6 +447,151 @@ export const Disabled: Story = {
423
447
  },
424
448
  },
425
449
  },
450
+ play: async ({ canvasElement, step }) => {
451
+ // Scenario (UiSelect): a disabled select reports its disabled state, is
452
+ // skipped by Tab, and never opens its dropdown.
453
+ const canvas = within(canvasElement);
454
+ const trigger = canvas.getByRole('combobox', { name: 'Select option' });
455
+
456
+ await step(
457
+ 'interaction: exposes the disabled state (WCAG 4.1.2)',
458
+ async () => {
459
+ await expect(trigger).toBeDisabled();
460
+ },
461
+ );
462
+
463
+ await step(
464
+ 'keyboard: removed from the tab order — not reachable via Tab (WCAG 2.1.1)',
465
+ async () => {
466
+ await userEvent.tab();
467
+ await expect(trigger).not.toHaveFocus();
468
+ },
469
+ );
470
+
471
+ await step(
472
+ 'interaction: forced clicks do not open the dropdown',
473
+ async () => {
474
+ await userEvent.click(trigger, { pointerEventsCheck: 0 });
475
+ await expect(trigger).toHaveAttribute('aria-expanded', 'false');
476
+ },
477
+ );
478
+ },
479
+ };
480
+
481
+ const statesTemplateSource = `<script setup lang="ts">
482
+ import { ref } from 'vue'
483
+ import {
484
+ UiSelect,
485
+ UiSelectTrigger,
486
+ UiSelectContent,
487
+ UiSelectItem,
488
+ UiSelectValue,
489
+ } from '@aleph-alpha/ui-library'
490
+
491
+ const emptyValue = ref('')
492
+ const filledValue = ref('banana')
493
+ const disabledValue = ref('')
494
+ </script>
495
+
496
+ <template>
497
+ <div class="flex flex-col gap-4">
498
+ <!-- Default: input surface with muted placeholder text -->
499
+ <UiSelect v-model="emptyValue">
500
+ <UiSelectTrigger ariaLabel="Select option">
501
+ <UiSelectValue placeholder="Placeholder" />
502
+ </UiSelectTrigger>
503
+ <UiSelectContent>
504
+ <UiSelectItem value="banana">Banana</UiSelectItem>
505
+ </UiSelectContent>
506
+ </UiSelect>
507
+
508
+ <!-- Filled: same surface, value rendered in regular text -->
509
+ <UiSelect v-model="filledValue">
510
+ <UiSelectTrigger ariaLabel="Select option">
511
+ <UiSelectValue placeholder="Placeholder" />
512
+ </UiSelectTrigger>
513
+ <UiSelectContent>
514
+ <UiSelectItem value="banana">Banana</UiSelectItem>
515
+ </UiSelectContent>
516
+ </UiSelect>
517
+
518
+ <!-- Disabled -->
519
+ <UiSelect v-model="disabledValue" :disabled="true">
520
+ <UiSelectTrigger ariaLabel="Select option">
521
+ <UiSelectValue placeholder="Placeholder" />
522
+ </UiSelectTrigger>
523
+ <UiSelectContent>
524
+ <UiSelectItem value="banana">Banana</UiSelectItem>
525
+ </UiSelectContent>
526
+ </UiSelect>
527
+ </div>
528
+ </template>`;
529
+
530
+ /**
531
+ * The select's visual states: Default (placeholder), Filled (a chosen value),
532
+ * and Disabled. Default and Filled share the same input surface — only the
533
+ * muted placeholder text switches to regular value text.
534
+ */
535
+ export const States: Story = {
536
+ render: () => ({
537
+ components: {
538
+ UiSelect,
539
+ UiSelectTrigger,
540
+ UiSelectContent,
541
+ UiSelectItem,
542
+ UiSelectValue,
543
+ },
544
+ setup() {
545
+ const emptyValue = ref('');
546
+ const filledValue = ref('banana');
547
+ const disabledValue = ref('');
548
+ return { emptyValue, filledValue, disabledValue };
549
+ },
550
+ template: `
551
+ <div class="grid w-fit grid-cols-[auto_220px] items-center gap-x-6 gap-y-4">
552
+ <span class="label-14-medium text-content-on-surface-primary text-right">Default</span>
553
+ <UiSelect v-model="emptyValue">
554
+ <UiSelectTrigger ariaLabel="Select option" class="w-full">
555
+ <UiSelectValue placeholder="Placeholder" />
556
+ </UiSelectTrigger>
557
+ <UiSelectContent>
558
+ <UiSelectItem value="banana">Banana</UiSelectItem>
559
+ </UiSelectContent>
560
+ </UiSelect>
561
+
562
+ <span class="label-14-medium text-content-on-surface-primary text-right">Filled</span>
563
+ <UiSelect v-model="filledValue">
564
+ <UiSelectTrigger ariaLabel="Select option" class="w-full">
565
+ <UiSelectValue placeholder="Placeholder" />
566
+ </UiSelectTrigger>
567
+ <UiSelectContent>
568
+ <UiSelectItem value="banana">Banana</UiSelectItem>
569
+ </UiSelectContent>
570
+ </UiSelect>
571
+
572
+ <span class="label-14-medium text-content-on-surface-primary text-right">Disabled</span>
573
+ <UiSelect v-model="disabledValue" :disabled="true">
574
+ <UiSelectTrigger ariaLabel="Select option" class="w-full">
575
+ <UiSelectValue placeholder="Placeholder" />
576
+ </UiSelectTrigger>
577
+ <UiSelectContent>
578
+ <UiSelectItem value="banana">Banana</UiSelectItem>
579
+ </UiSelectContent>
580
+ </UiSelect>
581
+ </div>
582
+ `,
583
+ }),
584
+ parameters: {
585
+ docs: {
586
+ description: {
587
+ story:
588
+ 'Default, Filled, and Disabled states side by side. The focus state is not shown here — it appears on keyboard focus and while the dropdown is open.',
589
+ },
590
+ source: {
591
+ code: statesTemplateSource,
592
+ },
593
+ },
594
+ },
426
595
  };
427
596
 
428
597
  const withDefaultValueTemplateSource = `<script setup lang="ts">
@@ -637,3 +806,603 @@ export const WithDefaultValue: Story = {
637
806
  },
638
807
  },
639
808
  };
809
+
810
+ // Test-only stories drive the test-runner (interactive/a11y checks) but are
811
+ // hidden from the Storybook sidebar and docs via the `!dev` / `!autodocs`
812
+ // tags. They keep the implicit `test` tag, so they still run in CI and appear
813
+ // in the automated report under their `test - …` name. `name`/`tags` must be
814
+ // literal properties so Storybook's static CSF indexer can read them.
815
+
816
+ // Shared render for the test scenarios: grouped options with a separator and a
817
+ // disabled option, covering every subcomponent (trigger, value, content,
818
+ // group, label, separator, item).
819
+ function renderTestSelect() {
820
+ return {
821
+ components: {
822
+ UiSelect,
823
+ UiSelectTrigger,
824
+ UiSelectContent,
825
+ UiSelectItem,
826
+ UiSelectValue,
827
+ UiSelectLabel,
828
+ UiSelectGroup,
829
+ UiSelectSeparator,
830
+ },
831
+ setup() {
832
+ const value = ref('');
833
+ return { value };
834
+ },
835
+ template: `
836
+ <UiSelect v-model="value">
837
+ <UiSelectTrigger ariaLabel="Select option">
838
+ <UiSelectValue placeholder="Select a food" />
839
+ </UiSelectTrigger>
840
+ <UiSelectContent>
841
+ <UiSelectGroup>
842
+ <UiSelectLabel>Fruits</UiSelectLabel>
843
+ <UiSelectItem value="apple">Apple</UiSelectItem>
844
+ <UiSelectItem value="banana">Banana</UiSelectItem>
845
+ <UiSelectItem value="mango" :disabled="true">Mango (sold out)</UiSelectItem>
846
+ </UiSelectGroup>
847
+ <UiSelectSeparator />
848
+ <UiSelectGroup>
849
+ <UiSelectLabel>Vegetables</UiSelectLabel>
850
+ <UiSelectItem value="carrot">Carrot</UiSelectItem>
851
+ <UiSelectItem value="broccoli">Broccoli</UiSelectItem>
852
+ </UiSelectGroup>
853
+ </UiSelectContent>
854
+ </UiSelect>
855
+ `,
856
+ };
857
+ }
858
+
859
+ // The dropdown fades in (and may remount on slow machines), so re-query on
860
+ // every retry until a visible listbox appears.
861
+ async function findOpenListbox(body: ReturnType<typeof within>) {
862
+ await waitFor(
863
+ async () => {
864
+ await expect(body.getByRole('listbox')).toBeVisible();
865
+ },
866
+ { timeout: 3000 },
867
+ );
868
+ return body.getByRole('listbox');
869
+ }
870
+
871
+ // While the dropdown is open, reka hides the app root (`aria-hidden`) and
872
+ // disables pointer events on <body>; both are only restored after the close
873
+ // animation. Wait for that before clicking the trigger again or ending the
874
+ // play (the axe audit runs on the end-of-play state).
875
+ async function waitForDropdownClosed(body: ReturnType<typeof within>) {
876
+ await waitFor(async () => {
877
+ await expect(body.queryByRole('listbox')).not.toBeInTheDocument();
878
+ await expect(document.querySelector('[data-aria-hidden]')).toBeNull();
879
+ await expect(document.body).not.toHaveStyle({ pointerEvents: 'none' });
880
+ });
881
+ }
882
+
883
+ /**
884
+ * Accessibility guidance for selects: an accessible trigger name, labelled
885
+ * groups, and visible disabled options — shown side by side in the default
886
+ * and accessible themes.
887
+ */
888
+ export const Accessibility: Story = {
889
+ tags: ['!autodocs'],
890
+ parameters: {
891
+ a11y: { test: 'off' },
892
+ chromatic: { disableSnapshot: true },
893
+ docs: {
894
+ canvas: {
895
+ sourceState: 'none',
896
+ },
897
+ },
898
+ },
899
+ render: () => ({
900
+ components: {
901
+ UiSelect,
902
+ UiSelectTrigger,
903
+ UiSelectContent,
904
+ UiSelectItem,
905
+ UiSelectValue,
906
+ },
907
+ setup() {
908
+ const defaultValue = ref('');
909
+ const accessibleValue = ref('');
910
+ return { defaultValue, accessibleValue };
911
+ },
912
+ template: `
913
+ <section class="flex flex-col gap-6 p-4">
914
+ <div>
915
+ <h2 class="heading-m font-bold text-content-on-surface-primary">
916
+ Accessibility
917
+ </h2>
918
+ </div>
919
+
920
+ <div class="flex flex-col gap-6">
921
+ <div class="flex flex-col gap-2">
922
+ <h3 class="body-16-medium text-content-on-surface-primary">
923
+ Give the trigger an accessible name
924
+ </h3>
925
+ <p class="body-16-regular text-content-on-surface-primary">
926
+ The placeholder disappears once a value is chosen, so it is not a
927
+ label. Pair the select with a visible label or set
928
+ <code>ariaLabel</code> on <code>UiSelectTrigger</code>.
929
+ </p>
930
+ </div>
931
+
932
+ <div class="flex flex-col gap-2">
933
+ <h3 class="body-16-medium text-content-on-surface-primary">
934
+ Group related options and label the groups
935
+ </h3>
936
+ <p class="body-16-regular text-content-on-surface-primary">
937
+ Long flat lists are hard to scan and listen to. Wrap related
938
+ options in <code>UiSelectGroup</code> with a
939
+ <code>UiSelectLabel</code> so the group is announced with its
940
+ name.
941
+ </p>
942
+ </div>
943
+
944
+ <div class="flex flex-col gap-2">
945
+ <h3 class="body-16-medium text-content-on-surface-primary">
946
+ Keep disabled options visible
947
+ </h3>
948
+ <p class="body-16-regular text-content-on-surface-primary">
949
+ A disabled option stays in the list so users see the full set of
950
+ choices. When possible, explain why it is unavailable in its
951
+ label (for example "Enterprise — contact sales").
952
+ </p>
953
+ </div>
954
+
955
+ <div class="flex flex-col gap-2">
956
+ <h3 class="body-16-medium text-content-on-surface-primary">
957
+ Enable accessibility theme
958
+ </h3>
959
+ <p class="body-16-regular text-content-on-surface-primary">
960
+ When accessibility is required, enable our accessibility theme.
961
+ This increases contrast and makes sure there are no color
962
+ contrast issues.
963
+ </p>
964
+ </div>
965
+ </div>
966
+
967
+ <div class="grid gap-4 md:grid-cols-2">
968
+ <div class="flex flex-col gap-3">
969
+ <h3 class="label-16-medium text-center text-content-on-surface-primary">
970
+ Default
971
+ </h3>
972
+ <div class="flex min-h-20 items-center justify-center border border-border-surface-default p-6">
973
+ <UiSelect v-model="defaultValue">
974
+ <UiSelectTrigger ariaLabel="Select a fruit">
975
+ <UiSelectValue placeholder="Select a fruit" />
976
+ </UiSelectTrigger>
977
+ <UiSelectContent>
978
+ <UiSelectItem value="apple">Apple</UiSelectItem>
979
+ <UiSelectItem value="banana">Banana</UiSelectItem>
980
+ <UiSelectItem value="orange">Orange</UiSelectItem>
981
+ </UiSelectContent>
982
+ </UiSelect>
983
+ </div>
984
+ </div>
985
+
986
+ <div class="accessible-theme flex flex-col gap-3">
987
+ <h3 class="label-16-medium text-center text-content-on-surface-primary">
988
+ Accessible
989
+ </h3>
990
+ <div class="flex min-h-20 items-center justify-center border border-border-surface-default p-6">
991
+ <UiSelect v-model="accessibleValue">
992
+ <UiSelectTrigger ariaLabel="Select a fruit">
993
+ <UiSelectValue placeholder="Select a fruit" />
994
+ </UiSelectTrigger>
995
+ <UiSelectContent>
996
+ <UiSelectItem value="apple">Apple</UiSelectItem>
997
+ <UiSelectItem value="banana">Banana</UiSelectItem>
998
+ <UiSelectItem value="orange">Orange</UiSelectItem>
999
+ </UiSelectContent>
1000
+ </UiSelect>
1001
+ </div>
1002
+ </div>
1003
+ </div>
1004
+ </section>
1005
+ `,
1006
+ }),
1007
+ };
1008
+
1009
+ /**
1010
+ * Full interaction flow: the dropdown opens on activation, a choice updates
1011
+ * the trigger and closes the panel, focus returns to the trigger, disabled
1012
+ * options cannot be chosen, and Escape dismisses the list.
1013
+ */
1014
+ export const OpenSelectClose: Story = {
1015
+ name: 'test - Open Select Close',
1016
+ tags: ['!dev', '!autodocs'],
1017
+ parameters: {
1018
+ // The play opens the dropdown and moves focus; skip the visual snapshot.
1019
+ chromatic: { disableSnapshot: true },
1020
+ docs: {
1021
+ description: {
1022
+ story:
1023
+ 'Open the dropdown, try the disabled option, choose a value, and dismiss with Escape.',
1024
+ },
1025
+ },
1026
+ },
1027
+ render: renderTestSelect,
1028
+ play: async ({ canvasElement, step }) => {
1029
+ // Scenario (UiSelect): a pointer user opens the dropdown, cannot choose the
1030
+ // disabled option, picks "Banana" (which closes the panel and returns
1031
+ // focus to the trigger), then reopens and dismisses with Escape.
1032
+ const canvas = within(canvasElement);
1033
+ const body = within(document.body);
1034
+ const trigger = canvas.getByRole('combobox', { name: 'Select option' });
1035
+
1036
+ await step(
1037
+ 'interaction: opens the dropdown on trigger activation',
1038
+ async () => {
1039
+ await userEvent.click(trigger);
1040
+ await findOpenListbox(body);
1041
+ await expect(trigger).toHaveAttribute('aria-expanded', 'true');
1042
+ },
1043
+ );
1044
+
1045
+ await step(
1046
+ 'interaction: a disabled option cannot be chosen (WCAG 4.1.2)',
1047
+ async () => {
1048
+ const disabledOption = body.getByRole('option', {
1049
+ name: 'Mango (sold out)',
1050
+ });
1051
+ await expect(disabledOption).toHaveAttribute('aria-disabled', 'true');
1052
+ // Disabled items render with pointer-events: none, so bypass the
1053
+ // check and assert the click is still a no-op.
1054
+ await userEvent.click(disabledOption, { pointerEventsCheck: 0 });
1055
+ await expect(body.getByRole('listbox')).toBeVisible();
1056
+ await expect(trigger).toHaveTextContent('Select a food');
1057
+ },
1058
+ );
1059
+
1060
+ await step(
1061
+ 'interaction: choosing an option updates the trigger and closes the dropdown',
1062
+ async () => {
1063
+ await userEvent.click(body.getByRole('option', { name: 'Banana' }));
1064
+ await waitFor(async () => {
1065
+ await expect(trigger).toHaveTextContent('Banana');
1066
+ });
1067
+ await waitForDropdownClosed(body);
1068
+ },
1069
+ );
1070
+
1071
+ await step(
1072
+ 'interaction: focus returns to the trigger after selection (WCAG 2.4.3)',
1073
+ async () => {
1074
+ await waitFor(async () => {
1075
+ await expect(trigger).toHaveFocus();
1076
+ });
1077
+ },
1078
+ );
1079
+
1080
+ await step(
1081
+ 'interaction: Escape dismisses a reopened dropdown and restores focus',
1082
+ async () => {
1083
+ await userEvent.click(trigger);
1084
+ await findOpenListbox(body);
1085
+ await userEvent.keyboard('{Escape}');
1086
+ await waitForDropdownClosed(body);
1087
+ await waitFor(async () => {
1088
+ await expect(trigger).toHaveFocus();
1089
+ });
1090
+ },
1091
+ );
1092
+ },
1093
+ };
1094
+
1095
+ /**
1096
+ * `UiSelect` is fully keyboard operable: `Tab` reaches the trigger, `Enter`
1097
+ * opens the list, arrow keys move through enabled options, `Enter` selects,
1098
+ * and `Escape` dismisses while restoring focus.
1099
+ */
1100
+ export const KeyboardNavigation: Story = {
1101
+ name: 'test - Keyboard Navigation',
1102
+ tags: ['!dev', '!autodocs'],
1103
+ parameters: {
1104
+ // Focus moves during the play function; skip the visual snapshot.
1105
+ chromatic: { disableSnapshot: true },
1106
+ docs: {
1107
+ description: {
1108
+ story:
1109
+ 'Press `Tab` to focus the trigger, `Enter` to open, arrow keys to navigate, `Enter` to select, and `Escape` to dismiss.',
1110
+ },
1111
+ },
1112
+ },
1113
+ render: renderTestSelect,
1114
+ play: async ({ canvasElement, step }) => {
1115
+ // Scenario (UiSelect): a keyboard user tabs to the trigger, opens the list
1116
+ // with Enter, arrows through options (skipping the disabled one), selects
1117
+ // with Enter, and dismisses a reopened list with Escape.
1118
+ const canvas = within(canvasElement);
1119
+ const body = within(document.body);
1120
+ const trigger = canvas.getByRole('combobox', { name: 'Select option' });
1121
+
1122
+ await step(
1123
+ 'keyboard: the trigger is reachable via Tab (WCAG 2.1.1 Keyboard)',
1124
+ async () => {
1125
+ await userEvent.tab();
1126
+ await expect(trigger).toHaveFocus();
1127
+ },
1128
+ );
1129
+
1130
+ await step('keyboard: Enter opens the dropdown', async () => {
1131
+ await userEvent.keyboard('{Enter}');
1132
+ await findOpenListbox(body);
1133
+ await expect(trigger).toHaveAttribute('aria-expanded', 'true');
1134
+ });
1135
+
1136
+ await step(
1137
+ 'keyboard: arrow keys move focus through enabled options (WCAG 2.4.3)',
1138
+ async () => {
1139
+ // Opening with Enter focuses the first enabled option; ArrowDown moves
1140
+ // to the next one.
1141
+ await waitFor(async () => {
1142
+ await expect(
1143
+ body.getByRole('option', { name: 'Apple' }),
1144
+ ).toHaveFocus();
1145
+ });
1146
+ await userEvent.keyboard('{ArrowDown}');
1147
+ await expect(
1148
+ body.getByRole('option', { name: 'Banana' }),
1149
+ ).toHaveFocus();
1150
+ },
1151
+ );
1152
+
1153
+ await step(
1154
+ 'keyboard: Enter selects the focused option and closes the list (WCAG 2.1.1)',
1155
+ async () => {
1156
+ await userEvent.keyboard('{Enter}');
1157
+ await waitFor(async () => {
1158
+ await expect(trigger).toHaveTextContent('Banana');
1159
+ });
1160
+ await waitForDropdownClosed(body);
1161
+ },
1162
+ );
1163
+
1164
+ await step(
1165
+ 'keyboard: focus returns to the trigger after the list closes (WCAG 2.4.3)',
1166
+ async () => {
1167
+ await waitFor(async () => {
1168
+ await expect(trigger).toHaveFocus();
1169
+ });
1170
+ },
1171
+ );
1172
+
1173
+ await step(
1174
+ 'keyboard: Escape dismisses a reopened list and restores focus',
1175
+ async () => {
1176
+ await userEvent.keyboard('{Enter}');
1177
+ await findOpenListbox(body);
1178
+ await userEvent.keyboard('{Escape}');
1179
+ await waitForDropdownClosed(body);
1180
+ await waitFor(async () => {
1181
+ await expect(trigger).toHaveFocus();
1182
+ });
1183
+ },
1184
+ );
1185
+ },
1186
+ };
1187
+
1188
+ /**
1189
+ * Screen-reader semantics: the trigger exposes a combobox with expanded state,
1190
+ * the panel is a listbox with labelled groups, options announce selected and
1191
+ * disabled states, and separators stay decorative.
1192
+ */
1193
+ export const ScreenReader: Story = {
1194
+ name: 'test - Screen Reader',
1195
+ tags: ['!dev', '!autodocs'],
1196
+ parameters: {
1197
+ // The play opens the dropdown and changes the selection.
1198
+ chromatic: { disableSnapshot: true },
1199
+ docs: {
1200
+ description: {
1201
+ story:
1202
+ 'Verifies the roles, names, grouping, and states that assistive technology announces.',
1203
+ },
1204
+ },
1205
+ },
1206
+ render: renderTestSelect,
1207
+ play: async ({ canvasElement, step }) => {
1208
+ // Scenario (UiSelect): assistive tech reads the trigger as a combobox with
1209
+ // its accessible name and expanded state, finds options organised under
1210
+ // labelled groups, and hears selected/disabled states on the options.
1211
+ const canvas = within(canvasElement);
1212
+ const body = within(document.body);
1213
+ const trigger = canvas.getByRole('combobox', { name: 'Select option' });
1214
+
1215
+ await step(
1216
+ 'screen-reader: the trigger exposes a combobox role, name, and collapsed state (WCAG 4.1.2)',
1217
+ async () => {
1218
+ await expect(trigger).toHaveAccessibleName('Select option');
1219
+ await expect(trigger).toHaveAttribute('aria-expanded', 'false');
1220
+ },
1221
+ );
1222
+
1223
+ await step(
1224
+ 'screen-reader: the open panel is exposed as a listbox and the trigger reports expanded',
1225
+ async () => {
1226
+ await userEvent.click(trigger);
1227
+ await findOpenListbox(body);
1228
+ await expect(trigger).toHaveAttribute('aria-expanded', 'true');
1229
+ },
1230
+ );
1231
+
1232
+ await step(
1233
+ 'screen-reader: options are organised under labelled groups (WCAG 1.3.1)',
1234
+ async () => {
1235
+ const fruits = body.getByRole('group', { name: 'Fruits' });
1236
+ await expect(
1237
+ within(fruits).getByRole('option', { name: 'Apple' }),
1238
+ ).toBeVisible();
1239
+ const vegetables = body.getByRole('group', { name: 'Vegetables' });
1240
+ await expect(
1241
+ within(vegetables).getByRole('option', { name: 'Carrot' }),
1242
+ ).toBeVisible();
1243
+ },
1244
+ );
1245
+
1246
+ await step(
1247
+ 'screen-reader: the separator is decorative and hidden from assistive tech',
1248
+ async () => {
1249
+ const separator = document.querySelector(
1250
+ '[data-slot="select-separator"]',
1251
+ );
1252
+ await expect(separator).toHaveAttribute('aria-hidden', 'true');
1253
+ },
1254
+ );
1255
+
1256
+ await step(
1257
+ 'screen-reader: a disabled option announces its disabled state (WCAG 4.1.2)',
1258
+ async () => {
1259
+ await expect(
1260
+ body.getByRole('option', { name: 'Mango (sold out)' }),
1261
+ ).toHaveAttribute('aria-disabled', 'true');
1262
+ },
1263
+ );
1264
+
1265
+ await step(
1266
+ 'screen-reader: the chosen option announces its selected state (WCAG 4.1.2)',
1267
+ async () => {
1268
+ await userEvent.click(body.getByRole('option', { name: 'Apple' }));
1269
+ await waitFor(async () => {
1270
+ await expect(trigger).toHaveTextContent('Apple');
1271
+ });
1272
+ await waitForDropdownClosed(body);
1273
+ await userEvent.click(trigger);
1274
+ const apple = await body.findByRole('option', { name: 'Apple' });
1275
+ await expect(apple).toHaveAttribute('aria-selected', 'true');
1276
+ await expect(
1277
+ body.getByRole('option', { name: 'Banana' }),
1278
+ ).toHaveAttribute('aria-selected', 'false');
1279
+ // Close again so the end-of-play axe audit sees the resting state.
1280
+ await userEvent.keyboard('{Escape}');
1281
+ await waitForDropdownClosed(body);
1282
+ },
1283
+ );
1284
+ },
1285
+ };
1286
+
1287
+ /**
1288
+ * Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
1289
+ * try 400% reflow (WCAG 1.4.10); the trigger and the open list must stay
1290
+ * visible and operable.
1291
+ */
1292
+ export const ZoomMagnification: Story = {
1293
+ name: 'test - Zoom Magnification',
1294
+ tags: ['!dev', '!autodocs'],
1295
+ globals: { zoom: '200' },
1296
+ parameters: {
1297
+ // The accessible-reflow Chromatic mode already covers magnified snapshots.
1298
+ chromatic: { disableSnapshot: true },
1299
+ docs: {
1300
+ description: {
1301
+ story:
1302
+ 'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
1303
+ },
1304
+ },
1305
+ },
1306
+ render: renderTestSelect,
1307
+ play: async ({ canvasElement, step }) => {
1308
+ // Scenario (UiSelect): at 200% page zoom the trigger keeps its accessible
1309
+ // name and the dropdown still opens, renders readable options, and accepts
1310
+ // a selection.
1311
+ const canvas = within(canvasElement);
1312
+ const body = within(document.body);
1313
+ const trigger = canvas.getByRole('combobox', { name: 'Select option' });
1314
+
1315
+ await step(
1316
+ 'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
1317
+ async () => {
1318
+ await expect(document.documentElement.style.zoom).toBe('200%');
1319
+ },
1320
+ );
1321
+
1322
+ await step(
1323
+ 'zoom: the trigger stays visible with its accessible name',
1324
+ async () => {
1325
+ await expect(trigger).toBeVisible();
1326
+ await expect(trigger).toHaveAccessibleName('Select option');
1327
+ },
1328
+ );
1329
+
1330
+ await step(
1331
+ 'zoom: the open list remains visible and operable when magnified',
1332
+ async () => {
1333
+ await userEvent.click(trigger);
1334
+ await findOpenListbox(body);
1335
+ await userEvent.click(body.getByRole('option', { name: 'Banana' }));
1336
+ await waitFor(async () => {
1337
+ await expect(trigger).toHaveTextContent('Banana');
1338
+ });
1339
+ await waitForDropdownClosed(body);
1340
+ },
1341
+ );
1342
+ },
1343
+ };
1344
+
1345
+ /**
1346
+ * Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
1347
+ * toolbar. The trigger and the options stay operable and meet the minimum
1348
+ * touch-target size (WCAG 2.5.8).
1349
+ */
1350
+ export const MobileBreakpoint: Story = {
1351
+ name: 'test - Mobile Breakpoint',
1352
+ tags: ['!dev', '!autodocs'],
1353
+ globals: { mediaBreakpoint: 'reflow' },
1354
+ parameters: {
1355
+ // Reflow snapshots are already covered by the accessible-reflow mode.
1356
+ chromatic: { disableSnapshot: true },
1357
+ docs: {
1358
+ description: {
1359
+ story:
1360
+ 'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
1361
+ },
1362
+ },
1363
+ },
1364
+ render: renderTestSelect,
1365
+ play: async ({ canvasElement, step }) => {
1366
+ // Scenario (UiSelect): at the 320px mobile breakpoint the select stays
1367
+ // usable and both the trigger and the options meet the minimum
1368
+ // touch-target size.
1369
+ const canvas = within(canvasElement);
1370
+ const body = within(document.body);
1371
+ const trigger = canvas.getByRole('combobox', { name: 'Select option' });
1372
+
1373
+ await step(
1374
+ 'mobile: the trigger meets the minimum touch-target size (WCAG 2.5.8)',
1375
+ async () => {
1376
+ const { width, height } = trigger.getBoundingClientRect();
1377
+ await expect(width).toBeGreaterThanOrEqual(24);
1378
+ await expect(height).toBeGreaterThanOrEqual(24);
1379
+ },
1380
+ );
1381
+
1382
+ await step(
1383
+ 'mobile: the dropdown opens and options stay operable at the 320px breakpoint (WCAG 1.4.10 Reflow)',
1384
+ async () => {
1385
+ await userEvent.click(trigger);
1386
+ await findOpenListbox(body);
1387
+ await userEvent.click(body.getByRole('option', { name: 'Carrot' }));
1388
+ await waitFor(async () => {
1389
+ await expect(trigger).toHaveTextContent('Carrot');
1390
+ });
1391
+ await waitForDropdownClosed(body);
1392
+ },
1393
+ );
1394
+
1395
+ await step(
1396
+ 'mobile: options meet the minimum touch-target size (WCAG 2.5.8)',
1397
+ async () => {
1398
+ await userEvent.click(trigger);
1399
+ const option = await body.findByRole('option', { name: 'Apple' });
1400
+ const { height } = option.getBoundingClientRect();
1401
+ await expect(height).toBeGreaterThanOrEqual(24);
1402
+ // Close again so the end-of-play axe audit sees the resting state.
1403
+ await userEvent.keyboard('{Escape}');
1404
+ await waitForDropdownClosed(body);
1405
+ },
1406
+ );
1407
+ },
1408
+ };