@aleph-alpha/ui-library 5.7.0 → 5.8.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 (67) hide show
  1. package/README.md +4 -0
  2. package/config.d.ts +5 -1
  3. package/config.js +18 -1
  4. package/dist/system/components/UiBreadcrumb/UiBreadcrumb.vue.d.ts +17 -0
  5. package/dist/system/components/UiBreadcrumb/UiBreadcrumbEllipsis.vue.d.ts +17 -0
  6. package/dist/system/components/UiBreadcrumb/UiBreadcrumbItem.vue.d.ts +17 -0
  7. package/dist/system/components/UiBreadcrumb/UiBreadcrumbLink.vue.d.ts +18 -0
  8. package/dist/system/components/UiBreadcrumb/UiBreadcrumbList.vue.d.ts +17 -0
  9. package/dist/system/components/UiBreadcrumb/UiBreadcrumbPage.vue.d.ts +17 -0
  10. package/dist/system/components/UiBreadcrumb/UiBreadcrumbSeparator.vue.d.ts +17 -0
  11. package/dist/system/components/UiBreadcrumb/index.d.ts +8 -0
  12. package/dist/system/components/UiBreadcrumb/types.d.ts +22 -0
  13. package/dist/system/components/UiToggleGroup/types.d.ts +0 -5
  14. package/dist/system/components/core/breadcrumb/Breadcrumb.vue.d.ts +21 -0
  15. package/dist/system/components/core/breadcrumb/BreadcrumbEllipsis.vue.d.ts +21 -0
  16. package/dist/system/components/core/breadcrumb/BreadcrumbItem.vue.d.ts +21 -0
  17. package/dist/system/components/core/breadcrumb/BreadcrumbLink.vue.d.ts +24 -0
  18. package/dist/system/components/core/breadcrumb/BreadcrumbList.vue.d.ts +21 -0
  19. package/dist/system/components/core/breadcrumb/BreadcrumbPage.vue.d.ts +21 -0
  20. package/dist/system/components/core/breadcrumb/BreadcrumbSeparator.vue.d.ts +21 -0
  21. package/dist/system/components/core/breadcrumb/index.d.ts +7 -0
  22. package/dist/system/components/core/listbox/Listbox.vue.d.ts +28 -2
  23. package/dist/system/components/core/listbox/context.d.ts +21 -0
  24. package/dist/system/components/index.d.ts +1 -0
  25. package/dist/system/lib.js +10057 -9707
  26. package/dist/system/patterns/UiDatePicker/UiDatePicker.vue.d.ts +1 -1
  27. package/dist/system/story-sidebar-icons.json +6 -0
  28. package/package.json +2 -2
  29. package/src/components/UiBreadcrumb/UiBreadcrumb.stories.ts +1419 -0
  30. package/src/components/UiBreadcrumb/UiBreadcrumb.vue +19 -0
  31. package/src/components/UiBreadcrumb/UiBreadcrumbEllipsis.vue +22 -0
  32. package/src/components/UiBreadcrumb/UiBreadcrumbItem.vue +19 -0
  33. package/src/components/UiBreadcrumb/UiBreadcrumbLink.vue +26 -0
  34. package/src/components/UiBreadcrumb/UiBreadcrumbList.vue +19 -0
  35. package/src/components/UiBreadcrumb/UiBreadcrumbPage.vue +19 -0
  36. package/src/components/UiBreadcrumb/UiBreadcrumbSeparator.vue +22 -0
  37. package/src/components/UiBreadcrumb/index.ts +8 -0
  38. package/src/components/UiBreadcrumb/types.ts +28 -0
  39. package/src/components/UiDropdownMenu/UiDropdownMenuTrigger.vue +2 -0
  40. package/src/components/UiListbox/UiListbox.stories.ts +1283 -30
  41. package/src/components/UiListbox/__tests__/UiListbox.test.ts +70 -35
  42. package/src/components/UiSwitch/UiSwitch.stories.ts +706 -9
  43. package/src/components/UiSwitch/__tests__/UiSwitch.test.ts +2 -6
  44. package/src/components/UiToggle/UiToggle.stories.ts +961 -130
  45. package/src/components/UiToggle/UiToggle.vue +8 -1
  46. package/src/components/UiToggle/__tests__/UiToggle.test.ts +55 -65
  47. package/src/components/UiToggleGroup/UiToggleGroup.stories.ts +1060 -173
  48. package/src/components/UiToggleGroup/UiToggleGroup.vue +4 -2
  49. package/src/components/UiToggleGroup/__tests__/UiToggleGroup.test.ts +117 -325
  50. package/src/components/UiToggleGroup/types.ts +0 -5
  51. package/src/components/core/breadcrumb/Breadcrumb.vue +13 -0
  52. package/src/components/core/breadcrumb/BreadcrumbEllipsis.vue +23 -0
  53. package/src/components/core/breadcrumb/BreadcrumbItem.vue +17 -0
  54. package/src/components/core/breadcrumb/BreadcrumbLink.vue +29 -0
  55. package/src/components/core/breadcrumb/BreadcrumbList.vue +22 -0
  56. package/src/components/core/breadcrumb/BreadcrumbPage.vue +20 -0
  57. package/src/components/core/breadcrumb/BreadcrumbSeparator.vue +22 -0
  58. package/src/components/core/breadcrumb/index.ts +7 -0
  59. package/src/components/core/listbox/Listbox.vue +14 -2
  60. package/src/components/core/listbox/ListboxContent.vue +61 -3
  61. package/src/components/core/listbox/ListboxItem.vue +6 -1
  62. package/src/components/core/listbox/context.ts +34 -0
  63. package/src/components/core/toggle/Toggle.vue +15 -1
  64. package/src/components/core/toggle/index.ts +2 -2
  65. package/src/components/core/toggle-group/ToggleGroup.vue +1 -1
  66. package/src/components/core/toggle-group/index.ts +5 -2
  67. package/src/components/index.ts +1 -0
