@aleph-alpha/ui-library 5.7.0 → 5.9.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 (124) hide show
  1. package/README.md +12 -7
  2. package/config.d.ts +5 -1
  3. package/config.js +18 -1
  4. package/dist/system/__tests__/test-utils.d.ts +24 -0
  5. package/dist/system/components/UiAutocomplete/UiAutocomplete.vue.d.ts +8 -4
  6. package/dist/system/components/UiAutocomplete/types.d.ts +11 -0
  7. package/dist/system/components/UiBreadcrumb/UiBreadcrumb.vue.d.ts +17 -0
  8. package/dist/system/components/UiBreadcrumb/UiBreadcrumbEllipsis.vue.d.ts +17 -0
  9. package/dist/system/components/UiBreadcrumb/UiBreadcrumbItem.vue.d.ts +17 -0
  10. package/dist/system/components/UiBreadcrumb/UiBreadcrumbLink.vue.d.ts +18 -0
  11. package/dist/system/components/UiBreadcrumb/UiBreadcrumbList.vue.d.ts +17 -0
  12. package/dist/system/components/UiBreadcrumb/UiBreadcrumbPage.vue.d.ts +17 -0
  13. package/dist/system/components/UiBreadcrumb/UiBreadcrumbSeparator.vue.d.ts +17 -0
  14. package/dist/system/components/UiBreadcrumb/index.d.ts +8 -0
  15. package/dist/system/components/UiBreadcrumb/types.d.ts +22 -0
  16. package/dist/system/components/UiFadeMask/UiFadeMask.vue.d.ts +21 -0
  17. package/dist/system/components/UiFadeMask/index.d.ts +2 -0
  18. package/dist/system/components/UiFadeMask/types.d.ts +33 -0
  19. package/dist/system/components/UiListbox/UiListboxVirtualizer.vue.d.ts +21 -0
  20. package/dist/system/components/UiListbox/index.d.ts +1 -0
  21. package/dist/system/components/UiListbox/types.d.ts +36 -0
  22. package/dist/system/components/UiSelect/UiSelectVirtualizer.vue.d.ts +21 -0
  23. package/dist/system/components/UiSelect/index.d.ts +1 -0
  24. package/dist/system/components/UiSelect/types.d.ts +36 -0
  25. package/dist/system/components/UiToggleGroup/types.d.ts +0 -5
  26. package/dist/system/components/core/breadcrumb/Breadcrumb.vue.d.ts +21 -0
  27. package/dist/system/components/core/breadcrumb/BreadcrumbEllipsis.vue.d.ts +21 -0
  28. package/dist/system/components/core/breadcrumb/BreadcrumbItem.vue.d.ts +21 -0
  29. package/dist/system/components/core/breadcrumb/BreadcrumbLink.vue.d.ts +24 -0
  30. package/dist/system/components/core/breadcrumb/BreadcrumbList.vue.d.ts +21 -0
  31. package/dist/system/components/core/breadcrumb/BreadcrumbPage.vue.d.ts +21 -0
  32. package/dist/system/components/core/breadcrumb/BreadcrumbSeparator.vue.d.ts +21 -0
  33. package/dist/system/components/core/breadcrumb/index.d.ts +7 -0
  34. package/dist/system/components/core/listbox/Listbox.vue.d.ts +28 -2
  35. package/dist/system/components/core/listbox/context.d.ts +21 -0
  36. package/dist/system/components/core/native-select/NativeSelectOptGroup.vue.d.ts +2 -2
  37. package/dist/system/components/core/native-select/NativeSelectOption.vue.d.ts +2 -2
  38. package/dist/system/components/index.d.ts +2 -0
  39. package/dist/system/lib.js +22570 -21061
  40. package/dist/system/mobile-device-frame.png +0 -0
  41. package/dist/system/patterns/UiDatePicker/UiDatePicker.vue.d.ts +1 -1
  42. package/dist/system/patterns/UiFloatActions/types.d.ts +2 -1
  43. package/dist/system/patterns/UiProfileCard/index.d.ts +7 -0
  44. package/dist/system/patterns/UiTopBar/UiTopBar.vue.d.ts +23 -0
  45. package/dist/system/patterns/UiTopBar/index.d.ts +2 -0
  46. package/dist/system/patterns/UiTopBar/types.d.ts +28 -0
  47. package/dist/system/patterns/index.d.ts +2 -0
  48. package/dist/system/story-sidebar-icons.json +10 -1
  49. package/package.json +3 -2
  50. package/src/__tests__/test-utils.ts +74 -0
  51. package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +94 -0
  52. package/src/components/UiAutocomplete/UiAutocomplete.vue +164 -44
  53. package/src/components/UiAutocomplete/__tests__/UiAutocompleteVirtualized.test.ts +107 -0
  54. package/src/components/UiAutocomplete/types.ts +11 -0
  55. package/src/components/UiBreadcrumb/UiBreadcrumb.stories.ts +1419 -0
  56. package/src/components/UiBreadcrumb/UiBreadcrumb.vue +19 -0
  57. package/src/components/UiBreadcrumb/UiBreadcrumbEllipsis.vue +22 -0
  58. package/src/components/UiBreadcrumb/UiBreadcrumbItem.vue +19 -0
  59. package/src/components/UiBreadcrumb/UiBreadcrumbLink.vue +26 -0
  60. package/src/components/UiBreadcrumb/UiBreadcrumbList.vue +19 -0
  61. package/src/components/UiBreadcrumb/UiBreadcrumbPage.vue +19 -0
  62. package/src/components/UiBreadcrumb/UiBreadcrumbSeparator.vue +22 -0
  63. package/src/components/UiBreadcrumb/index.ts +8 -0
  64. package/src/components/UiBreadcrumb/types.ts +28 -0
  65. package/src/components/UiDropdownMenu/UiDropdownMenu.stories.ts +760 -0
  66. package/src/components/UiDropdownMenu/UiDropdownMenuTrigger.vue +2 -0
  67. package/src/components/UiFadeMask/UiFadeMask.stories.ts +563 -0
  68. package/src/components/UiFadeMask/UiFadeMask.vue +86 -0
  69. package/src/components/UiFadeMask/__tests__/UiFadeMask.test.ts +52 -0
  70. package/src/components/UiFadeMask/index.ts +6 -0
  71. package/src/components/UiFadeMask/types.ts +35 -0
  72. package/src/components/UiListbox/UiListbox.stories.ts +1404 -30
  73. package/src/components/UiListbox/UiListboxVirtualizer.vue +42 -0
  74. package/src/components/UiListbox/__tests__/UiListbox.test.ts +70 -35
  75. package/src/components/UiListbox/__tests__/UiListboxVirtualizer.test.ts +96 -0
  76. package/src/components/UiListbox/index.ts +1 -0
  77. package/src/components/UiListbox/types.ts +42 -0
  78. package/src/components/UiSelect/UiSelect.stories.ts +109 -1
  79. package/src/components/UiSelect/UiSelectVirtualizer.vue +373 -0
  80. package/src/components/UiSelect/__tests__/UiSelectVirtualizer.test.ts +185 -0
  81. package/src/components/UiSelect/index.ts +1 -0
  82. package/src/components/UiSelect/types.ts +38 -0
  83. package/src/components/UiSwitch/UiSwitch.stories.ts +706 -9
  84. package/src/components/UiSwitch/__tests__/UiSwitch.test.ts +2 -6
  85. package/src/components/UiToggle/UiToggle.stories.ts +961 -130
  86. package/src/components/UiToggle/UiToggle.vue +8 -1
  87. package/src/components/UiToggle/__tests__/UiToggle.test.ts +55 -65
  88. package/src/components/UiToggleGroup/UiToggleGroup.stories.ts +1060 -173
  89. package/src/components/UiToggleGroup/UiToggleGroup.vue +4 -2
  90. package/src/components/UiToggleGroup/__tests__/UiToggleGroup.test.ts +117 -325
  91. package/src/components/UiToggleGroup/types.ts +0 -5
  92. package/src/components/core/breadcrumb/Breadcrumb.vue +13 -0
  93. package/src/components/core/breadcrumb/BreadcrumbEllipsis.vue +23 -0
  94. package/src/components/core/breadcrumb/BreadcrumbItem.vue +17 -0
  95. package/src/components/core/breadcrumb/BreadcrumbLink.vue +29 -0
  96. package/src/components/core/breadcrumb/BreadcrumbList.vue +22 -0
  97. package/src/components/core/breadcrumb/BreadcrumbPage.vue +20 -0
  98. package/src/components/core/breadcrumb/BreadcrumbSeparator.vue +22 -0
  99. package/src/components/core/breadcrumb/index.ts +7 -0
  100. package/src/components/core/dropdown-menu/DropdownMenuCheckboxItem.vue +8 -2
  101. package/src/components/core/dropdown-menu/DropdownMenuItem.vue +1 -1
  102. package/src/components/core/dropdown-menu/DropdownMenuRadioItem.vue +8 -2
  103. package/src/components/core/dropdown-menu/DropdownMenuSubTrigger.vue +1 -1
  104. package/src/components/core/listbox/Listbox.vue +14 -2
  105. package/src/components/core/listbox/ListboxContent.vue +61 -3
  106. package/src/components/core/listbox/ListboxItem.vue +6 -1
  107. package/src/components/core/listbox/context.ts +34 -0
  108. package/src/components/core/toggle/Toggle.vue +15 -1
  109. package/src/components/core/toggle/index.ts +2 -2
  110. package/src/components/core/toggle-group/ToggleGroup.vue +1 -1
  111. package/src/components/core/toggle-group/index.ts +5 -2
  112. package/src/components/index.ts +2 -0
  113. package/src/patterns/UiFloatActions/UiFloatActions.stories.ts +4 -5
  114. package/src/patterns/UiFloatActions/UiFloatActions.vue +23 -11
  115. package/src/patterns/UiFloatActions/__tests__/UiFloatActions.test.ts +23 -0
  116. package/src/patterns/UiFloatActions/types.ts +2 -1
  117. package/src/patterns/UiProfileCard/UiProfileCard.stories.ts +1064 -0
  118. package/src/patterns/UiProfileCard/index.ts +7 -0
  119. package/src/patterns/UiTopBar/UiTopBar.stories.ts +1121 -0
  120. package/src/patterns/UiTopBar/UiTopBar.vue +166 -0
  121. package/src/patterns/UiTopBar/__tests__/UiTopBar.test.ts +245 -0
  122. package/src/patterns/UiTopBar/index.ts +2 -0
  123. package/src/patterns/UiTopBar/types.ts +29 -0
  124. package/src/patterns/index.ts +2 -0
@@ -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, computed } from 'vue';
3
4
  import { useFilter } from 'reka-ui';
4
5
  import UiListbox from './UiListbox.vue';
@@ -8,6 +9,7 @@ import UiListboxItem from './UiListboxItem.vue';
8
9
  import UiListboxItemIndicator from './UiListboxItemIndicator.vue';
9
10
  import UiListboxGroup from './UiListboxGroup.vue';
10
11
  import UiListboxGroupLabel from './UiListboxGroupLabel.vue';
12
+ import UiListboxVirtualizer from './UiListboxVirtualizer.vue';
11
13
 
12
14
  /**
13
15
  * UiListbox is a scrollable, single- or multi-select option list with optional filtering and grouping.
@@ -29,7 +31,8 @@ const meta: Meta<typeof UiListbox> = {
29
31
  },
30
32
  highlightOnHover: {
31
33
  control: 'boolean',
32
- description: 'Highlight items on hover',
34
+ description:
35
+ 'Highlight items on hover. Only applies when a `UiListboxFilter` holds the focus.',
33
36
  },
34
37
  },
35
38
  args: {
@@ -70,7 +73,7 @@ const fruits = [
70
73
 
71
74
  <template>
72
75
  <UiListbox v-model="selected" class="w-[200px] p-1">
73
- <UiListboxContent>
76
+ <UiListboxContent aria-label="Fruits">
74
77
  <UiListboxItem
75
78
  v-for="fruit in fruits"
76
79
  :key="fruit.value"
@@ -84,7 +87,8 @@ const fruits = [
84
87
  </template>`;
85
88
 
86
89
  /**
87
- * Default single-selection listbox.
90
+ * Default single-selection listbox. Selecting another option replaces the
91
+ * current one; selecting the active option again clears the selection.
88
92
  */