@@ -0,0 +1,1419 @@
1
+ import type { Meta, StoryObj } from '@storybook/vue3-vite';
2
+ import { expect, fn, userEvent, waitFor, within } from 'storybook/test';
3
+ import { useMediaQuery } from '@vueuse/core';
4
+ import { ref } from 'vue';
5
+ import { RouterLink } from 'vue-router';
6
+ import UiBreadcrumb from './UiBreadcrumb.vue';
7
+ import UiBreadcrumbEllipsis from './UiBreadcrumbEllipsis.vue';
8
+ import UiBreadcrumbItem from './UiBreadcrumbItem.vue';
9
+ import UiBreadcrumbLink from './UiBreadcrumbLink.vue';
10
+ import UiBreadcrumbList from './UiBreadcrumbList.vue';
11
+ import UiBreadcrumbPage from './UiBreadcrumbPage.vue';
12
+ import UiBreadcrumbSeparator from './UiBreadcrumbSeparator.vue';
13
+ import { UiButton } from '../UiButton';
14
+ import { UiIcon } from '../UiIcon';
15
+ import {
16
+ UiDropdownMenu,
17
+ UiDropdownMenuContent,
18
+ UiDropdownMenuItem,
19
+ UiDropdownMenuTrigger,
20
+ } from '../UiDropdownMenu';
21
+ import {
22
+ UiDrawer,
23
+ UiDrawerClose,
24
+ UiDrawerContent,
25
+ UiDrawerDescription,
26
+ UiDrawerFooter,
27
+ UiDrawerHeader,
28
+ UiDrawerTitle,
29
+ UiDrawerTrigger,
30
+ } from '../UiDrawer';
31
+
32
+ // Crumbs render native anchors and declare no `onClick` prop, so plays assert
33
+ // against these module-level spies bound via `@click`. Each `play` clears them
34
+ // first, so the shared spies are safe.
35
+ const onCrumbClick = fn();
36
+ const onMenuSelect = fn();
37
+
38
+ /**
39
+ * UiBreadcrumb shows the path to the current resource as a hierarchy of links.
40
+ * It renders an ordered list inside a `nav` landmark labelled "breadcrumb", so
41
+ * assistive technology can jump straight to it.
42
+ */
43
+ const meta: Meta<typeof UiBreadcrumb> = {
44
+ title: 'Components/UiBreadcrumb',
45
+ component: UiBreadcrumb,
46
+ tags: ['autodocs'],
47
+ };
48
+
49
+ export default meta;
50
+
51
+ type Story = StoryObj<typeof UiBreadcrumb>;
52
+
53
+ const components = {
54
+ UiBreadcrumb,
55
+ UiBreadcrumbEllipsis,
56
+ UiBreadcrumbItem,
57
+ UiBreadcrumbLink,
58
+ UiBreadcrumbList,
59
+ UiBreadcrumbPage,
60
+ UiBreadcrumbSeparator,
61
+ };
62
+
63
+ const dropdownComponents = {
64
+ UiDropdownMenu,
65
+ UiDropdownMenuContent,
66
+ UiDropdownMenuItem,
67
+ UiDropdownMenuTrigger,
68
+ };
69
+
70
+ const drawerComponents = {
71
+ UiDrawer,
72
+ UiDrawerClose,
73
+ UiDrawerContent,
74
+ UiDrawerDescription,
75
+ UiDrawerFooter,
76
+ UiDrawerHeader,
77
+ UiDrawerTitle,
78
+ UiDrawerTrigger,
79
+ };
80
+
81
+ const HIDDEN_CRUMBS = ['Documentation', 'Building Your Application'];
82
+
83
+ const defaultTemplateSource = `<script setup lang="ts">
84
+ import {
85
+ UiBreadcrumb,
86
+ UiBreadcrumbItem,
87
+ UiBreadcrumbLink,
88
+ UiBreadcrumbList,
89
+ UiBreadcrumbPage,
90
+ UiBreadcrumbSeparator,
91
+ } from '@aleph-alpha/ui-library'
92
+ </script>
93
+
94
+ <template>
95
+ <UiBreadcrumb>
96
+ <UiBreadcrumbList>
97
+ <UiBreadcrumbItem>
98
+ <UiBreadcrumbLink href="/">Home</UiBreadcrumbLink>
99
+ </UiBreadcrumbItem>
100
+ <UiBreadcrumbSeparator />
101
+ <UiBreadcrumbItem>
102
+ <UiBreadcrumbLink href="/components">Components</UiBreadcrumbLink>
103
+ </UiBreadcrumbItem>
104
+ <UiBreadcrumbSeparator />
105
+ <UiBreadcrumbItem>
106
+ <UiBreadcrumbPage>Breadcrumb</UiBreadcrumbPage>
107
+ </UiBreadcrumbItem>
108
+ </UiBreadcrumbList>
109
+ </UiBreadcrumb>
110
+ </template>`;
111
+
112
+ /**
113
+ * Standard breadcrumb trail. The final crumb uses `UiBreadcrumbPage` instead of a
114
+ * link, which marks it as `aria-current="page"` so screen readers announce the
115
+ * user's current location.
116
+ */
117
+ export const Default: Story = {
118
+ render: () => ({
119
+ components,
120
+ template: `
121
+ <UiBreadcrumb>
122
+ <UiBreadcrumbList>
123
+ <UiBreadcrumbItem>
124
+ <UiBreadcrumbLink href="/">Home</UiBreadcrumbLink>
125
+ </UiBreadcrumbItem>
126
+ <UiBreadcrumbSeparator />
127
+ <UiBreadcrumbItem>
128
+ <UiBreadcrumbLink href="/components">Components</UiBreadcrumbLink>
129
+ </UiBreadcrumbItem>
130
+ <UiBreadcrumbSeparator />
131
+ <UiBreadcrumbItem>
132
+ <UiBreadcrumbPage>Breadcrumb</UiBreadcrumbPage>
133
+ </UiBreadcrumbItem>
134
+ </UiBreadcrumbList>
135
+ </UiBreadcrumb>
136
+ `,
137
+ }),
138
+ parameters: {
139
+ docs: {
140
+ source: {
141
+ code: defaultTemplateSource,
142
+ },
143
+ },
144
+ },
145
+ play: async ({ canvasElement, step }) => {
146
+ // Scenario (UiBreadcrumb): assistive tech finds the trail via its nav landmark,
147
+ // reads three crumbs (decorative separators excluded), and hears which one is
148
+ // the current page.
149
+ const canvas = within(canvasElement);
150
+
151
+ await step(
152
+ 'interaction: exposes a nav landmark named "breadcrumb" (WCAG 1.3.1)',
153
+ async () => {
154
+ await expect(
155
+ canvas.getByRole('navigation', { name: 'breadcrumb' }),
156
+ ).toBeVisible();
157
+ },
158
+ );
159
+
160
+ await step(
161
+ 'interaction: decorative separators are excluded from the list',
162
+ async () => {
163
+ // Five <li> elements render, but the two separators are role="presentation".
164
+ await expect(canvas.getAllByRole('listitem')).toHaveLength(3);
165
+ },
166
+ );
167
+
168
+ await step('interaction: crumbs keep their link destinations', async () => {
169
+ await expect(canvas.getByRole('link', { name: 'Home' })).toHaveAttribute(
170
+ 'href',
171
+ '/',
172
+ );
173
+ await expect(
174
+ canvas.getByRole('link', { name: 'Components' }),
175
+ ).toHaveAttribute('href', '/components');
176
+ });
177
+
178
+ await step(
179
+ 'interaction: the last crumb is marked as the current page and is not navigable (WCAG 4.1.2)',
180
+ async () => {
181
+ const current = canvas.getByRole('link', { name: 'Breadcrumb' });
182
+ await expect(current).toHaveAttribute('aria-current', 'page');
183
+ await expect(current).toHaveAttribute('aria-disabled', 'true');
184
+ await expect(current).not.toHaveAttribute('href');
185
+ },
186
+ );
187
+ },
188
+ };
189
+
190
+ const customSeparatorTemplateSource = `<script setup lang="ts">
191
+ import {
192
+ UiBreadcrumb,
193
+ UiBreadcrumbItem,
194
+ UiBreadcrumbLink,
195
+ UiBreadcrumbList,
196
+ UiBreadcrumbPage,
197
+ UiBreadcrumbSeparator,
198
+ UiIcon,
199
+ } from '@aleph-alpha/ui-library'
200
+ </script>
201
+
202
+ <template>
203
+ <UiBreadcrumb>
204
+ <UiBreadcrumbList>
205
+ <UiBreadcrumbItem>
206
+ <UiBreadcrumbLink href="/">Home</UiBreadcrumbLink>
207
+ </UiBreadcrumbItem>
208
+ <UiBreadcrumbSeparator>
209
+ <UiIcon name="slash" size="xs" />
210
+ </UiBreadcrumbSeparator>
211
+ <UiBreadcrumbItem>
212
+ <UiBreadcrumbLink href="/components">Components</UiBreadcrumbLink>
213
+ </UiBreadcrumbItem>
214
+ <UiBreadcrumbSeparator>
215
+ <UiIcon name="slash" size="xs" />
216
+ </UiBreadcrumbSeparator>
217
+ <UiBreadcrumbItem>
218
+ <UiBreadcrumbPage>Breadcrumb</UiBreadcrumbPage>
219
+ </UiBreadcrumbItem>
220
+ </UiBreadcrumbList>
221
+ </UiBreadcrumb>
222
+ </template>`;
223
+
224
+ /**
225
+ * Pass any content into the `UiBreadcrumbSeparator` slot to replace the default
226
+ * chevron. The separator stays `aria-hidden`, so a decorative glyph never reaches
227
+ * the accessibility tree.
228
+ */
229
+ export const CustomSeparator: Story = {
230
+ render: () => ({
231
+ components: { ...components, UiIcon },
232
+ template: `
233
+ <UiBreadcrumb>
234
+ <UiBreadcrumbList>
235
+ <UiBreadcrumbItem>
236
+ <UiBreadcrumbLink href="/">Home</UiBreadcrumbLink>
237
+ </UiBreadcrumbItem>
238
+ <UiBreadcrumbSeparator>
239
+ <UiIcon name="slash" size="xs" />
240
+ </UiBreadcrumbSeparator>
241
+ <UiBreadcrumbItem>
242
+ <UiBreadcrumbLink href="/components">Components</UiBreadcrumbLink>
243
+ </UiBreadcrumbItem>
244
+ <UiBreadcrumbSeparator>
245
+ <UiIcon name="slash" size="xs" />
246
+ </UiBreadcrumbSeparator>
247
+ <UiBreadcrumbItem>
248
+ <UiBreadcrumbPage>Breadcrumb</UiBreadcrumbPage>
249
+ </UiBreadcrumbItem>
250
+ </UiBreadcrumbList>
251
+ </UiBreadcrumb>
252
+ `,
253
+ }),
254
+ parameters: {
255
+ docs: {
256
+ source: {
257
+ code: customSeparatorTemplateSource,
258
+ },
259
+ },
260
+ },
261
+ play: async ({ canvasElement, step }) => {
262
+ // Scenario (UiBreadcrumb): swapping the separator glyph must not add anything to
263
+ // the accessibility tree — the trail still reads as exactly three crumbs.
264
+ const canvas = within(canvasElement);
265
+
266
+ await step(
267
+ 'interaction: a custom separator glyph stays out of the accessibility tree',
268
+ async () => {
269
+ await expect(canvas.getAllByRole('listitem')).toHaveLength(3);
270
+ await expect(canvas.queryByRole('img')).not.toBeInTheDocument();
271
+ },
272
+ );
273
+ },
274
+ };
275
+
276
+ const collapsedTemplateSource = `<script setup lang="ts">
277
+ import {
278
+ UiBreadcrumb,
279
+ UiBreadcrumbEllipsis,
280
+ UiBreadcrumbItem,
281
+ UiBreadcrumbLink,
282
+ UiBreadcrumbList,
283
+ UiBreadcrumbPage,
284
+ UiBreadcrumbSeparator,
285
+ } from '@aleph-alpha/ui-library'
286
+ </script>
287
+
288
+ <template>
289
+ <UiBreadcrumb>
290
+ <UiBreadcrumbList>
291
+ <UiBreadcrumbItem>
292
+ <UiBreadcrumbLink href="/">Home</UiBreadcrumbLink>
293
+ </UiBreadcrumbItem>
294
+ <UiBreadcrumbSeparator />
295
+ <UiBreadcrumbItem>
296
+ <UiBreadcrumbEllipsis />
297
+ </UiBreadcrumbItem>
298
+ <UiBreadcrumbSeparator />
299
+ <UiBreadcrumbItem>
300
+ <UiBreadcrumbLink href="/components">Components</UiBreadcrumbLink>
301
+ </UiBreadcrumbItem>
302
+ <UiBreadcrumbSeparator />
303
+ <UiBreadcrumbItem>
304
+ <UiBreadcrumbPage>Breadcrumb</UiBreadcrumbPage>
305
+ </UiBreadcrumbItem>
306
+ </UiBreadcrumbList>
307
+ </UiBreadcrumb>
308
+ </template>`;
309
+
310
+ /**
311
+ * Use `UiBreadcrumbEllipsis` to stand in for hidden middle crumbs when the trail
312
+ * is too long for its container. The placeholder is purely decorative — it is
313
+ * `aria-hidden`, so prefer the Dropdown story when the hidden crumbs still need
314
+ * to be reachable.
315
+ */
316
+ export const Collapsed: Story = {
317
+ render: () => ({
318
+ components,
319
+ template: `
320
+ <UiBreadcrumb>
321
+ <UiBreadcrumbList>
322
+ <UiBreadcrumbItem>
323
+ <UiBreadcrumbLink href="/">Home</UiBreadcrumbLink>
324
+ </UiBreadcrumbItem>
325
+ <UiBreadcrumbSeparator />
326
+ <UiBreadcrumbItem>
327
+ <UiBreadcrumbEllipsis />
328
+ </UiBreadcrumbItem>
329
+ <UiBreadcrumbSeparator />
330
+ <UiBreadcrumbItem>
331
+ <UiBreadcrumbLink href="/components">Components</UiBreadcrumbLink>
332
+ </UiBreadcrumbItem>
333
+ <UiBreadcrumbSeparator />
334
+ <UiBreadcrumbItem>
335
+ <UiBreadcrumbPage>Breadcrumb</UiBreadcrumbPage>
336
+ </UiBreadcrumbItem>
337
+ </UiBreadcrumbList>
338
+ </UiBreadcrumb>
339
+ `,
340
+ }),
341
+ parameters: {
342
+ docs: {
343
+ source: {
344
+ code: collapsedTemplateSource,
345
+ },
346
+ },
347
+ },
348
+ play: async ({ canvasElement, step }) => {
349
+ // Scenario (UiBreadcrumb): the collapsed placeholder is decorative. Its
350
+ // visually-hidden "More" text sits inside an aria-hidden container, so it is
351
+ // never announced and cannot be reached by keyboard.
352
+ const canvas = within(canvasElement);
353
+
354
+ await step(
355
+ 'interaction: the collapsed placeholder is hidden from assistive technology',
356
+ async () => {
357
+ const label = canvas.getByText('More');
358
+ await expect(label.closest('[aria-hidden="true"]')).not.toBeNull();
359
+ },
360
+ );
361
+
362
+ await step(
363
+ 'interaction: the placeholder is not interactive on its own',
364
+ async () => {
365
+ await expect(canvas.queryByRole('button')).not.toBeInTheDocument();
366
+ },
367
+ );
368
+ },
369
+ };
370
+
371
+ const dropdownTemplateSource = `<script setup lang="ts">
372
+ import {
373
+ UiBreadcrumb,
374
+ UiBreadcrumbEllipsis,
375
+ UiBreadcrumbItem,
376
+ UiBreadcrumbLink,
377
+ UiBreadcrumbList,
378
+ UiBreadcrumbPage,
379
+ UiBreadcrumbSeparator,
380
+ UiDropdownMenu,
381
+ UiDropdownMenuContent,
382
+ UiDropdownMenuItem,
383
+ UiDropdownMenuTrigger,
384
+ } from '@aleph-alpha/ui-library'
385
+ </script>
386
+
387
+ <template>
388
+ <UiBreadcrumb>
389
+ <UiBreadcrumbList>
390
+ <UiBreadcrumbItem>
391
+ <UiBreadcrumbLink href="/">Home</UiBreadcrumbLink>
392
+ </UiBreadcrumbItem>
393
+ <UiBreadcrumbSeparator />
394
+ <UiBreadcrumbItem>
395
+ <UiDropdownMenu>
396
+ <UiDropdownMenuTrigger class="flex items-center gap-1" aria-label="Show hidden pages">
397
+ <UiBreadcrumbEllipsis />
398
+ </UiDropdownMenuTrigger>
399
+ <UiDropdownMenuContent align="start">
400
+ <UiDropdownMenuItem>Documentation</UiDropdownMenuItem>
401
+ <UiDropdownMenuItem>Building Your Application</UiDropdownMenuItem>
402
+ <UiDropdownMenuItem>Data Fetching</UiDropdownMenuItem>
403
+ </UiDropdownMenuContent>
404
+ </UiDropdownMenu>
405
+ </UiBreadcrumbItem>
406
+ <UiBreadcrumbSeparator />
407
+ <UiBreadcrumbItem>
408
+ <UiBreadcrumbLink href="/components">Components</UiBreadcrumbLink>
409
+ </UiBreadcrumbItem>
410
+ <UiBreadcrumbSeparator />
411
+ <UiBreadcrumbItem>
412
+ <UiBreadcrumbPage>Breadcrumb</UiBreadcrumbPage>
413
+ </UiBreadcrumbItem>
414
+ </UiBreadcrumbList>
415
+ </UiBreadcrumb>
416
+ </template>`;
417
+
418
+ /**
419
+ * Make collapsed crumbs reachable by wrapping the ellipsis in a dropdown menu.
420
+ * The trigger needs its own `aria-label` because the ellipsis glyph itself is
421
+ * hidden from assistive technology.
422
+ */
423
+ export const WithDropdown: Story = {
424
+ parameters: {
425
+ // The play opens the menu and moves focus; skip the visual snapshot.
426
+ chromatic: { disableSnapshot: true },
427
+ docs: {
428
+ source: {
429
+ code: dropdownTemplateSource,
430
+ },
431
+ },
432
+ },
433
+ render: () => ({
434
+ components: { ...components, ...dropdownComponents },
435
+ setup() {
436
+ return { onMenuSelect };
437
+ },
438
+ template: `
439
+ <UiBreadcrumb>
440
+ <UiBreadcrumbList>
441
+ <UiBreadcrumbItem>
442
+ <UiBreadcrumbLink href="/">Home</UiBreadcrumbLink>
443
+ </UiBreadcrumbItem>
444
+ <UiBreadcrumbSeparator />
445
+ <UiBreadcrumbItem>
446
+ <UiDropdownMenu>
447
+ <UiDropdownMenuTrigger class="flex items-center gap-1" aria-label="Show hidden pages">
448
+ <UiBreadcrumbEllipsis />
449
+ </UiDropdownMenuTrigger>
450
+ <UiDropdownMenuContent align="start">
451
+ <UiDropdownMenuItem @click="onMenuSelect">Documentation</UiDropdownMenuItem>
452
+ <UiDropdownMenuItem @click="onMenuSelect">Building Your Application</UiDropdownMenuItem>
453
+ <UiDropdownMenuItem @click="onMenuSelect">Data Fetching</UiDropdownMenuItem>
454
+ </UiDropdownMenuContent>
455
+ </UiDropdownMenu>
456
+ </UiBreadcrumbItem>
457
+ <UiBreadcrumbSeparator />
458
+ <UiBreadcrumbItem>
459
+ <UiBreadcrumbLink href="/components">Components</UiBreadcrumbLink>
460
+ </UiBreadcrumbItem>
461
+ <UiBreadcrumbSeparator />
462
+ <UiBreadcrumbItem>
463
+ <UiBreadcrumbPage>Breadcrumb</UiBreadcrumbPage>
464
+ </UiBreadcrumbItem>
465
+ </UiBreadcrumbList>
466
+ </UiBreadcrumb>
467
+ `,
468
+ }),
469
+ play: async ({ canvasElement, step }) => {
470
+ // Scenario (UiBreadcrumb): a user reveals the collapsed crumbs from the ellipsis
471
+ // menu, picks one, and can also drive the whole flow from the keyboard. The menu
472
+ // is portalled to the body, so it is queried outside the story canvas.
473
+ onMenuSelect.mockClear();
474
+ const canvas = within(canvasElement);
475
+ const body = within(document.body);
476
+ const trigger = canvas.getByRole('button', { name: 'Show hidden pages' });
477
+
478
+ await step(
479
+ 'interaction: the collapsed crumbs get an accessible name from the trigger (WCAG 4.1.2)',
480
+ async () => {
481
+ await expect(trigger).toHaveAccessibleName('Show hidden pages');
482
+ await expect(trigger).toHaveAttribute('aria-expanded', 'false');
483
+ },
484
+ );
485
+
486
+ await step('interaction: opens the menu of hidden crumbs', async () => {
487
+ await userEvent.click(trigger);
488
+ await waitFor(async () => {
489
+ await expect(body.getByRole('menu')).toBeVisible();
490
+ });
491
+ await expect(trigger).toHaveAttribute('aria-expanded', 'true');
492
+ await expect(body.getAllByRole('menuitem')).toHaveLength(3);
493
+ });
494
+
495
+ await step(
496
+ 'interaction: choosing a hidden crumb closes the menu',
497
+ async () => {
498
+ await userEvent.click(
499
+ body.getByRole('menuitem', { name: 'Documentation' }),
500
+ );
501
+ await expect(onMenuSelect).toHaveBeenCalledTimes(1);
502
+ await waitFor(async () => {
503
+ await expect(body.queryByRole('menu')).not.toBeInTheDocument();
504
+ });
505
+ },
506
+ );
507
+
508
+ await step(
509
+ 'keyboard: Enter on the trigger opens the menu (WCAG 2.1.1)',
510
+ async () => {
511
+ trigger.focus();
512
+ await expect(trigger).toHaveFocus();
513
+ await userEvent.keyboard('{Enter}');
514
+ await waitFor(async () => {
515
+ await expect(body.getByRole('menu')).toBeVisible();
516
+ });
517
+ },
518
+ );
519
+
520
+ await step(
521
+ 'keyboard: Escape dismisses the menu and returns focus to the trigger (WCAG 2.4.3)',
522
+ async () => {
523
+ await userEvent.keyboard('{Escape}');
524
+ await waitFor(async () => {
525
+ await expect(body.queryByRole('menu')).not.toBeInTheDocument();
526
+ });
527
+ // Reka restores focus asynchronously after the menu unmounts.
528
+ await waitFor(async () => {
529
+ await expect(trigger).toHaveFocus();
530
+ });
531
+ },
532
+ );
533
+ },
534
+ };
535
+
536
+ const routerLinkTemplateSource = `<script setup lang="ts">
537
+ import { RouterLink } from 'vue-router'
538
+ import {
539
+ UiBreadcrumb,
540
+ UiBreadcrumbItem,
541
+ UiBreadcrumbLink,
542
+ UiBreadcrumbList,
543
+ UiBreadcrumbPage,
544
+ UiBreadcrumbSeparator,
545
+ } from '@aleph-alpha/ui-library'
546
+ </script>
547
+
548
+ <template>
549
+ <UiBreadcrumb>
550
+ <UiBreadcrumbList>
551
+ <UiBreadcrumbItem>
552
+ <UiBreadcrumbLink as-child>
553
+ <RouterLink to="/">Home</RouterLink>
554
+ </UiBreadcrumbLink>
555
+ </UiBreadcrumbItem>
556
+ <UiBreadcrumbSeparator />
557
+ <UiBreadcrumbItem>
558
+ <UiBreadcrumbLink as-child>
559
+ <RouterLink to="/components">Components</RouterLink>
560
+ </UiBreadcrumbLink>
561
+ </UiBreadcrumbItem>
562
+ <UiBreadcrumbSeparator />
563
+ <UiBreadcrumbItem>
564
+ <UiBreadcrumbPage>Breadcrumb</UiBreadcrumbPage>
565
+ </UiBreadcrumbItem>
566
+ </UiBreadcrumbList>
567
+ </UiBreadcrumb>
568
+ </template>`;
569
+
570
+ /**
571
+ * Set `as-child` on `UiBreadcrumbLink` to hand rendering over to your router's
572
+ * link component (`RouterLink`, `NuxtLink`) while keeping breadcrumb styling.
573
+ * `as-child` merges the crumb's props into the slotted element rather than
574
+ * wrapping it, so no redundant anchor is emitted.
575
+ */
576
+ export const WithCustomLinkComponent: Story = {
577
+ render: () => ({
578
+ components: { ...components, RouterLink },
579
+ template: `
580
+ <UiBreadcrumb>
581
+ <UiBreadcrumbList>
582
+ <UiBreadcrumbItem>
583
+ <UiBreadcrumbLink as-child>
584
+ <RouterLink to="/">Home</RouterLink>
585
+ </UiBreadcrumbLink>
586
+ </UiBreadcrumbItem>
587
+ <UiBreadcrumbSeparator />
588
+ <UiBreadcrumbItem>
589
+ <UiBreadcrumbLink as-child>
590
+ <RouterLink to="/components">Components</RouterLink>
591
+ </UiBreadcrumbLink>
592
+ </UiBreadcrumbItem>
593
+ <UiBreadcrumbSeparator />
594
+ <UiBreadcrumbItem>
595
+ <UiBreadcrumbPage>Breadcrumb</UiBreadcrumbPage>
596
+ </UiBreadcrumbItem>
597
+ </UiBreadcrumbList>
598
+ </UiBreadcrumb>
599
+ `,
600
+ }),
601
+ parameters: {
602
+ docs: {
603
+ source: {
604
+ code: routerLinkTemplateSource,
605
+ },
606
+ },
607
+ },
608
+ play: async ({ canvasElement, step }) => {
609
+ // Scenario (UiBreadcrumb): with as-child the router's link replaces the crumb's
610
+ // own anchor, so each crumb still exposes exactly one link with its destination.
611
+ const canvas = within(canvasElement);
612
+
613
+ await step(
614
+ 'interaction: the slotted router link owns the crumb, with no nested anchor',
615
+ async () => {
616
+ const home = canvas.getByRole('link', { name: 'Home' });
617
+ await expect(home).toHaveAttribute('href', '/');
618
+ await expect(home.querySelector('a')).toBeNull();
619
+ },
620
+ );
621
+
622
+ await step(
623
+ 'interaction: as-child does not emit a duplicate crumb element',
624
+ async () => {
625
+ // Two anchors plus the current page, which carries role="link".
626
+ await expect(canvas.getAllByRole('link')).toHaveLength(3);
627
+ await expect(canvas.getAllByRole('listitem')).toHaveLength(3);
628
+ },
629
+ );
630
+ },
631
+ };
632
+
633
+ const responsiveTemplateSource = `<script setup lang="ts">
634
+ import { ref } from 'vue'
635
+ import { useMediaQuery } from '@vueuse/core'
636
+ import {
637
+ UiBreadcrumb,
638
+ UiBreadcrumbEllipsis,
639
+ UiBreadcrumbItem,
640
+ UiBreadcrumbLink,
641
+ UiBreadcrumbList,
642
+ UiBreadcrumbPage,
643
+ UiBreadcrumbSeparator,
644
+ UiButton,
645
+ UiDrawer,
646
+ UiDrawerClose,
647
+ UiDrawerContent,
648
+ UiDrawerDescription,
649
+ UiDrawerFooter,
650
+ UiDrawerHeader,
651
+ UiDrawerTitle,
652
+ UiDrawerTrigger,
653
+ UiDropdownMenu,
654
+ UiDropdownMenuContent,
655
+ UiDropdownMenuItem,
656
+ UiDropdownMenuTrigger,
657
+ } from '@aleph-alpha/ui-library'
658
+
659
+ const items = [
660
+ { href: '#', label: 'Home' },
661
+ { href: '#', label: 'Documentation' },
662
+ { href: '#', label: 'Building Your Application' },
663
+ { href: '#', label: 'Data Fetching' },
664
+ { label: 'Caching and Revalidating' },
665
+ ]
666
+
667
+ const ITEMS_TO_DISPLAY = 3
668
+
669
+ const open = ref(false)
670
+ const isDesktop = useMediaQuery('(min-width: 768px)')
671
+ </script>
672
+
673
+ <template>
674
+ <UiBreadcrumb>
675
+ <UiBreadcrumbList>
676
+ <UiBreadcrumbItem>
677
+ <UiBreadcrumbLink :href="items[0].href">{{ items[0].label }}</UiBreadcrumbLink>
678
+ </UiBreadcrumbItem>
679
+ <UiBreadcrumbSeparator />
680
+
681
+ <template v-if="items.length > ITEMS_TO_DISPLAY">
682
+ <UiBreadcrumbItem>
683
+ <UiDropdownMenu v-if="isDesktop" v-model:open="open">
684
+ <UiDropdownMenuTrigger class="flex items-center gap-1" aria-label="Show hidden pages">
685
+ <UiBreadcrumbEllipsis />
686
+ </UiDropdownMenuTrigger>
687
+ <UiDropdownMenuContent align="start">
688
+ <UiDropdownMenuItem v-for="item in items.slice(1, -2)" :key="item.label">
689
+ {{ item.label }}
690
+ </UiDropdownMenuItem>
691
+ </UiDropdownMenuContent>
692
+ </UiDropdownMenu>
693
+
694
+ <UiDrawer v-else v-model:open="open">
695
+ <UiDrawerTrigger aria-label="Show hidden pages">
696
+ <UiBreadcrumbEllipsis />
697
+ </UiDrawerTrigger>
698
+ <UiDrawerContent>
699
+ <UiDrawerHeader class="text-left">
700
+ <UiDrawerTitle>Navigate to</UiDrawerTitle>
701
+ <UiDrawerDescription>Select a page to navigate to.</UiDrawerDescription>
702
+ </UiDrawerHeader>
703
+ <div class="grid gap-1 px-4">
704
+ <a
705
+ v-for="item in items.slice(1, -2)"
706
+ :key="item.label"
707
+ :href="item.href"
708
+ class="py-1 body-14-regular"
709
+ >
710
+ {{ item.label }}
711
+ </a>
712
+ </div>
713
+ <UiDrawerFooter class="pt-4">
714
+ <UiDrawerClose as-child>
715
+ <UiButton variant="outline">Close</UiButton>
716
+ </UiDrawerClose>
717
+ </UiDrawerFooter>
718
+ </UiDrawerContent>
719
+ </UiDrawer>
720
+ </UiBreadcrumbItem>
721
+ <UiBreadcrumbSeparator />
722
+ </template>
723
+
724
+ <template v-for="(item, index) in items.slice(-ITEMS_TO_DISPLAY + 1)" :key="item.label">
725
+ <UiBreadcrumbItem>
726
+ <UiBreadcrumbLink v-if="item.href" :href="item.href" class="max-w-20 truncate md:max-w-none">
727
+ {{ item.label }}
728
+ </UiBreadcrumbLink>
729
+ <UiBreadcrumbPage v-else class="max-w-20 truncate md:max-w-none">
730
+ {{ item.label }}
731
+ </UiBreadcrumbPage>
732
+ </UiBreadcrumbItem>
733
+ <UiBreadcrumbSeparator v-if="index < ITEMS_TO_DISPLAY - 2" />
734
+ </template>
735
+ </UiBreadcrumbList>
736
+ </UiBreadcrumb>
737
+ </template>`;
738
+
739
+ /**
740
+ * Shared render for the collapsing trail. The hidden crumbs open in a dropdown menu on
741
+ * desktop and in a drawer below 768px, chosen by `useMediaQuery` — so which one appears
742
+ * depends on the real viewport width.
743
+ */
744
+ const renderResponsiveTrail = () => ({
745
+ components: {
746
+ ...components,
747
+ ...dropdownComponents,
748
+ ...drawerComponents,
749
+ UiButton,
750
+ },
751
+ setup() {
752
+ const items = [
753
+ { href: '#', label: 'Home' },
754
+ { href: '#', label: 'Documentation' },
755
+ { href: '#', label: 'Building Your Application' },
756
+ { href: '#', label: 'Data Fetching' },
757
+ { label: 'Caching and Revalidating' },
758
+ ];
759
+
760
+ const open = ref(false);
761
+ const isDesktop = useMediaQuery('(min-width: 768px)');
762
+
763
+ return { items, open, isDesktop, ITEMS_TO_DISPLAY: 3 };
764
+ },
765
+ template: `
766
+ <UiBreadcrumb>
767
+ <UiBreadcrumbList>
768
+ <UiBreadcrumbItem>
769
+ <UiBreadcrumbLink :href="items[0].href">{{ items[0].label }}</UiBreadcrumbLink>
770
+ </UiBreadcrumbItem>
771
+ <UiBreadcrumbSeparator />
772
+
773
+ <template v-if="items.length > ITEMS_TO_DISPLAY">
774
+ <UiBreadcrumbItem>
775
+ <UiDropdownMenu v-if="isDesktop" v-model:open="open">
776
+ <UiDropdownMenuTrigger class="flex items-center gap-1" aria-label="Show hidden pages">
777
+ <UiBreadcrumbEllipsis />
778
+ </UiDropdownMenuTrigger>
779
+ <UiDropdownMenuContent align="start">
780
+ <UiDropdownMenuItem v-for="item in items.slice(1, -2)" :key="item.label">
781
+ {{ item.label }}
782
+ </UiDropdownMenuItem>
783
+ </UiDropdownMenuContent>
784
+ </UiDropdownMenu>
785
+
786
+ <UiDrawer v-else v-model:open="open">
787
+ <UiDrawerTrigger aria-label="Show hidden pages">
788
+ <UiBreadcrumbEllipsis />
789
+ </UiDrawerTrigger>
790
+ <UiDrawerContent>
791
+ <UiDrawerHeader class="text-left">
792
+ <UiDrawerTitle>Navigate to</UiDrawerTitle>
793
+ <UiDrawerDescription>Select a page to navigate to.</UiDrawerDescription>
794
+ </UiDrawerHeader>
795
+ <div class="grid gap-1 px-4">
796
+ <a
797
+ v-for="item in items.slice(1, -2)"
798
+ :key="item.label"
799
+ :href="item.href"
800
+ class="py-1 body-14-regular"
801
+ >
802
+ {{ item.label }}
803
+ </a>
804
+ </div>
805
+ <UiDrawerFooter class="pt-4">
806
+ <UiDrawerClose as-child>
807
+ <UiButton variant="outline">Close</UiButton>
808
+ </UiDrawerClose>
809
+ </UiDrawerFooter>
810
+ </UiDrawerContent>
811
+ </UiDrawer>
812
+ </UiBreadcrumbItem>
813
+ <UiBreadcrumbSeparator />
814
+ </template>
815
+
816
+ <template v-for="(item, index) in items.slice(-ITEMS_TO_DISPLAY + 1)" :key="item.label">
817
+ <UiBreadcrumbItem>
818
+ <UiBreadcrumbLink v-if="item.href" :href="item.href" class="max-w-20 truncate md:max-w-none">
819
+ {{ item.label }}
820
+ </UiBreadcrumbLink>
821
+ <UiBreadcrumbPage v-else class="max-w-20 truncate md:max-w-none">
822
+ {{ item.label }}
823
+ </UiBreadcrumbPage>
824
+ </UiBreadcrumbItem>
825
+ <UiBreadcrumbSeparator v-if="index < ITEMS_TO_DISPLAY - 2" />
826
+ </template>
827
+ </UiBreadcrumbList>
828
+ </UiBreadcrumb>
829
+ `,
830
+ });
831
+
832
+ /**
833
+ * A long trail that collapses its middle crumbs, revealing them in a dropdown on
834
+ * desktop and a drawer on touch-sized viewports. Use the Storybook viewport
835
+ * toolbar to switch between the two presentations.
836
+ */
837
+ export const Responsive: Story = {
838
+ render: renderResponsiveTrail,
839
+ parameters: {
840
+ docs: {
841
+ source: {
842
+ code: responsiveTemplateSource,
843
+ },
844
+ },
845
+ },
846
+ };
847
+
848
+ /**
849
+ * A keyboard user tabs along the trail. Every crumb link is reachable in DOM
850
+ * order, the current-page crumb is deliberately skipped because it is not a
851
+ * navigation target, and `Enter` follows the focused crumb.
852
+ */
853
+ export const KeyboardNavigation: Story = {
854
+ name: 'test - Keyboard Navigation',
855
+ tags: ['!dev', '!autodocs'],
856
+ parameters: {
857
+ // Focus moves during the play function; skip the visual snapshot so the
858
+ // focus ring doesn't register as a Chromatic diff.
859
+ chromatic: { disableSnapshot: true },
860
+ docs: {
861
+ description: {
862
+ story:
863
+ 'Tab along the crumbs, confirm the current page is skipped, and activate a crumb with Enter.',
864
+ },
865
+ },
866
+ },
867
+ render: () => ({
868
+ components: { ...components, RouterLink },
869
+ setup() {
870
+ return { onCrumbClick };
871
+ },
872
+ template: `
873
+ <UiBreadcrumb>
874
+ <UiBreadcrumbList>
875
+ <UiBreadcrumbItem>
876
+ <UiBreadcrumbLink as-child>
877
+ <RouterLink to="/home" @click="onCrumbClick">Home</RouterLink>
878
+ </UiBreadcrumbLink>
879
+ </UiBreadcrumbItem>
880
+ <UiBreadcrumbSeparator />
881
+ <UiBreadcrumbItem>
882
+ <UiBreadcrumbLink as-child>
883
+ <RouterLink to="/home/docs" @click="onCrumbClick">Documentation</RouterLink>
884
+ </UiBreadcrumbLink>
885
+ </UiBreadcrumbItem>
886
+ <UiBreadcrumbSeparator />
887
+ <UiBreadcrumbItem>
888
+ <UiBreadcrumbPage>Breadcrumb</UiBreadcrumbPage>
889
+ </UiBreadcrumbItem>
890
+ </UiBreadcrumbList>
891
+ </UiBreadcrumb>
892
+ `,
893
+ }),
894
+ play: async ({ canvasElement, step }) => {
895
+ // Scenario (UiBreadcrumb): a keyboard user tabs from the first crumb to the
896
+ // second, finds the current-page crumb excluded from the tab order, and
897
+ // activates a crumb with Enter.
898
+ onCrumbClick.mockClear();
899
+ const canvas = within(canvasElement);
900
+ const home = canvas.getByRole('link', { name: 'Home' });
901
+ const docs = canvas.getByRole('link', { name: 'Documentation' });
902
+ const current = canvas.getByRole('link', { name: 'Breadcrumb' });
903
+
904
+ await step(
905
+ 'keyboard: Tab reaches the first crumb (WCAG 2.1.1 Keyboard)',
906
+ async () => {
907
+ await userEvent.tab();
908
+ await expect(home).toHaveFocus();
909
+ },
910
+ );
911
+
912
+ await step(
913
+ 'keyboard: Tab follows the trail in DOM order (WCAG 2.4.3 Focus Order)',
914
+ async () => {
915
+ await userEvent.tab();
916
+ await expect(docs).toHaveFocus();
917
+ },
918
+ );
919
+
920
+ await step(
921
+ 'keyboard: the current-page crumb is skipped by Tab',
922
+ async () => {
923
+ await userEvent.tab();
924
+ await expect(current).not.toHaveFocus();
925
+ },
926
+ );
927
+
928
+ await step('keyboard: Enter activates the focused crumb', async () => {
929
+ home.focus();
930
+ await expect(home).toHaveFocus();
931
+ await userEvent.keyboard('{Enter}');
932
+ await expect(onCrumbClick).toHaveBeenCalledTimes(1);
933
+ });
934
+ },
935
+ };
936
+
937
+ /**
938
+ * Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
939
+ * try 400% reflow (WCAG 1.4.10); the trail must stay visible and operable.
940
+ */
941
+ export const ZoomMagnification: Story = {
942
+ name: 'test - Zoom Magnification',
943
+ tags: ['!dev', '!autodocs'],
944
+ globals: { zoom: '200' },
945
+ parameters: {
946
+ // Zoom changes the layout scale; the accessible-reflow Chromatic mode
947
+ // already covers magnified snapshots, so skip this one.
948
+ chromatic: { disableSnapshot: true },
949
+ docs: {
950
+ description: {
951
+ story:
952
+ 'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
953
+ },
954
+ },
955
+ },
956
+ render: () => ({
957
+ components: { ...components, ...dropdownComponents },
958
+ setup() {
959
+ return { onMenuSelect };
960
+ },
961
+ template: `
962
+ <UiBreadcrumb>
963
+ <UiBreadcrumbList>
964
+ <UiBreadcrumbItem>
965
+ <UiBreadcrumbLink href="/">Home</UiBreadcrumbLink>
966
+ </UiBreadcrumbItem>
967
+ <UiBreadcrumbSeparator />
968
+ <UiBreadcrumbItem>
969
+ <UiDropdownMenu>
970
+ <UiDropdownMenuTrigger class="flex items-center gap-1" aria-label="Show hidden pages">
971
+ <UiBreadcrumbEllipsis />
972
+ </UiDropdownMenuTrigger>
973
+ <UiDropdownMenuContent align="start">
974
+ <UiDropdownMenuItem @click="onMenuSelect">Documentation</UiDropdownMenuItem>
975
+ </UiDropdownMenuContent>
976
+ </UiDropdownMenu>
977
+ </UiBreadcrumbItem>
978
+ <UiBreadcrumbSeparator />
979
+ <UiBreadcrumbItem>
980
+ <UiBreadcrumbPage>Caching and Revalidating</UiBreadcrumbPage>
981
+ </UiBreadcrumbItem>
982
+ </UiBreadcrumbList>
983
+ </UiBreadcrumb>
984
+ `,
985
+ }),
986
+ play: async ({ canvasElement, step }) => {
987
+ // Scenario (UiBreadcrumb): at 200% page zoom the crumbs stay visible with their
988
+ // accessible names and the collapsed-crumbs menu still opens.
989
+ onMenuSelect.mockClear();
990
+ const canvas = within(canvasElement);
991
+ const body = within(document.body);
992
+
993
+ await step(
994
+ 'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
995
+ async () => {
996
+ await expect(document.documentElement.style.zoom).toBe('200%');
997
+ },
998
+ );
999
+
1000
+ await step(
1001
+ 'zoom: crumbs stay visible with their accessible names',
1002
+ async () => {
1003
+ await expect(canvas.getByRole('link', { name: 'Home' })).toBeVisible();
1004
+ await expect(
1005
+ canvas.getByRole('link', { name: 'Caching and Revalidating' }),
1006
+ ).toBeVisible();
1007
+ },
1008
+ );
1009
+
1010
+ await step('zoom: remains operable when magnified', async () => {
1011
+ await userEvent.click(
1012
+ canvas.getByRole('button', { name: 'Show hidden pages' }),
1013
+ );
1014
+ await waitFor(async () => {
1015
+ await expect(body.getByRole('menu')).toBeVisible();
1016
+ });
1017
+ // Leave the menu closed: while it is open Reka marks the rest of the app
1018
+ // aria-hidden, which the axe audit would flag as hiding focusable content.
1019
+ await userEvent.keyboard('{Escape}');
1020
+ await waitFor(async () => {
1021
+ await expect(body.queryByRole('menu')).not.toBeInTheDocument();
1022
+ });
1023
+ });
1024
+ },
1025
+ };
1026
+
1027
+ /**
1028
+ * What assistive technology reports for the trail: a named `nav` landmark, a
1029
+ * list of crumbs with the decorative separators removed, the current page
1030
+ * announced via `aria-current`, and a named trigger for the collapsed crumbs.
1031
+ */
1032
+ export const ScreenReader: Story = {
1033
+ name: 'test - Screen Reader',
1034
+ tags: ['!dev', '!autodocs'],
1035
+ parameters: {
1036
+ docs: {
1037
+ description: {
1038
+ story:
1039
+ 'Accessible names, list semantics, and ARIA state exposed by the breadcrumb.',
1040
+ },
1041
+ },
1042
+ },
1043
+ render: () => ({
1044
+ components: { ...components, ...dropdownComponents },
1045
+ template: `
1046
+ <UiBreadcrumb>
1047
+ <UiBreadcrumbList>
1048
+ <UiBreadcrumbItem>
1049
+ <UiBreadcrumbLink href="/">Home</UiBreadcrumbLink>
1050
+ </UiBreadcrumbItem>
1051
+ <UiBreadcrumbSeparator />
1052
+ <UiBreadcrumbItem>
1053
+ <UiDropdownMenu>
1054
+ <UiDropdownMenuTrigger class="flex items-center gap-1" aria-label="Show hidden pages">
1055
+ <UiBreadcrumbEllipsis />
1056
+ </UiDropdownMenuTrigger>
1057
+ <UiDropdownMenuContent align="start">
1058
+ <UiDropdownMenuItem>Documentation</UiDropdownMenuItem>
1059
+ </UiDropdownMenuContent>
1060
+ </UiDropdownMenu>
1061
+ </UiBreadcrumbItem>
1062
+ <UiBreadcrumbSeparator />
1063
+ <UiBreadcrumbItem>
1064
+ <UiBreadcrumbPage>Data Fetching</UiBreadcrumbPage>
1065
+ </UiBreadcrumbItem>
1066
+ </UiBreadcrumbList>
1067
+ </UiBreadcrumb>
1068
+ `,
1069
+ }),
1070
+ play: async ({ canvasElement, step }) => {
1071
+ // Scenario (UiBreadcrumb): a screen-reader user reaches the trail by landmark,
1072
+ // hears three crumbs rather than five list items, is told which one is current,
1073
+ // and gets a real name for the collapsed-crumbs trigger.
1074
+ const canvas = within(canvasElement);
1075
+
1076
+ await step(
1077
+ 'screen-reader: the trail is reachable as a named landmark (WCAG 1.3.1)',
1078
+ async () => {
1079
+ await expect(
1080
+ canvas.getByRole('navigation', { name: 'breadcrumb' }),
1081
+ ).toHaveAccessibleName('breadcrumb');
1082
+ },
1083
+ );
1084
+
1085
+ await step(
1086
+ 'screen-reader: crumbs are announced as a list without the separators',
1087
+ async () => {
1088
+ await expect(canvas.getByRole('list')).toBeInTheDocument();
1089
+ await expect(canvas.getAllByRole('listitem')).toHaveLength(3);
1090
+ },
1091
+ );
1092
+
1093
+ await step(
1094
+ 'screen-reader: the current page is announced via aria-current (WCAG 4.1.2)',
1095
+ async () => {
1096
+ await expect(
1097
+ canvas.getByRole('link', { name: 'Data Fetching' }),
1098
+ ).toHaveAttribute('aria-current', 'page');
1099
+ },
1100
+ );
1101
+
1102
+ await step(
1103
+ 'screen-reader: the collapsed-crumbs trigger is labelled, since the ellipsis is aria-hidden',
1104
+ async () => {
1105
+ await expect(
1106
+ canvas.getByRole('button', { name: 'Show hidden pages' }),
1107
+ ).toHaveAccessibleName('Show hidden pages');
1108
+ await expect(
1109
+ canvas.getByText('More').closest('[aria-hidden="true"]'),
1110
+ ).not.toBeNull();
1111
+ },
1112
+ );
1113
+ },
1114
+ };
1115
+
1116
+ /**
1117
+ * Accessibility guidance for the breadcrumb: a named landmark, a clearly marked
1118
+ * current page, and decorative parts kept out of the accessibility tree — shown
1119
+ * side by side in the default and accessible themes.
1120
+ */
1121
+ export const Accessibility: Story = {
1122
+ tags: ['!autodocs'],
1123
+ parameters: {
1124
+ a11y: { test: 'off' },
1125
+ chromatic: { disableSnapshot: true },
1126
+ docs: {
1127
+ canvas: {
1128
+ sourceState: 'none',
1129
+ },
1130
+ },
1131
+ },
1132
+ render: () => ({
1133
+ components,
1134
+ template: `
1135
+ <section class="flex flex-col gap-6 p-4">
1136
+ <div>
1137
+ <h2 class="heading-m font-bold text-content-on-surface-primary">
1138
+ Accessibility
1139
+ </h2>
1140
+ </div>
1141
+
1142
+ <div class="flex flex-col gap-6">
1143
+ <div class="flex flex-col gap-2">
1144
+ <h3 class="body-16-medium text-content-on-surface-primary">
1145
+ The trail is already a named landmark
1146
+ </h3>
1147
+ <p class="body-16-regular text-content-on-surface-primary">
1148
+ <code>UiBreadcrumb</code> renders a <code>nav</code> labelled
1149
+ "breadcrumb" around an ordered list, so screen-reader users can jump
1150
+ straight to it. You do not need to add your own
1151
+ <code>aria-label</code>, and there should only be one breadcrumb
1152
+ trail per page.
1153
+ </p>
1154
+ </div>
1155
+
1156
+ <div class="flex flex-col gap-2">
1157
+ <h3 class="body-16-medium text-content-on-surface-primary">
1158
+ Mark the current page
1159
+ </h3>
1160
+ <p class="body-16-regular text-content-on-surface-primary">
1161
+ End the trail with <code>UiBreadcrumbPage</code> instead of
1162
+ <code>UiBreadcrumbLink</code>. It sets
1163
+ <code>aria-current="page"</code> and is not a link, so
1164
+ <code>Tab</code> skips it — a link that navigates nowhere is
1165
+ confusing (WCAG 4.1.2).
1166
+ </p>
1167
+ </div>
1168
+
1169
+ <div class="flex flex-col gap-2">
1170
+ <h3 class="body-16-medium text-content-on-surface-primary">
1171
+ Label the collapsed-crumbs trigger
1172
+ </h3>
1173
+ <p class="body-16-regular text-content-on-surface-primary">
1174
+ <code>UiBreadcrumbEllipsis</code> is hidden from assistive
1175
+ technology, so it contributes no accessible name. When you wrap it in
1176
+ a menu trigger, give that trigger an <code>aria-label</code> such as
1177
+ "Show hidden pages", and keep its target at least 24×24px
1178
+ (WCAG 2.5.8).
1179
+ </p>
1180
+ </div>
1181
+
1182
+ <div class="flex flex-col gap-2">
1183
+ <h3 class="body-16-medium text-content-on-surface-primary">
1184
+ Keep separators decorative
1185
+ </h3>
1186
+ <p class="body-16-regular text-content-on-surface-primary">
1187
+ <code>UiBreadcrumbSeparator</code> is presentational and excluded
1188
+ from the list, so screen readers announce the crumbs without a
1189
+ "slash" between each one. Never put meaningful text in it.
1190
+ </p>
1191
+ </div>
1192
+
1193
+ <div class="flex flex-col gap-2">
1194
+ <h3 class="body-16-medium text-content-on-surface-primary">
1195
+ Enable accessibility theme
1196
+ </h3>
1197
+ <p class="body-16-regular text-content-on-surface-primary">
1198
+ When accessibility is required, enable our accessibility theme.
1199
+ This increases contrast and makes sure there are no color
1200
+ contrast issues.
1201
+ </p>
1202
+ </div>
1203
+ </div>
1204
+
1205
+ <div class="grid gap-4 md:grid-cols-2">
1206
+ <div class="flex flex-col gap-3">
1207
+ <h3 class="label-16-medium text-center text-content-on-surface-primary">
1208
+ Default
1209
+ </h3>
1210
+ <div class="flex min-h-20 items-center justify-center border border-border-surface-default p-6">
1211
+ <UiBreadcrumb>
1212
+ <UiBreadcrumbList>
1213
+ <UiBreadcrumbItem>
1214
+ <UiBreadcrumbLink href="/">Home</UiBreadcrumbLink>
1215
+ </UiBreadcrumbItem>
1216
+ <UiBreadcrumbSeparator />
1217
+ <UiBreadcrumbItem>
1218
+ <UiBreadcrumbLink href="/components">Components</UiBreadcrumbLink>
1219
+ </UiBreadcrumbItem>
1220
+ <UiBreadcrumbSeparator />
1221
+ <UiBreadcrumbItem>
1222
+ <UiBreadcrumbPage>Breadcrumb</UiBreadcrumbPage>
1223
+ </UiBreadcrumbItem>
1224
+ </UiBreadcrumbList>
1225
+ </UiBreadcrumb>
1226
+ </div>
1227
+ </div>
1228
+
1229
+ <div class="accessible-theme flex flex-col gap-3">
1230
+ <h3 class="label-16-medium text-center text-content-on-surface-primary">
1231
+ Accessible
1232
+ </h3>
1233
+ <div class="flex min-h-20 items-center justify-center border border-border-surface-default p-6">
1234
+ <UiBreadcrumb>
1235
+ <UiBreadcrumbList>
1236
+ <UiBreadcrumbItem>
1237
+ <UiBreadcrumbLink href="/">Home</UiBreadcrumbLink>
1238
+ </UiBreadcrumbItem>
1239
+ <UiBreadcrumbSeparator />
1240
+ <UiBreadcrumbItem>
1241
+ <UiBreadcrumbLink href="/components">Components</UiBreadcrumbLink>
1242
+ </UiBreadcrumbItem>
1243
+ <UiBreadcrumbSeparator />
1244
+ <UiBreadcrumbItem>
1245
+ <UiBreadcrumbPage>Breadcrumb</UiBreadcrumbPage>
1246
+ </UiBreadcrumbItem>
1247
+ </UiBreadcrumbList>
1248
+ </UiBreadcrumb>
1249
+ </div>
1250
+ </div>
1251
+ </div>
1252
+ </section>
1253
+ `,
1254
+ }),
1255
+ };
1256
+
1257
+ /**
1258
+ * The collapsing trail above 768px, where `useMediaQuery` selects the dropdown menu.
1259
+ * Pairs with `test - Mobile Breakpoint`, which asserts the drawer is used instead at
1260
+ * 320px; together they cover the responsive swap.
1261
+ */
1262
+ export const ResponsiveDesktop: Story = {
1263
+ name: 'test - Responsive Desktop',
1264
+ tags: ['!dev', '!autodocs'],
1265
+ parameters: {
1266
+ // The play opens the menu and moves focus; the Responsive story covers the visuals.
1267
+ chromatic: { disableSnapshot: true },
1268
+ docs: {
1269
+ description: {
1270
+ story:
1271
+ 'On a desktop-width viewport the hidden crumbs open in a dropdown menu, not a drawer.',
1272
+ },
1273
+ },
1274
+ },
1275
+ render: renderResponsiveTrail,
1276
+ play: async ({ canvasElement, step }) => {
1277
+ // Scenario (UiBreadcrumb): on a wide viewport the collapsed crumbs open in a
1278
+ // dropdown menu, and no drawer is mounted.
1279
+ const canvas = within(canvasElement);
1280
+ const body = within(document.body);
1281
+
1282
+ await step(
1283
+ 'interaction: the viewport is wider than the 768px switch',
1284
+ async () => {
1285
+ await expect(window.innerWidth).toBeGreaterThanOrEqual(768);
1286
+ },
1287
+ );
1288
+
1289
+ await step(
1290
+ 'interaction: the collapsed crumbs open in a dropdown menu',
1291
+ async () => {
1292
+ await userEvent.click(
1293
+ canvas.getByRole('button', { name: 'Show hidden pages' }),
1294
+ );
1295
+ await waitFor(async () => {
1296
+ await expect(body.getByRole('menu')).toBeVisible();
1297
+ });
1298
+ await expect(
1299
+ body.getAllByRole('menuitem').map((item) => item.textContent?.trim()),
1300
+ ).toEqual(HIDDEN_CRUMBS);
1301
+ await expect(body.queryByRole('dialog')).not.toBeInTheDocument();
1302
+ },
1303
+ );
1304
+
1305
+ await step(
1306
+ 'interaction: dismissing the menu restores the trail',
1307
+ async () => {
1308
+ // Leave the menu closed: while it is open Reka marks the rest of the app
1309
+ // aria-hidden, which the axe audit would flag as hiding focusable content.
1310
+ await userEvent.keyboard('{Escape}');
1311
+ await waitFor(async () => {
1312
+ await expect(body.queryByRole('menu')).not.toBeInTheDocument();
1313
+ });
1314
+ await expect(
1315
+ canvas.getByRole('navigation', { name: 'breadcrumb' }),
1316
+ ).toBeVisible();
1317
+ },
1318
+ );
1319
+ },
1320
+ };
1321
+
1322
+ /**
1323
+ * Rendered at the 320px mobile breakpoint (WCAG 1.4.10 Reflow). The trail fits without
1324
+ * sideways scrolling, `useMediaQuery` swaps the dropdown for a drawer, and the
1325
+ * collapsed-crumbs trigger keeps an adequate touch target (WCAG 2.5.8).
1326
+ */
1327
+ export const MobileBreakpoint: Story = {
1328
+ name: 'test - Mobile Breakpoint',
1329
+ tags: ['!dev', '!autodocs'],
1330
+ globals: { mediaBreakpoint: 'reflow' },
1331
+ parameters: {
1332
+ // Reflow snapshots are already covered by the accessible-reflow mode.
1333
+ chromatic: { disableSnapshot: true },
1334
+ docs: {
1335
+ description: {
1336
+ story:
1337
+ 'Use the Media breakpoint toolbar to render the trail at 320px wide.',
1338
+ },
1339
+ },
1340
+ },
1341
+ render: renderResponsiveTrail,
1342
+ play: async ({ canvasElement, step }) => {
1343
+ // Scenario (UiBreadcrumb): at 320px the trail fits without sideways scrolling, the
1344
+ // hidden crumbs open in a drawer instead of a dropdown, and the trigger stays tappable.
1345
+ const canvas = within(canvasElement);
1346
+ const body = within(document.body);
1347
+ const trigger = canvas.getByRole('button', { name: 'Show hidden pages' });
1348
+
1349
+ await step(
1350
+ 'mobile: the story renders at the 320px breakpoint (WCAG 1.4.10 Reflow)',
1351
+ async () => {
1352
+ await expect(document.documentElement.dataset.aaMediaBreakpoint).toBe(
1353
+ 'reflow',
1354
+ );
1355
+ await expect(window.innerWidth).toBeLessThanOrEqual(320);
1356
+ },
1357
+ );
1358
+
1359
+ await step(
1360
+ 'mobile: the trail fits without sideways scrolling',
1361
+ async () => {
1362
+ const { scrollWidth, clientWidth } = document.documentElement;
1363
+ await expect(scrollWidth).toBeLessThanOrEqual(clientWidth);
1364
+ },
1365
+ );
1366
+
1367
+ await step('mobile: every crumb stays visible', async () => {
1368
+ await expect(canvas.getByRole('link', { name: 'Home' })).toBeVisible();
1369
+ await expect(
1370
+ canvas.getByRole('link', { name: 'Caching and Revalidating' }),
1371
+ ).toBeVisible();
1372
+ });
1373
+
1374
+ await step(
1375
+ 'mobile: the collapsed-crumbs trigger meets the minimum touch-target size (WCAG 2.5.8)',
1376
+ async () => {
1377
+ const { width, height } = trigger.getBoundingClientRect();
1378
+ await expect(width).toBeGreaterThanOrEqual(24);
1379
+ await expect(height).toBeGreaterThanOrEqual(24);
1380
+ },
1381
+ );
1382
+
1383
+ await step(
1384
+ 'mobile: the collapsed crumbs open in a drawer instead of a dropdown',
1385
+ async () => {
1386
+ await userEvent.click(trigger);
1387
+ // The drawer slides and fades in, so it reports opacity 0 until the
1388
+ // animation starts; retry until it is actually visible.
1389
+ const drawer = await waitFor(
1390
+ async () => {
1391
+ const dialog = body.getByRole('dialog', { name: 'Navigate to' });
1392
+ await expect(dialog).toBeVisible();
1393
+ return dialog;
1394
+ },
1395
+ { timeout: 5000 },
1396
+ );
1397
+ for (const crumb of HIDDEN_CRUMBS) {
1398
+ await expect(
1399
+ within(drawer).getByRole('link', { name: crumb }),
1400
+ ).toBeVisible();
1401
+ }
1402
+ await expect(body.queryByRole('menu')).not.toBeInTheDocument();
1403
+ },
1404
+ );
1405
+
1406
+ await step('mobile: dismissing the drawer restores the trail', async () => {
1407
+ // Leave the drawer closed: while it is open the rest of the app is aria-hidden,
1408
+ // which the axe audit would flag as hiding focusable content.
1409
+ await userEvent.click(body.getByRole('button', { name: 'Close' }));
1410
+ await waitFor(
1411
+ async () => {
1412
+ await expect(body.queryByRole('dialog')).not.toBeInTheDocument();
1413
+ },
1414
+ { timeout: 5000 },
1415
+ );
1416
+ await expect(trigger).toBeVisible();
1417
+ });
1418
+ },
1419
+ };