89
93
  export const Default: Story = {
90
94
  render: (args) => ({
@@ -105,7 +109,7 @@ export const Default: Story = {
105
109
  :disabled="args.disabled"
106
110
  :highlight-on-hover="args.highlightOnHover"
107
111
  >
108
- <UiListboxContent>
112
+ <UiListboxContent aria-label="Fruits">
109
113
  <UiListboxItem
110
114
  v-for="fruit in fruits"
111
115
  :key="fruit.value"
@@ -146,7 +150,7 @@ const fruits = [
146
150
 
147
151
  <template>
148
152
  <UiListbox v-model="selected" multiple class="w-[200px] p-1">
149
- <UiListboxContent>
153
+ <UiListboxContent aria-label="Fruits">
150
154
  <UiListboxItem
151
155
  v-for="fruit in fruits"
152
156
  :key="fruit.value"
@@ -160,7 +164,9 @@ const fruits = [
160
164
  </template>`;
161
165
 
162
166
  /**
163
- * Multiple selection listbox.
167
+ * Multiple selection listbox. Each option toggles independently, and the list
168
+ * reports `aria-multiselectable` so assistive technology announces that more
169
+ * than one option can be chosen.
164
170
  */
165
171
  export const Multiple: Story = {
166
172
  render: () => ({
@@ -176,7 +182,7 @@ export const Multiple: Story = {
176
182
  },
177
183
  template: `
178
184
  <UiListbox v-model="selected" multiple class="w-[200px] p-1">
179
- <UiListboxContent>
185
+ <UiListboxContent aria-label="Fruits">
180
186
  <UiListboxItem
181
187
  v-for="fruit in fruits"
182
188
  :key="fruit.value"
@@ -227,8 +233,13 @@ const filteredFruits = computed(() =>
227
233
 
228
234
  <template>
229
235
  <UiListbox v-model="selected" class="w-[200px]">
230
- <UiListboxFilter v-model="searchTerm" placeholder="Search fruits..." class="border-b" />
231
- <UiListboxContent class="p-1">
236
+ <UiListboxFilter
237
+ v-model="searchTerm"
238
+ placeholder="Search fruits..."
239
+ aria-label="Search fruits"
240
+ class="border-b"
241
+ />
242
+ <UiListboxContent aria-label="Fruits" class="p-1">
232
243
  <UiListboxItem
233
244
  v-for="fruit in filteredFruits"
234
245
  :key="fruit.value"
@@ -238,11 +249,21 @@ const filteredFruits = computed(() =>
238
249
  <UiListboxItemIndicator />
239
250
  </UiListboxItem>
240
251
  </UiListboxContent>
252
+ <p
253
+ v-if="filteredFruits.length === 0"
254
+ role="status"
255
+ class="px-3 py-6 text-center label-14-regular text-content-on-surface-muted"
256
+ >
257
+ No fruits match "{{ searchTerm }}"
258
+ </p>
241
259
  </UiListbox>
242
260
  </template>`;
243
261
 
244
262
  /**
245
- * Listbox with filter/search functionality.
263
+ * Listbox with filter/search functionality. The filter owns the keyboard
264
+ * focus, so the arrow keys move a virtual highlight (`aria-activedescendant`)
265
+ * instead of moving focus. Always render a no-results message so the empty
266
+ * outcome is announced rather than leaving a silent, blank list.
246
267
  */
247
268
  export const WithFilter: Story = {
248
269
  render: () => ({
@@ -268,8 +289,13 @@ export const WithFilter: Story = {
268
289
  },
269
290
  template: `
270
291
  <UiListbox v-model="selected" class="w-[200px]">
271
- <UiListboxFilter v-model="searchTerm" placeholder="Search fruits..." class="border-b" />
272
- <UiListboxContent class="p-1">
292
+ <UiListboxFilter
293
+ v-model="searchTerm"
294
+ placeholder="Search fruits..."
295
+ aria-label="Search fruits"
296
+ class="border-b"
297
+ />
298
+ <UiListboxContent aria-label="Fruits" class="p-1">
273
299
  <UiListboxItem
274
300
  v-for="fruit in filteredFruits"
275
301
  :key="fruit.value"
@@ -279,6 +305,13 @@ export const WithFilter: Story = {
279
305
  <UiListboxItemIndicator />
280
306
  </UiListboxItem>
281
307
  </UiListboxContent>
308
+ <p
309
+ v-if="filteredFruits.length === 0"
310
+ role="status"
311
+ class="px-3 py-6 text-center label-14-regular text-content-on-surface-muted"
312
+ >
313
+ No fruits match "{{ searchTerm }}"
314
+ </p>
282
315
  </UiListbox>
283
316
  `,
284
317
  }),
@@ -307,7 +340,7 @@ const selected = ref('apple')
307
340
 
308
341
  <template>
309
342
  <UiListbox v-model="selected" class="w-[200px] p-1">
310
- <UiListboxContent>
343
+ <UiListboxContent aria-label="Ingredients">
311
344
  <UiListboxGroup>
312
345
  <UiListboxGroupLabel>Fruits</UiListboxGroupLabel>
313
346
  <UiListboxItem value="apple">
@@ -335,7 +368,9 @@ const selected = ref('apple')
335
368
  </template>`;
336
369
 
337
370
  /**
338
- * Listbox with grouped items.
371
+ * Listbox with grouped items. `UiListboxGroup` wires its `UiListboxGroupLabel`
372
+ * up as the group's accessible name, so screen readers announce "Fruits" and
373
+ * "Vegetables" while moving through the options.
339
374
  */
340
375
  export const WithGroups: Story = {
341
376
  render: () => ({
@@ -353,7 +388,7 @@ export const WithGroups: Story = {
353
388
  },
354
389
  template: `
355
390
  <UiListbox v-model="selected" class="w-[200px] p-1">
356
- <UiListboxContent>
391
+ <UiListboxContent aria-label="Ingredients">
357
392
  <UiListboxGroup>
358
393
  <UiListboxGroupLabel>Fruits</UiListboxGroupLabel>
359
394
  <UiListboxItem value="apple">
@@ -389,6 +424,299 @@ export const WithGroups: Story = {
389
424
  },
390
425
  };
391
426
 
427
+ const scrollableTemplateSource = `<script setup lang="ts">
428
+ import { ref } from 'vue'
429
+ import {
430
+ UiListbox,
431
+ UiListboxContent,
432
+ UiListboxItem,
433
+ UiListboxItemIndicator
434
+ } from '@aleph-alpha/ui-library'
435
+
436
+ const selected = ref('option-1')
437
+ const options = Array.from({ length: 30 }, (_, index) => ({
438
+ value: \`option-\${index + 1}\`,
439
+ label: \`Option \${index + 1}\`,
440
+ }))
441
+ </script>
442
+
443
+ <template>
444
+ <UiListbox v-model="selected" class="w-[220px] p-1">
445
+ <UiListboxContent aria-label="Options">
446
+ <UiListboxItem
447
+ v-for="option in options"
448
+ :key="option.value"
449
+ :value="option.value"
450
+ >
451
+ <span>{{ option.label }}</span>
452
+ <UiListboxItemIndicator />
453
+ </UiListboxItem>
454
+ </UiListboxContent>
455
+ </UiListbox>
456
+ </template>`;
457
+
458
+ /**
459
+ * `UiListboxContent` caps its height and scrolls once the options overflow, so
460
+ * a long list never pushes the surrounding layout. Keyboard navigation scrolls
461
+ * the highlighted option into view automatically.
462
+ */
463
+ export const Scrollable: Story = {
464
+ render: () => ({
465
+ components: {
466
+ UiListbox,
467
+ UiListboxContent,
468
+ UiListboxItem,
469
+ UiListboxItemIndicator,
470
+ },
471
+ setup() {
472
+ const selected = ref('option-1');
473
+ const options = Array.from({ length: 30 }, (_, index) => ({
474
+ value: `option-${index + 1}`,
475
+ label: `Option ${index + 1}`,
476
+ }));
477
+ return { selected, options };
478
+ },
479
+ template: `
480
+ <UiListbox v-model="selected" class="w-[220px] p-1">
481
+ <UiListboxContent aria-label="Options">
482
+ <UiListboxItem
483
+ v-for="option in options"
484
+ :key="option.value"
485
+ :value="option.value"
486
+ >
487
+ <span>{{ option.label }}</span>
488
+ <UiListboxItemIndicator />
489
+ </UiListboxItem>
490
+ </UiListboxContent>
491
+ </UiListbox>
492
+ `,
493
+ }),
494
+ parameters: {
495
+ docs: {
496
+ source: {
497
+ code: scrollableTemplateSource,
498
+ },
499
+ },
500
+ },
501
+ play: async ({ canvasElement, step }) => {
502
+ // Scenario (List content): a long option list stays inside a fixed-height
503
+ // scroll container, and scrolling reveals the options further down.
504
+ const canvas = within(canvasElement);
505
+ const list = canvas.getByRole('listbox', { name: 'Options' });
506
+
507
+ await step(
508
+ 'interaction: the list keeps every option reachable in one scroll container',
509
+ async () => {
510
+ await expect(canvas.getAllByRole('option')).toHaveLength(30);
511
+ await expect(list.scrollHeight).toBeGreaterThan(list.clientHeight);
512
+ },
513
+ );
514
+
515
+ await step(
516
+ 'interaction: scrolling moves down the list without clipping options',
517
+ async () => {
518
+ list.scrollTop = list.scrollHeight;
519
+ await waitFor(async () => {
520
+ await expect(list.scrollTop).toBeGreaterThan(0);
521
+ });
522
+ await expect(
523
+ canvas.getByRole('option', { name: 'Option 30' }),
524
+ ).toBeVisible();
525
+ // Restore the resting state so the visual snapshot stays stable.
526
+ list.scrollTop = 0;
527
+ },
528
+ );
529
+ },
530
+ };
531
+
532
+ const virtualizedTemplateSource = `<script setup lang="ts">
533
+ import { ref } from 'vue'
534
+ import {
535
+ UiListbox,
536
+ UiListboxContent,
537
+ UiListboxItem,
538
+ UiListboxItemIndicator,
539
+ UiListboxVirtualizer
540
+ } from '@aleph-alpha/ui-library'
541
+
542
+ const selected = ref('Option 1')
543
+ const options = Array.from({ length: 10000 }, (_, index) => 'Option ' + (index + 1))
544
+ </script>
545
+
546
+ <template>
547
+ <UiListbox v-model="selected" class="w-[220px] p-1">
548
+ <UiListboxContent aria-label="Options">
549
+ <UiListboxVirtualizer v-slot="{ option }" :options="options">
550
+ <UiListboxItem :value="option">
551
+ <span>{{ option }}</span>
552
+ <UiListboxItemIndicator />
553
+ </UiListboxItem>
554
+ </UiListboxVirtualizer>
555
+ </UiListboxContent>
556
+ </UiListbox>
557
+ </template>`;
558
+
559
+ /**
560
+ * `UiListboxVirtualizer` mounts only the options that are in view, so a list of
561
+ * thousands stays as fast as a short one. The scrollbar, keyboard navigation
562
+ * and type-ahead still cover the full list. Pass `textContent` when the options
563
+ * are objects, so type-ahead knows what to match on, and `estimateSize` when an
564
+ * option is not the default 28px tall.
565
+ */
566
+ export const Virtualized: Story = {
567
+ render: () => ({
568
+ components: {
569
+ UiListbox,
570
+ UiListboxContent,
571
+ UiListboxItem,
572
+ UiListboxItemIndicator,
573
+ UiListboxVirtualizer,
574
+ },
575
+ setup() {
576
+ const selected = ref('Option 1');
577
+ const options = Array.from(
578
+ { length: 10000 },
579
+ (_, index) => `Option ${index + 1}`,
580
+ );
581
+ return { selected, options };
582
+ },
583
+ template: `
584
+ <UiListbox v-model="selected" class="w-[220px] p-1">
585
+ <UiListboxContent aria-label="Options">
586
+ <UiListboxVirtualizer v-slot="{ option }" :options="options">
587
+ <UiListboxItem :value="option">
588
+ <span>{{ option }}</span>
589
+ <UiListboxItemIndicator />
590
+ </UiListboxItem>
591
+ </UiListboxVirtualizer>
592
+ </UiListboxContent>
593
+ </UiListbox>
594
+ `,
595
+ }),
596
+ parameters: {
597
+ docs: {
598
+ source: {
599
+ code: virtualizedTemplateSource,
600
+ },
601
+ },
602
+ },
603
+ play: async ({ canvasElement, step }) => {
604
+ // Scenario (List content): a 10,000 option list keeps only the visible
605
+ // options in the DOM, and scrolling swaps in the ones further down while
606
+ // every option keeps its place in the full list.
607
+ const canvas = within(canvasElement);
608
+ const list = canvas.getByRole('listbox', { name: 'Options' });
609
+
610
+ await step(
611
+ 'interaction: only the options in view are in the DOM',
612
+ async () => {
613
+ const rendered = canvas.getAllByRole('option');
614
+ await expect(rendered.length).toBeGreaterThan(0);
615
+ await expect(rendered.length).toBeLessThan(100);
616
+ },
617
+ );
618
+
619
+ await step(
620
+ 'screen-reader: an option announces its place in the full list (WCAG 4.1.2)',
621
+ async () => {
622
+ const first = canvas.getByRole('option', { name: 'Option 1' });
623
+ await expect(first).toHaveAttribute('aria-setsize', '10000');
624
+ await expect(first).toHaveAttribute('aria-posinset', '1');
625
+ },
626
+ );
627
+
628
+ await step(
629
+ 'interaction: scrolling mounts the options further down the list',
630
+ async () => {
631
+ list.scrollTop = list.scrollHeight;
632
+ await waitFor(async () => {
633
+ await expect(
634
+ canvas.getByRole('option', { name: 'Option 10000' }),
635
+ ).toBeVisible();
636
+ });
637
+ await expect(canvas.queryByRole('option', { name: 'Option 1' })).toBe(
638
+ null,
639
+ );
640
+ // Restore the resting state so the visual snapshot stays stable.
641
+ list.scrollTop = 0;
642
+ await waitFor(async () => {
643
+ await expect(
644
+ canvas.getByRole('option', { name: 'Option 1' }),
645
+ ).toBeVisible();
646
+ });
647
+ },
648
+ );
649
+ },
650
+ };
651
+
652
+ const emptyStateTemplateSource = `<script setup lang="ts">
653
+ import { ref } from 'vue'
654
+ import { UiListbox, UiListboxContent } from '@aleph-alpha/ui-library'
655
+
656
+ const selected = ref<string>()
657
+ const savedFilters: { value: string; label: string }[] = []
658
+ </script>
659
+
660
+ <template>
661
+ <UiListbox v-model="selected" class="w-[220px] p-1">
662
+ <UiListboxContent aria-label="Saved filters" />
663
+ <p class="px-3 py-6 text-center label-14-regular text-content-on-surface-muted">
664
+ No saved filters yet
665
+ </p>
666
+ </UiListbox>
667
+ </template>`;
668
+
669
+ /**
670
+ * An empty listbox still exposes the list to assistive technology, so pair it
671
+ * with a short message that explains why there is nothing to choose from.
672
+ */
673
+ export const EmptyState: Story = {
674
+ render: () => ({
675
+ components: { UiListbox, UiListboxContent },
676
+ setup() {
677
+ const selected = ref<string>();
678
+ return { selected };
679
+ },
680
+ template: `
681
+ <UiListbox v-model="selected" class="w-[220px] p-1">
682
+ <UiListboxContent aria-label="Saved filters" />
683
+ <p class="px-3 py-6 text-center label-14-regular text-content-on-surface-muted">
684
+ No saved filters yet
685
+ </p>
686
+ </UiListbox>
687
+ `,
688
+ }),
689
+ parameters: {
690
+ docs: {
691
+ source: {
692
+ code: emptyStateTemplateSource,
693
+ },
694
+ },
695
+ },
696
+ play: async ({ canvasElement, step }) => {
697
+ // Scenario (List content): with nothing to choose from, the list is still
698
+ // exposed but empty, and the reason is spelled out in visible text.
699
+ const canvas = within(canvasElement);
700
+
701
+ await step(
702
+ 'interaction: the empty list exposes no selectable options',
703
+ async () => {
704
+ await expect(
705
+ canvas.getByRole('listbox', { name: 'Saved filters' }),
706
+ ).toBeVisible();
707
+ await expect(canvas.queryAllByRole('option')).toHaveLength(0);
708
+ },
709
+ );
710
+
711
+ await step(
712
+ 'interaction: the empty state explains why the list is empty',
713
+ async () => {
714
+ await expect(canvas.getByText('No saved filters yet')).toBeVisible();
715
+ },
716
+ );
717
+ },
718
+ };
719
+
392
720
  const disabledTemplateSource = `<script setup lang="ts">
393
721
  import { ref } from 'vue'
394
722
  import {
@@ -408,7 +736,7 @@ const fruits = [
408
736
 
409
737
  <template>
410
738
  <UiListbox v-model="selected" disabled class="w-[200px] p-1">
411
- <UiListboxContent>
739
+ <UiListboxContent aria-label="Fruits">
412
740
  <UiListboxItem
413
741
  v-for="fruit in fruits"
414
742
  :key="fruit.value"
@@ -422,7 +750,8 @@ const fruits = [
422
750
  </template>`;
423
751
 
424
752
  /**
425
- * Disabled listbox.
753
+ * Disabled listbox. The list and every option report `aria-disabled`, so the
754
+ * state is announced instead of being conveyed by dimming alone.
426
755
  */
427
756
  export const Disabled: Story = {
428
757
  args: {
@@ -441,7 +770,7 @@ export const Disabled: Story = {
441
770
  },
442
771
  template: `
443
772
  <UiListbox v-model="selected" disabled class="w-[200px] p-1">
444
- <UiListboxContent>
773
+ <UiListboxContent aria-label="Fruits">
445
774
  <UiListboxItem
446
775
  v-for="fruit in fruits"
447
776
  :key="fruit.value"
@@ -461,30 +790,76 @@ export const Disabled: Story = {
461
790
  },
462
791
  },
463
792
  },
793
+ play: async ({ canvasElement, step }) => {
794
+ // Scenario (Listbox): the whole list is turned off — the state is exposed
795
+ // to assistive technology and clicks cannot change the selection.
796
+ const canvas = within(canvasElement);
797
+ const list = canvas.getByRole('listbox', { name: 'Fruits' });
798
+
799
+ await step(
800
+ 'interaction: the list reports its disabled state (WCAG 4.1.2)',
801
+ async () => {
802
+ await expect(list).toHaveAttribute('aria-disabled', 'true');
803
+ for (const option of canvas.getAllByRole('option')) {
804
+ await expect(option).toHaveAttribute('aria-disabled', 'true');
805
+ }
806
+ },
807
+ );
808
+
809
+ await step(
810
+ 'interaction: clicking an option in a disabled list does not change the selection',
811
+ async () => {
812
+ const banana = canvas.getByRole('option', { name: 'Banana' });
813
+ // Disabled options render with pointer-events: none, so bypass the
814
+ // check and assert the click is still a no-op.
815
+ await userEvent.click(banana, { pointerEventsCheck: 0 });
816
+ await expect(banana).toHaveAttribute('aria-selected', 'false');
817
+ await expect(
818
+ canvas.getByRole('option', { name: 'Apple' }),
819
+ ).toHaveAttribute('aria-selected', 'true');
820
+ },
821
+ );
822
+ },
464
823
  };
465
824
 
466
825
  const highlightOnHoverTemplateSource = `<script setup lang="ts">
467
- import { ref } from 'vue'
826
+ import { ref, computed } from 'vue'
827
+ import { useFilter } from 'reka-ui'
468
828
  import {
469
829
  UiListbox,
470
830
  UiListboxContent,
831
+ UiListboxFilter,
471
832
  UiListboxItem,
472
833
  UiListboxItemIndicator
473
834
  } from '@aleph-alpha/ui-library'
474
835
 
475
836
  const selected = ref('apple')
837
+ const searchTerm = ref('')
476
838
  const fruits = [
477
839
  { value: 'apple', label: 'Apple' },
478
840
  { value: 'banana', label: 'Banana' },
479
841
  { value: 'cherry', label: 'Cherry' },
480
842
  ]
843
+
844
+ const { contains } = useFilter({ sensitivity: 'base' })
845
+ const filteredFruits = computed(() =>
846
+ searchTerm.value === ''
847
+ ? fruits
848
+ : fruits.filter(fruit => contains(fruit.label, searchTerm.value))
849
+ )
481
850
  </script>
482
851
 
483
852
  <template>
484
- <UiListbox v-model="selected" highlight-on-hover class="w-[200px] p-1">
485
- <UiListboxContent>
853
+ <UiListbox v-model="selected" highlight-on-hover class="w-[200px]">
854
+ <UiListboxFilter
855
+ v-model="searchTerm"
856
+ placeholder="Search fruits..."
857
+ aria-label="Search fruits"
858
+ class="border-b"
859
+ />
860
+ <UiListboxContent aria-label="Fruits" class="p-1">
486
861
  <UiListboxItem
487
- v-for="fruit in fruits"
862
+ v-for="fruit in filteredFruits"
488
863
  :key="fruit.value"
489
864
  :value="fruit.value"
490
865
  >
@@ -496,7 +871,10 @@ const fruits = [
496
871
  </template>`;
497
872
 
498
873
  /**
499
- * Listbox with highlight on hover enabled.
874
+ * `highlightOnHover` keeps the pointer and the keyboard on the same active
875
+ * option. It only applies while a `UiListboxFilter` holds the focus — without
876
+ * a filter the options are focusable themselves and the browser's own focus
877
+ * already tracks the active option.
500
878
  */
501
879
  export const HighlightOnHover: Story = {
502
880
  args: {
@@ -506,18 +884,34 @@ export const HighlightOnHover: Story = {
506
884
  components: {
507
885
  UiListbox,
508
886
  UiListboxContent,
887
+ UiListboxFilter,
509
888
  UiListboxItem,
510
889
  UiListboxItemIndicator,
511
890
  },
512
891
  setup() {
513
892
  const selected = ref('apple');
514
- return { selected, fruits };
893
+ const searchTerm = ref('');
894
+ const { contains } = useFilter({ sensitivity: 'base' });
895
+
896
+ const filteredFruits = computed(() =>
897
+ searchTerm.value === ''
898
+ ? fruits
899
+ : fruits.filter((fruit) => contains(fruit.label, searchTerm.value)),
900
+ );
901
+
902
+ return { selected, searchTerm, filteredFruits };
515
903
  },
516
904
  template: `
517
- <UiListbox v-model="selected" highlight-on-hover class="w-[200px] p-1">
518
- <UiListboxContent>
905
+ <UiListbox v-model="selected" highlight-on-hover class="w-[200px]">
906
+ <UiListboxFilter
907
+ v-model="searchTerm"
908
+ placeholder="Search fruits..."
909
+ aria-label="Search fruits"
910
+ class="border-b"
911
+ />
912
+ <UiListboxContent aria-label="Fruits" class="p-1">
519
913
  <UiListboxItem
520
- v-for="fruit in fruits"
914
+ v-for="fruit in filteredFruits"
521
915
  :key="fruit.value"
522
916
  :value="fruit.value"
523
917
  >
@@ -551,7 +945,7 @@ const selected = ref('apple')
551
945
 
552
946
  <template>
553
947
  <UiListbox v-model="selected" class="w-[200px] p-1">
554
- <UiListboxContent>
948
+ <UiListboxContent aria-label="Fruits">
555
949
  <UiListboxItem value="apple">
556
950
  <span>Apple</span>
557
951
  <UiListboxItemIndicator />
@@ -569,7 +963,8 @@ const selected = ref('apple')
569
963
  </template>`;
570
964
 
571
965
  /**
572
- * Listbox with some disabled items.
966
+ * Listbox with some disabled items. Keep unavailable options in the list so
967
+ * the full set of choices stays visible, and say why in the label.
573
968
  */
574
969
  export const WithDisabledItems: Story = {
575
970
  render: () => ({
@@ -585,7 +980,7 @@ export const WithDisabledItems: Story = {
585
980
  },
586
981
  template: `
587
982
  <UiListbox v-model="selected" class="w-[200px] p-1">
588
- <UiListboxContent>
983
+ <UiListboxContent aria-label="Fruits">
589
984
  <UiListboxItem value="apple">
590
985
  <span>Apple</span>
591
986
  <UiListboxItemIndicator />
@@ -609,4 +1004,983 @@ export const WithDisabledItems: Story = {
609
1004
  },
610
1005
  },
611
1006
  },
1007
+ play: async ({ canvasElement, step }) => {
1008
+ // Scenario (Option): a single unavailable option stays listed and
1009
+ // announced, but cannot be chosen.
1010
+ const canvas = within(canvasElement);
1011
+ const banana = canvas.getByRole('option', { name: 'Banana (unavailable)' });
1012
+
1013
+ await step(
1014
+ 'interaction: the unavailable option stays in the list and reports its state (WCAG 4.1.2)',
1015
+ async () => {
1016
+ await expect(banana).toBeVisible();
1017
+ await expect(banana).toHaveAttribute('aria-disabled', 'true');
1018
+ await expect(
1019
+ canvas.getByRole('option', { name: 'Cherry' }),
1020
+ ).not.toHaveAttribute('aria-disabled');
1021
+ },
1022
+ );
1023
+
1024
+ await step(
1025
+ 'interaction: a disabled option cannot be selected',
1026
+ async () => {
1027
+ // Disabled options render with pointer-events: none, so bypass the
1028
+ // check and assert the click is still a no-op.
1029
+ await userEvent.click(banana, { pointerEventsCheck: 0 });
1030
+ await expect(banana).toHaveAttribute('aria-selected', 'false');
1031
+ await expect(
1032
+ canvas.getByRole('option', { name: 'Apple' }),
1033
+ ).toHaveAttribute('aria-selected', 'true');
1034
+ },
1035
+ );
1036
+ },
1037
+ };
1038
+
1039
+ /**
1040
+ * Accessibility guidance for listboxes: a meaningful list name, labelled
1041
+ * groups, an announced selection, and a spoken empty state — shown side by
1042
+ * side in the default and accessible themes.
1043
+ */
1044
+ export const Accessibility: Story = {
1045
+ tags: ['!autodocs'],
1046
+ parameters: {
1047
+ a11y: { test: 'off' },
1048
+ chromatic: { disableSnapshot: true },
1049
+ docs: {
1050
+ canvas: {
1051
+ sourceState: 'none',
1052
+ },
1053
+ },
1054
+ },
1055
+ render: () => ({
1056
+ components: {
1057
+ UiListbox,
1058
+ UiListboxContent,
1059
+ UiListboxFilter,
1060
+ UiListboxItem,
1061
+ UiListboxItemIndicator,
1062
+ UiListboxGroup,
1063
+ UiListboxGroupLabel,
1064
+ },
1065
+ setup() {
1066
+ const defaultValue = ref('apple');
1067
+ const accessibleValue = ref('apple');
1068
+ const defaultTerm = ref('');
1069
+ const accessibleTerm = ref('');
1070
+ return {
1071
+ defaultValue,
1072
+ accessibleValue,
1073
+ defaultTerm,
1074
+ accessibleTerm,
1075
+ };
1076
+ },
1077
+ template: `
1078
+ <section class="flex flex-col gap-6 p-4">
1079
+ <div>
1080
+ <h2 class="heading-m font-bold text-content-on-surface-primary">
1081
+ Accessibility
1082
+ </h2>
1083
+ </div>
1084
+
1085
+ <div class="flex flex-col gap-6">
1086
+ <div class="flex flex-col gap-2">
1087
+ <h3 class="body-16-medium text-content-on-surface-primary">
1088
+ Give the list a meaningful name
1089
+ </h3>
1090
+ <p class="body-16-regular text-content-on-surface-primary">
1091
+ <code>UiListboxContent</code> falls back to the generic name
1092
+ "Options". Set <code>aria-label</code> (or point
1093
+ <code>aria-labelledby</code> at a visible heading) so the list is
1094
+ announced as what it actually contains.
1095
+ </p>
1096
+ </div>
1097
+
1098
+ <div class="flex flex-col gap-2">
1099
+ <h3 class="body-16-medium text-content-on-surface-primary">
1100
+ Label the filter input
1101
+ </h3>
1102
+ <p class="body-16-regular text-content-on-surface-primary">
1103
+ The placeholder disappears as soon as the user types, so it is not
1104
+ a label. Give <code>UiListboxFilter</code> its own
1105
+ <code>aria-label</code>.
1106
+ </p>
1107
+ </div>
1108
+
1109
+ <div class="flex flex-col gap-2">
1110
+ <h3 class="body-16-medium text-content-on-surface-primary">
1111
+ Group related options and label the groups
1112
+ </h3>
1113
+ <p class="body-16-regular text-content-on-surface-primary">
1114
+ Long flat lists are hard to scan and to listen to. Wrap related
1115
+ options in <code>UiListboxGroup</code> with a
1116
+ <code>UiListboxGroupLabel</code> so each group is announced with
1117
+ its name.
1118
+ </p>
1119
+ </div>
1120
+
1121
+ <div class="flex flex-col gap-2">
1122
+ <h3 class="body-16-medium text-content-on-surface-primary">
1123
+ Do not rely on the indicator alone
1124
+ </h3>
1125
+ <p class="body-16-regular text-content-on-surface-primary">
1126
+ <code>UiListboxItemIndicator</code> is decorative and hidden from
1127
+ assistive technology. The selected state is carried by
1128
+ <code>aria-selected</code> on the option, which the component sets
1129
+ for you — keep the indicator as the visible counterpart.
1130
+ </p>
1131
+ </div>
1132
+
1133
+ <div class="flex flex-col gap-2">
1134
+ <h3 class="body-16-medium text-content-on-surface-primary">
1135
+ Announce the empty and no-results states
1136
+ </h3>
1137
+ <p class="body-16-regular text-content-on-surface-primary">
1138
+ A list that filters down to nothing is silent. Render a short
1139
+ message in a <code>role="status"</code> region so the outcome is
1140
+ spoken instead of leaving a blank panel.
1141
+ </p>
1142
+ </div>
1143
+
1144
+ <div class="flex flex-col gap-2">
1145
+ <h3 class="body-16-medium text-content-on-surface-primary">
1146
+ Enable accessibility theme
1147
+ </h3>
1148
+ <p class="body-16-regular text-content-on-surface-primary">
1149
+ When accessibility is required, enable our accessibility theme.
1150
+ This increases contrast and makes sure there are no color
1151
+ contrast issues.
1152
+ </p>
1153
+ </div>
1154
+ </div>
1155
+
1156
+ <div class="grid gap-4 md:grid-cols-2">
1157
+ <div class="flex flex-col gap-3">
1158
+ <h3 class="label-16-medium text-center text-content-on-surface-primary">
1159
+ Default
1160
+ </h3>
1161
+ <div class="flex min-h-20 items-center justify-center border border-border-surface-default p-6">
1162
+ <UiListbox v-model="defaultValue" class="w-[200px]">
1163
+ <UiListboxFilter
1164
+ v-model="defaultTerm"
1165
+ placeholder="Search food..."
1166
+ aria-label="Search food"
1167
+ class="border-b"
1168
+ />
1169
+ <UiListboxContent aria-label="Food" class="p-1">
1170
+ <UiListboxGroup>
1171
+ <UiListboxGroupLabel>Fruits</UiListboxGroupLabel>
1172
+ <UiListboxItem value="apple">
1173
+ <span>Apple</span>
1174
+ <UiListboxItemIndicator />
1175
+ </UiListboxItem>
1176
+ <UiListboxItem value="mango" disabled>
1177
+ <span>Mango (sold out)</span>
1178
+ <UiListboxItemIndicator />
1179
+ </UiListboxItem>
1180
+ </UiListboxGroup>
1181
+ <UiListboxGroup>
1182
+ <UiListboxGroupLabel>Vegetables</UiListboxGroupLabel>
1183
+ <UiListboxItem value="carrot">
1184
+ <span>Carrot</span>
1185
+ <UiListboxItemIndicator />
1186
+ </UiListboxItem>
1187
+ </UiListboxGroup>
1188
+ </UiListboxContent>
1189
+ </UiListbox>
1190
+ </div>
1191
+ </div>
1192
+
1193
+ <div class="accessible-theme flex flex-col gap-3">
1194
+ <h3 class="label-16-medium text-center text-content-on-surface-primary">
1195
+ Accessible
1196
+ </h3>
1197
+ <div class="flex min-h-20 items-center justify-center border border-border-surface-default p-6">
1198
+ <UiListbox v-model="accessibleValue" class="w-[200px]">
1199
+ <UiListboxFilter
1200
+ v-model="accessibleTerm"
1201
+ placeholder="Search food..."
1202
+ aria-label="Search food"
1203
+ class="border-b"
1204
+ />
1205
+ <UiListboxContent aria-label="Food" class="p-1">
1206
+ <UiListboxGroup>
1207
+ <UiListboxGroupLabel>Fruits</UiListboxGroupLabel>
1208
+ <UiListboxItem value="apple">
1209
+ <span>Apple</span>
1210
+ <UiListboxItemIndicator />
1211
+ </UiListboxItem>
1212
+ <UiListboxItem value="mango" disabled>
1213
+ <span>Mango (sold out)</span>
1214
+ <UiListboxItemIndicator />
1215
+ </UiListboxItem>
1216
+ </UiListboxGroup>
1217
+ <UiListboxGroup>
1218
+ <UiListboxGroupLabel>Vegetables</UiListboxGroupLabel>
1219
+ <UiListboxItem value="carrot">
1220
+ <span>Carrot</span>
1221
+ <UiListboxItemIndicator />
1222
+ </UiListboxItem>
1223
+ </UiListboxGroup>
1224
+ </UiListboxContent>
1225
+ </UiListbox>
1226
+ </div>
1227
+ </div>
1228
+ </div>
1229
+ </section>
1230
+ `,
1231
+ }),
1232
+ };
1233
+
1234
+ // Test-only stories drive the test-runner (interactive/a11y checks) but are
1235
+ // hidden from the Storybook sidebar and docs via the `!dev` / `!autodocs`
1236
+ // tags. They keep the implicit `test` tag, so they still run in CI and appear
1237
+ // in the automated report under their `test - …` name. `name`/`tags` must be
1238
+ // literal properties so Storybook's static CSF indexer can read them.
1239
+
1240
+ // Shared render for the keyboard scenario: no filter, so the options own the
1241
+ // focus via a roving tabindex. The leading button is the anchor the test tabs
1242
+ // from, since the list highlights its first option as soon as it mounts.
1243
+ function renderKeyboardListbox() {
1244
+ return {
1245
+ components: {
1246
+ UiListbox,
1247
+ UiListboxContent,
1248
+ UiListboxItem,
1249
+ UiListboxItemIndicator,
1250
+ UiListboxGroup,
1251
+ UiListboxGroupLabel,
1252
+ },
1253
+ setup() {
1254
+ const selected = ref<string>();
1255
+ return { selected };
1256
+ },
1257
+ template: `
1258
+ <div class="flex flex-col items-start gap-3">
1259
+ <button type="button" class="rounded-md border border-border-surface-default px-3 py-1.5 label-14-regular">
1260
+ Before the list
1261
+ </button>
1262
+ <UiListbox v-model="selected" class="w-[220px] p-1">
1263
+ <UiListboxContent aria-label="Food">
1264
+ <UiListboxGroup>
1265
+ <UiListboxGroupLabel>Fruits</UiListboxGroupLabel>
1266
+ <UiListboxItem value="apple"><span>Apple</span><UiListboxItemIndicator /></UiListboxItem>
1267
+ <UiListboxItem value="mango" disabled><span>Mango (sold out)</span><UiListboxItemIndicator /></UiListboxItem>
1268
+ <UiListboxItem value="banana"><span>Banana</span><UiListboxItemIndicator /></UiListboxItem>
1269
+ </UiListboxGroup>
1270
+ <UiListboxGroup>
1271
+ <UiListboxGroupLabel>Vegetables</UiListboxGroupLabel>
1272
+ <UiListboxItem value="carrot"><span>Carrot</span><UiListboxItemIndicator /></UiListboxItem>
1273
+ </UiListboxGroup>
1274
+ </UiListboxContent>
1275
+ </UiListbox>
1276
+ </div>
1277
+ `,
1278
+ };
1279
+ }
1280
+
1281
+ // Shared render for the filter scenarios: the filter owns the focus, the
1282
+ // options are highlighted virtually, and an empty result set is announced.
1283
+ function renderFilterListbox() {
1284
+ return {
1285
+ components: {
1286
+ UiListbox,
1287
+ UiListboxContent,
1288
+ UiListboxFilter,
1289
+ UiListboxItem,
1290
+ UiListboxItemIndicator,
1291
+ UiListboxGroup,
1292
+ UiListboxGroupLabel,
1293
+ },
1294
+ setup() {
1295
+ const selected = ref<string>();
1296
+ const searchTerm = ref('');
1297
+ const { contains } = useFilter({ sensitivity: 'base' });
1298
+ const food = [
1299
+ { value: 'apple', label: 'Apple', group: 'Fruits' },
1300
+ { value: 'mango', label: 'Mango (sold out)', group: 'Fruits' },
1301
+ { value: 'banana', label: 'Banana', group: 'Fruits' },
1302
+ { value: 'carrot', label: 'Carrot', group: 'Vegetables' },
1303
+ ];
1304
+ const matches = computed(() =>
1305
+ searchTerm.value === ''
1306
+ ? food
1307
+ : food.filter((item) => contains(item.label, searchTerm.value)),
1308
+ );
1309
+ const fruitMatches = computed(() =>
1310
+ matches.value.filter((item) => item.group === 'Fruits'),
1311
+ );
1312
+ const vegetableMatches = computed(() =>
1313
+ matches.value.filter((item) => item.group === 'Vegetables'),
1314
+ );
1315
+ return { selected, searchTerm, matches, fruitMatches, vegetableMatches };
1316
+ },
1317
+ template: `
1318
+ <UiListbox v-model="selected" highlight-on-hover class="w-[220px]">
1319
+ <UiListboxFilter
1320
+ v-model="searchTerm"
1321
+ placeholder="Search food..."
1322
+ aria-label="Search food"
1323
+ class="border-b"
1324
+ />
1325
+ <UiListboxContent aria-label="Food" class="p-1">
1326
+ <UiListboxGroup v-if="fruitMatches.length">
1327
+ <UiListboxGroupLabel>Fruits</UiListboxGroupLabel>
1328
+ <UiListboxItem
1329
+ v-for="item in fruitMatches"
1330
+ :key="item.value"
1331
+ :value="item.value"
1332
+ :disabled="item.value === 'mango'"
1333
+ >
1334
+ <span>{{ item.label }}</span>
1335
+ <UiListboxItemIndicator />
1336
+ </UiListboxItem>
1337
+ </UiListboxGroup>
1338
+ <UiListboxGroup v-if="vegetableMatches.length">
1339
+ <UiListboxGroupLabel>Vegetables</UiListboxGroupLabel>
1340
+ <UiListboxItem
1341
+ v-for="item in vegetableMatches"
1342
+ :key="item.value"
1343
+ :value="item.value"
1344
+ >
1345
+ <span>{{ item.label }}</span>
1346
+ <UiListboxItemIndicator />
1347
+ </UiListboxItem>
1348
+ </UiListboxGroup>
1349
+ </UiListboxContent>
1350
+ <p
1351
+ v-if="matches.length === 0"
1352
+ role="status"
1353
+ class="px-3 py-6 text-center label-14-regular text-content-on-surface-muted"
1354
+ >
1355
+ No food matches "{{ searchTerm }}"
1356
+ </p>
1357
+ </UiListbox>
1358
+ `,
1359
+ };
1360
+ }
1361
+
1362
+ /**
1363
+ * Single selection: choosing an option marks it, marks it with the indicator,
1364
+ * replaces any earlier choice, and choosing it again clears the selection.
1365
+ */
1366
+ export const SingleSelection: Story = {
1367
+ name: 'test - Single Selection',
1368
+ tags: ['!dev', '!autodocs'],
1369
+ parameters: {
1370
+ // The play changes the selection and moves focus into the list.
1371
+ chromatic: { disableSnapshot: true },
1372
+ docs: {
1373
+ description: {
1374
+ story:
1375
+ 'Select an option, replace it with another, and clear it by selecting it again.',
1376
+ },
1377
+ },
1378
+ },
1379
+ render: () => ({
1380
+ components: {
1381
+ UiListbox,
1382
+ UiListboxContent,
1383
+ UiListboxItem,
1384
+ UiListboxItemIndicator,
1385
+ },
1386
+ setup() {
1387
+ const selected = ref('apple');
1388
+ return { selected, fruits };
1389
+ },
1390
+ template: `
1391
+ <UiListbox v-model="selected" class="w-[200px] p-1">
1392
+ <UiListboxContent aria-label="Fruits">
1393
+ <UiListboxItem
1394
+ v-for="fruit in fruits"
1395
+ :key="fruit.value"
1396
+ :value="fruit.value"
1397
+ >
1398
+ <span>{{ fruit.label }}</span>
1399
+ <UiListboxItemIndicator />
1400
+ </UiListboxItem>
1401
+ </UiListboxContent>
1402
+ </UiListbox>
1403
+ `,
1404
+ }),
1405
+ play: async ({ canvasElement, step }) => {
1406
+ // Scenario (Listbox / Option / Selected indicator): a pointer user picks a
1407
+ // different fruit, sees the indicator follow the selection, and clears it
1408
+ // again by re-selecting the same option.
1409
+ const canvas = within(canvasElement);
1410
+ const apple = canvas.getByRole('option', { name: 'Apple' });
1411
+ const banana = canvas.getByRole('option', { name: 'Banana' });
1412
+ const indicator = (option: HTMLElement) =>
1413
+ option.querySelector('[data-slot="listbox-item-indicator"]');
1414
+
1415
+ await step(
1416
+ 'interaction: only the selected option is marked as selected',
1417
+ async () => {
1418
+ await expect(apple).toHaveAttribute('aria-selected', 'true');
1419
+ await expect(banana).toHaveAttribute('aria-selected', 'false');
1420
+ },
1421
+ );
1422
+
1423
+ await step(
1424
+ 'interaction: the selected indicator marks the current selection',
1425
+ async () => {
1426
+ await expect(indicator(apple)).toBeVisible();
1427
+ await expect(indicator(banana)).toBeNull();
1428
+ },
1429
+ );
1430
+
1431
+ await step(
1432
+ 'interaction: selecting another option replaces the previous selection',
1433
+ async () => {
1434
+ await userEvent.click(banana);
1435
+ await waitFor(async () => {
1436
+ await expect(banana).toHaveAttribute('aria-selected', 'true');
1437
+ });
1438
+ await expect(apple).toHaveAttribute('aria-selected', 'false');
1439
+ await expect(indicator(banana)).toBeVisible();
1440
+ await expect(indicator(apple)).toBeNull();
1441
+ },
1442
+ );
1443
+
1444
+ await step(
1445
+ 'interaction: selecting the active option again deselects it',
1446
+ async () => {
1447
+ await userEvent.click(banana);
1448
+ await waitFor(async () => {
1449
+ await expect(banana).toHaveAttribute('aria-selected', 'false');
1450
+ });
1451
+ await expect(indicator(banana)).toBeNull();
1452
+ await expect(
1453
+ canvas.queryAllByRole('option', { selected: true }),
1454
+ ).toHaveLength(0);
1455
+ },
1456
+ );
1457
+ },
1458
+ };
1459
+
1460
+ /**
1461
+ * Multiple selection: options toggle independently, the list advertises
1462
+ * `aria-multiselectable`, and every chosen option keeps its indicator.
1463
+ */
1464
+ export const MultipleSelection: Story = {
1465
+ name: 'test - Multiple Selection',
1466
+ tags: ['!dev', '!autodocs'],
1467
+ parameters: {
1468
+ // The play changes the selection and moves focus into the list.
1469
+ chromatic: { disableSnapshot: true },
1470
+ docs: {
1471
+ description: {
1472
+ story:
1473
+ 'Add and remove options from a multi-select list and check the indicators keep up.',
1474
+ },
1475
+ },
1476
+ },
1477
+ render: () => ({
1478
+ components: {
1479
+ UiListbox,
1480
+ UiListboxContent,
1481
+ UiListboxItem,
1482
+ UiListboxItemIndicator,
1483
+ },
1484
+ setup() {
1485
+ const selected = ref(['apple', 'cherry']);
1486
+ return { selected, fruits };
1487
+ },
1488
+ template: `
1489
+ <UiListbox v-model="selected" multiple class="w-[200px] p-1">
1490
+ <UiListboxContent aria-label="Fruits">
1491
+ <UiListboxItem
1492
+ v-for="fruit in fruits"
1493
+ :key="fruit.value"
1494
+ :value="fruit.value"
1495
+ >
1496
+ <span>{{ fruit.label }}</span>
1497
+ <UiListboxItemIndicator />
1498
+ </UiListboxItem>
1499
+ </UiListboxContent>
1500
+ </UiListbox>
1501
+ `,
1502
+ }),
1503
+ play: async ({ canvasElement, step }) => {
1504
+ // Scenario (Listbox / Selected indicator): several fruits are selected at
1505
+ // once; adding a third keeps the first two, and clicking a selected fruit
1506
+ // removes only that one.
1507
+ const canvas = within(canvasElement);
1508
+ const list = canvas.getByRole('listbox', { name: 'Fruits' });
1509
+ const banana = canvas.getByRole('option', { name: 'Banana' });
1510
+ const cherry = canvas.getByRole('option', { name: 'Cherry' });
1511
+
1512
+ await step(
1513
+ 'interaction: the list allows more than one selection at a time',
1514
+ async () => {
1515
+ await expect(list).toHaveAttribute('aria-multiselectable', 'true');
1516
+ await expect(
1517
+ canvas
1518
+ .getAllByRole('option', { selected: true })
1519
+ .map((o) => o.textContent?.trim()),
1520
+ ).toEqual(['Apple', 'Cherry']);
1521
+ },
1522
+ );
1523
+
1524
+ await step(
1525
+ 'interaction: selecting another option adds it to the selection',
1526
+ async () => {
1527
+ await userEvent.click(banana);
1528
+ await waitFor(async () => {
1529
+ await expect(banana).toHaveAttribute('aria-selected', 'true');
1530
+ });
1531
+ await expect(
1532
+ canvas.getAllByRole('option', { selected: true }),
1533
+ ).toHaveLength(3);
1534
+ await expect(
1535
+ banana.querySelector('[data-slot="listbox-item-indicator"]'),
1536
+ ).toBeVisible();
1537
+ },
1538
+ );
1539
+
1540
+ await step(
1541
+ 'interaction: clicking a selected option removes only that option',
1542
+ async () => {
1543
+ await userEvent.click(cherry);
1544
+ await waitFor(async () => {
1545
+ await expect(cherry).toHaveAttribute('aria-selected', 'false');
1546
+ });
1547
+ await expect(
1548
+ canvas
1549
+ .getAllByRole('option', { selected: true })
1550
+ .map((o) => o.textContent?.trim()),
1551
+ ).toEqual(['Apple', 'Banana']);
1552
+ },
1553
+ );
1554
+ },
1555
+ };
1556
+
1557
+ /**
1558
+ * Filtering: typing narrows the list, an empty result set is announced, and
1559
+ * clearing the filter brings every option back. The filter is fully operable
1560
+ * from the keyboard.
1561
+ */
1562
+ export const Filtering: Story = {
1563
+ name: 'test - Filtering',
1564
+ tags: ['!dev', '!autodocs'],
1565
+ parameters: {
1566
+ // The play types into the filter and moves focus.
1567
+ chromatic: { disableSnapshot: true },
1568
+ docs: {
1569
+ description: {
1570
+ story:
1571
+ 'Type to narrow the list, reach the no-results state, and clear the filter again.',
1572
+ },
1573
+ },
1574
+ },
1575
+ render: renderFilterListbox,
1576
+ play: async ({ canvasElement, step }) => {
1577
+ // Scenario (Filter / Option): a user tabs to the filter, narrows the list
1578
+ // by typing, hits a no-results state, clears it, and confirms the
1579
+ // highlighted option with the keyboard.
1580
+ const canvas = within(canvasElement);
1581
+ const filter = canvas.getByRole('textbox', { name: 'Search food' });
1582
+
1583
+ await step(
1584
+ 'keyboard: the filter is reachable via Tab (WCAG 2.1.1 Keyboard)',
1585
+ async () => {
1586
+ await userEvent.tab();
1587
+ await expect(filter).toHaveFocus();
1588
+ },
1589
+ );
1590
+
1591
+ await step('interaction: typing narrows the list to matches', async () => {
1592
+ await userEvent.type(filter, 'an');
1593
+ await waitFor(async () => {
1594
+ await expect(
1595
+ canvas.getAllByRole('option').map((o) => o.textContent?.trim()),
1596
+ ).toEqual(['Mango (sold out)', 'Banana']);
1597
+ });
1598
+ });
1599
+
1600
+ await step(
1601
+ 'interaction: a search without matches announces the no-results state',
1602
+ async () => {
1603
+ await userEvent.clear(filter);
1604
+ await userEvent.type(filter, 'zzz');
1605
+ await waitFor(async () => {
1606
+ await expect(canvas.queryAllByRole('option')).toHaveLength(0);
1607
+ });
1608
+ await expect(canvas.getByRole('status')).toHaveTextContent(
1609
+ 'No food matches "zzz"',
1610
+ );
1611
+ },
1612
+ );
1613
+
1614
+ await step(
1615
+ 'screen-reader: an empty result set leaves no dangling active-descendant reference (WCAG 4.1.2)',
1616
+ async () => {
1617
+ // The highlighted option was filtered away, so the filter must stop
1618
+ // pointing at it rather than naming an option that no longer exists.
1619
+ await expect(filter).not.toHaveAttribute('aria-activedescendant');
1620
+ },
1621
+ );
1622
+
1623
+ await step(
1624
+ 'interaction: clearing the filter restores every option',
1625
+ async () => {
1626
+ await userEvent.clear(filter);
1627
+ await waitFor(async () => {
1628
+ await expect(canvas.getAllByRole('option')).toHaveLength(4);
1629
+ });
1630
+ await expect(canvas.queryByRole('status')).not.toBeInTheDocument();
1631
+ },
1632
+ );
1633
+
1634
+ await step(
1635
+ 'keyboard: the arrow keys move the highlight while focus stays in the filter',
1636
+ async () => {
1637
+ await userEvent.keyboard('{ArrowDown}');
1638
+ await waitFor(async () => {
1639
+ await expect(filter).toHaveAttribute(
1640
+ 'aria-activedescendant',
1641
+ canvas.getByRole('option', { name: 'Banana' }).id,
1642
+ );
1643
+ });
1644
+ await expect(filter).toHaveFocus();
1645
+ },
1646
+ );
1647
+
1648
+ await step(
1649
+ 'keyboard: Enter selects the highlighted option from the filter',
1650
+ async () => {
1651
+ await userEvent.keyboard('{Enter}');
1652
+ await waitFor(async () => {
1653
+ await expect(
1654
+ canvas.getByRole('option', { name: 'Banana' }),
1655
+ ).toHaveAttribute('aria-selected', 'true');
1656
+ });
1657
+ },
1658
+ );
1659
+
1660
+ await step(
1661
+ 'interaction: hovering an option moves the highlight to it',
1662
+ async () => {
1663
+ const carrot = canvas.getByRole('option', { name: 'Carrot' });
1664
+ await userEvent.hover(carrot);
1665
+ await waitFor(async () => {
1666
+ await expect(carrot).toHaveAttribute('data-highlighted');
1667
+ });
1668
+ },
1669
+ );
1670
+ },
1671
+ };
1672
+
1673
+ /**
1674
+ * `UiListbox` is fully keyboard operable: `Tab` reaches the list, the arrow
1675
+ * keys move through the enabled options, `Enter` and `Space` confirm the
1676
+ * selection, and `Home`/`End` jump to the ends.
1677
+ */
1678
+ export const KeyboardNavigation: Story = {
1679
+ name: 'test - Keyboard Navigation',
1680
+ tags: ['!dev', '!autodocs'],
1681
+ parameters: {
1682
+ // Focus moves during the play function; skip the visual snapshot.
1683
+ chromatic: { disableSnapshot: true },
1684
+ docs: {
1685
+ description: {
1686
+ story:
1687
+ 'Press `Tab` to reach the list, the arrow keys to move, and `Enter` or `Space` to select.',
1688
+ },
1689
+ },
1690
+ },
1691
+ render: renderKeyboardListbox,
1692
+ play: async ({ canvasElement, step }) => {
1693
+ // Scenario (Listbox / Option): a keyboard user tabs into the list, arrows
1694
+ // past the sold-out option, selects with Enter and Space, and jumps to the
1695
+ // ends of the list with Home and End.
1696
+ const canvas = within(canvasElement);
1697
+ const anchor = canvas.getByRole('button', { name: 'Before the list' });
1698
+ const apple = canvas.getByRole('option', { name: 'Apple' });
1699
+ const banana = canvas.getByRole('option', { name: 'Banana' });
1700
+ const carrot = canvas.getByRole('option', { name: 'Carrot' });
1701
+
1702
+ await step(
1703
+ 'keyboard: Tab reaches the list at its active option (WCAG 2.1.1 Keyboard)',
1704
+ async () => {
1705
+ anchor.focus();
1706
+ await userEvent.tab();
1707
+ await expect(apple).toHaveFocus();
1708
+ // The list is a single tab stop: only the active option is tabbable.
1709
+ await expect(apple).toHaveAttribute('tabindex', '0');
1710
+ await expect(banana).toHaveAttribute('tabindex', '-1');
1711
+ },
1712
+ );
1713
+
1714
+ await step(
1715
+ 'keyboard: the arrow keys move through the options and skip disabled ones',
1716
+ async () => {
1717
+ await userEvent.keyboard('{ArrowDown}');
1718
+ await expect(banana).toHaveFocus();
1719
+ await expect(
1720
+ canvas.getByRole('option', { name: 'Mango (sold out)' }),
1721
+ ).not.toHaveFocus();
1722
+ await userEvent.keyboard('{ArrowUp}');
1723
+ await expect(apple).toHaveFocus();
1724
+ },
1725
+ );
1726
+
1727
+ await step('keyboard: Enter selects the active option', async () => {
1728
+ await userEvent.keyboard('{Enter}');
1729
+ await waitFor(async () => {
1730
+ await expect(apple).toHaveAttribute('aria-selected', 'true');
1731
+ });
1732
+ });
1733
+
1734
+ await step('keyboard: Space toggles the active option', async () => {
1735
+ await userEvent.keyboard(' ');
1736
+ await waitFor(async () => {
1737
+ await expect(apple).toHaveAttribute('aria-selected', 'false');
1738
+ });
1739
+ });
1740
+
1741
+ await step(
1742
+ 'keyboard: End and Home jump to the last and first option (WCAG 2.4.3)',
1743
+ async () => {
1744
+ await userEvent.keyboard('{End}');
1745
+ await expect(carrot).toHaveFocus();
1746
+ await userEvent.keyboard('{Home}');
1747
+ await expect(apple).toHaveFocus();
1748
+ },
1749
+ );
1750
+ },
1751
+ };
1752
+
1753
+ /**
1754
+ * Screen-reader semantics: the list exposes a named `listbox`, the options
1755
+ * sit in labelled groups, and each option announces its selected and disabled
1756
+ * state.
1757
+ */
1758
+ export const ScreenReader: Story = {
1759
+ name: 'test - Screen Reader',
1760
+ tags: ['!dev', '!autodocs'],
1761
+ parameters: {
1762
+ // The play changes the selection.
1763
+ chromatic: { disableSnapshot: true },
1764
+ docs: {
1765
+ description: {
1766
+ story:
1767
+ 'Verifies the roles, names, grouping, and states that assistive technology announces.',
1768
+ },
1769
+ },
1770
+ },
1771
+ render: renderFilterListbox,
1772
+ play: async ({ canvasElement, step }) => {
1773
+ // Scenario (Listbox / Group / Option / Filter): assistive tech reads a
1774
+ // named list, finds the options under labelled groups, and hears the
1775
+ // selected and disabled states of individual options.
1776
+ const canvas = within(canvasElement);
1777
+ const list = canvas.getByRole('listbox', { name: 'Food' });
1778
+
1779
+ await step(
1780
+ 'screen-reader: the list exposes a listbox role with a meaningful name (WCAG 4.1.2)',
1781
+ async () => {
1782
+ await expect(list).toHaveAccessibleName('Food');
1783
+ await expect(list).toHaveAttribute('aria-orientation', 'vertical');
1784
+ },
1785
+ );
1786
+
1787
+ await step(
1788
+ 'screen-reader: the filter exposes a named text input (WCAG 3.3.2)',
1789
+ async () => {
1790
+ await expect(
1791
+ canvas.getByRole('textbox', { name: 'Search food' }),
1792
+ ).toHaveAccessibleName('Search food');
1793
+ },
1794
+ );
1795
+
1796
+ await step(
1797
+ 'screen-reader: options are organised under labelled groups (WCAG 1.3.1)',
1798
+ async () => {
1799
+ const fruitsGroup = canvas.getByRole('group', { name: 'Fruits' });
1800
+ await expect(
1801
+ within(fruitsGroup).getByRole('option', { name: 'Apple' }),
1802
+ ).toBeVisible();
1803
+ const vegetablesGroup = canvas.getByRole('group', {
1804
+ name: 'Vegetables',
1805
+ });
1806
+ await expect(
1807
+ within(vegetablesGroup).getByRole('option', { name: 'Carrot' }),
1808
+ ).toBeVisible();
1809
+ },
1810
+ );
1811
+
1812
+ await step(
1813
+ 'screen-reader: every option exposes an option role and its own name',
1814
+ async () => {
1815
+ await expect(
1816
+ canvas.getAllByRole('option').map((o) => o.textContent?.trim()),
1817
+ ).toEqual(['Apple', 'Mango (sold out)', 'Banana', 'Carrot']);
1818
+ },
1819
+ );
1820
+
1821
+ await step(
1822
+ 'screen-reader: an unavailable option announces its disabled state (WCAG 4.1.2)',
1823
+ async () => {
1824
+ await expect(
1825
+ canvas.getByRole('option', { name: 'Mango (sold out)' }),
1826
+ ).toHaveAttribute('aria-disabled', 'true');
1827
+ },
1828
+ );
1829
+
1830
+ await step(
1831
+ 'screen-reader: the chosen option announces its selected state (WCAG 4.1.2)',
1832
+ async () => {
1833
+ const apple = canvas.getByRole('option', { name: 'Apple' });
1834
+ await expect(apple).toHaveAttribute('aria-selected', 'false');
1835
+ await userEvent.click(apple);
1836
+ await waitFor(async () => {
1837
+ await expect(apple).toHaveAttribute('aria-selected', 'true');
1838
+ });
1839
+ await expect(
1840
+ canvas.getByRole('option', { name: 'Carrot' }),
1841
+ ).toHaveAttribute('aria-selected', 'false');
1842
+ },
1843
+ );
1844
+
1845
+ await step(
1846
+ 'screen-reader: the selected indicator is decorative and not announced twice',
1847
+ async () => {
1848
+ const indicator = canvas
1849
+ .getByRole('option', { name: 'Apple' })
1850
+ .querySelector('[data-slot="listbox-item-indicator"]');
1851
+ await expect(indicator).toHaveAttribute('aria-hidden', 'true');
1852
+ },
1853
+ );
1854
+ },
1855
+ };
1856
+
1857
+ /**
1858
+ * Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
1859
+ * try 400% reflow (WCAG 1.4.10); the filter and the list must stay visible and
1860
+ * operable.
1861
+ */
1862
+ export const ZoomMagnification: Story = {
1863
+ name: 'test - Zoom Magnification',
1864
+ tags: ['!dev', '!autodocs'],
1865
+ globals: { zoom: '200' },
1866
+ parameters: {
1867
+ // The accessible-reflow Chromatic mode already covers magnified snapshots.
1868
+ chromatic: { disableSnapshot: true },
1869
+ docs: {
1870
+ description: {
1871
+ story:
1872
+ 'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
1873
+ },
1874
+ },
1875
+ },
1876
+ render: renderFilterListbox,
1877
+ play: async ({ canvasElement, step }) => {
1878
+ // Scenario (Listbox / Filter): at 200% page zoom the filter and the list
1879
+ // stay on screen, the options are still readable, and both filtering and
1880
+ // selecting keep working.
1881
+ const canvas = within(canvasElement);
1882
+ const filter = canvas.getByRole('textbox', { name: 'Search food' });
1883
+ const list = canvas.getByRole('listbox', { name: 'Food' });
1884
+
1885
+ await step(
1886
+ 'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
1887
+ async () => {
1888
+ await expect(document.documentElement.style.zoom).toBe('200%');
1889
+ },
1890
+ );
1891
+
1892
+ await step(
1893
+ 'zoom: the filter and the list stay visible when magnified',
1894
+ async () => {
1895
+ await expect(filter).toBeVisible();
1896
+ await expect(list).toBeVisible();
1897
+ await expect(
1898
+ canvas.getByRole('option', { name: 'Apple' }),
1899
+ ).toBeVisible();
1900
+ },
1901
+ );
1902
+
1903
+ await step('zoom: the list stays operable when magnified', async () => {
1904
+ await userEvent.type(filter, 'car');
1905
+ await waitFor(async () => {
1906
+ await expect(canvas.getAllByRole('option')).toHaveLength(1);
1907
+ });
1908
+ const carrot = canvas.getByRole('option', { name: 'Carrot' });
1909
+ await userEvent.click(carrot);
1910
+ await waitFor(async () => {
1911
+ await expect(carrot).toHaveAttribute('aria-selected', 'true');
1912
+ });
1913
+ });
1914
+ },
1915
+ };
1916
+
1917
+ /**
1918
+ * Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
1919
+ * toolbar. The list and its options stay operable and meet the minimum
1920
+ * touch-target size (WCAG 2.5.8).
1921
+ */
1922
+ export const MobileBreakpoint: Story = {
1923
+ name: 'test - Mobile Breakpoint',
1924
+ tags: ['!dev', '!autodocs'],
1925
+ globals: { mediaBreakpoint: 'reflow' },
1926
+ parameters: {
1927
+ // Reflow snapshots are already covered by the accessible-reflow mode.
1928
+ chromatic: { disableSnapshot: true },
1929
+ docs: {
1930
+ description: {
1931
+ story:
1932
+ 'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
1933
+ },
1934
+ },
1935
+ },
1936
+ render: renderFilterListbox,
1937
+ play: async ({ canvasElement, step }) => {
1938
+ // Scenario (Listbox / Filter / Option): at the 320px mobile breakpoint the
1939
+ // list fits the viewport, the filter and options meet the minimum
1940
+ // touch-target size, and tapping an option still selects it.
1941
+ const canvas = within(canvasElement);
1942
+ const filter = canvas.getByRole('textbox', { name: 'Search food' });
1943
+ const list = canvas.getByRole('listbox', { name: 'Food' });
1944
+
1945
+ await step(
1946
+ 'mobile: the list fits the 320px viewport without clipping (WCAG 1.4.10 Reflow)',
1947
+ async () => {
1948
+ await expect(list).toBeVisible();
1949
+ await expect(list.getBoundingClientRect().width).toBeLessThanOrEqual(
1950
+ 320,
1951
+ );
1952
+ },
1953
+ );
1954
+
1955
+ await step(
1956
+ 'mobile: the filter meets the minimum touch-target size (WCAG 2.5.8)',
1957
+ async () => {
1958
+ const { width, height } = filter.getBoundingClientRect();
1959
+ await expect(width).toBeGreaterThanOrEqual(24);
1960
+ await expect(height).toBeGreaterThanOrEqual(24);
1961
+ },
1962
+ );
1963
+
1964
+ await step(
1965
+ 'mobile: options meet the minimum touch-target size (WCAG 2.5.8)',
1966
+ async () => {
1967
+ for (const option of canvas.getAllByRole('option')) {
1968
+ const { width, height } = option.getBoundingClientRect();
1969
+ await expect(width).toBeGreaterThanOrEqual(24);
1970
+ await expect(height).toBeGreaterThanOrEqual(24);
1971
+ }
1972
+ },
1973
+ );
1974
+
1975
+ await step(
1976
+ 'mobile: tapping an option still selects it at the 320px breakpoint',
1977
+ async () => {
1978
+ const carrot = canvas.getByRole('option', { name: 'Carrot' });
1979
+ await userEvent.click(carrot);
1980
+ await waitFor(async () => {
1981
+ await expect(carrot).toHaveAttribute('aria-selected', 'true');
1982
+ });
1983
+ },
1984
+ );
1985
+ },
612
1986
  };