@aleph-alpha/ui-library 7.0.2 → 7.2.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 (64) hide show
  1. package/dist/system/components/UiPagination/UiPagination.vue.d.ts +19 -0
  2. package/dist/system/components/UiPagination/constants.d.ts +6 -0
  3. package/dist/system/components/UiPagination/index.d.ts +3 -0
  4. package/dist/system/components/UiPagination/types.d.ts +81 -0
  5. package/dist/system/components/UiSlider/step-marks.d.ts +45 -0
  6. package/dist/system/components/UiSlider/types.d.ts +28 -0
  7. package/dist/system/components/core/pagination/Pagination.vue.d.ts +29 -0
  8. package/dist/system/components/core/pagination/PaginationContent.vue.d.ts +29 -0
  9. package/dist/system/components/core/pagination/PaginationEllipsis.vue.d.ts +22 -0
  10. package/dist/system/components/core/pagination/PaginationFirst.vue.d.ts +22 -0
  11. package/dist/system/components/core/pagination/PaginationItem.vue.d.ts +26 -0
  12. package/dist/system/components/core/pagination/PaginationLast.vue.d.ts +22 -0
  13. package/dist/system/components/core/pagination/PaginationNext.vue.d.ts +22 -0
  14. package/dist/system/components/core/pagination/PaginationPrevious.vue.d.ts +22 -0
  15. package/dist/system/components/core/pagination/index.d.ts +8 -0
  16. package/dist/system/components/core/slider/Slider.vue.d.ts +21 -1
  17. package/dist/system/components/index.d.ts +1 -0
  18. package/dist/system/icons/story-sidebar-icons.json +4 -0
  19. package/dist/system/lib.js +11762 -10952
  20. package/dist/system/patterns/UiBulkAction/UiBulkAction.vue.d.ts +43 -0
  21. package/dist/system/patterns/UiBulkAction/index.d.ts +3 -0
  22. package/dist/system/patterns/UiBulkAction/types.d.ts +109 -0
  23. package/dist/system/patterns/UiBulkAction/useBulkAction.d.ts +7 -0
  24. package/dist/system/patterns/UiDataTable/constants.d.ts +10 -0
  25. package/dist/system/patterns/index.d.ts +1 -0
  26. package/dist/system/story-sidebar-icons.json +4 -0
  27. package/package.json +8 -8
  28. package/src/components/UiPagination/UiPagination.guidance.md +60 -0
  29. package/src/components/UiPagination/UiPagination.stories.ts +1070 -0
  30. package/src/components/UiPagination/UiPagination.vue +109 -0
  31. package/src/components/UiPagination/__tests__/UiPagination.test.ts +203 -0
  32. package/src/components/UiPagination/constants.ts +17 -0
  33. package/src/components/UiPagination/index.ts +3 -0
  34. package/src/components/UiPagination/types.ts +82 -0
  35. package/src/components/UiSlider/UiSlider.stories.ts +710 -2
  36. package/src/components/UiSlider/UiSlider.vue +109 -1
  37. package/src/components/UiSlider/__tests__/UiSliderValueAndSteps.test.ts +210 -0
  38. package/src/components/UiSlider/__tests__/step-marks.test.ts +94 -0
  39. package/src/components/UiSlider/step-marks.ts +96 -0
  40. package/src/components/UiSlider/types.ts +32 -0
  41. package/src/components/core/pagination/Pagination.vue +26 -0
  42. package/src/components/core/pagination/PaginationContent.vue +24 -0
  43. package/src/components/core/pagination/PaginationEllipsis.vue +30 -0
  44. package/src/components/core/pagination/PaginationFirst.vue +30 -0
  45. package/src/components/core/pagination/PaginationItem.vue +39 -0
  46. package/src/components/core/pagination/PaginationLast.vue +30 -0
  47. package/src/components/core/pagination/PaginationNext.vue +35 -0
  48. package/src/components/core/pagination/PaginationPrevious.vue +35 -0
  49. package/src/components/core/pagination/index.ts +8 -0
  50. package/src/components/core/slider/Slider.vue +16 -6
  51. package/src/components/index.ts +1 -0
  52. package/src/patterns/UiBulkAction/UiBulkAction.guidance.md +59 -0
  53. package/src/patterns/UiBulkAction/UiBulkAction.stories.ts +2238 -0
  54. package/src/patterns/UiBulkAction/UiBulkAction.vue +62 -0
  55. package/src/patterns/UiBulkAction/__tests__/useBulkAction.test.ts +78 -0
  56. package/src/patterns/UiBulkAction/index.ts +3 -0
  57. package/src/patterns/UiBulkAction/types.ts +126 -0
  58. package/src/patterns/UiBulkAction/useBulkAction.ts +50 -0
  59. package/src/patterns/UiDataTable/UiDataTable.stories.ts +375 -1
  60. package/src/patterns/UiDataTable/UiDataTablePagination.vue +43 -60
  61. package/src/patterns/UiDataTable/__tests__/UiDataTablePagination.test.ts +58 -29
  62. package/src/patterns/UiDataTable/constants.ts +10 -0
  63. package/src/patterns/UiProfileCard/UiProfileCard.stories.ts +12 -12
  64. package/src/patterns/index.ts +1 -0
@@ -0,0 +1,1070 @@
1
+ import type { Meta, StoryObj } from '@storybook/vue3-vite';
2
+ import { expect, fn, userEvent, within } from 'storybook/test';
3
+ import { computed, ref, watch } from 'vue';
4
+ import UiPagination from './UiPagination.vue';
5
+ import {
6
+ accessibilityRequirementsTemplate,
7
+ designNotesStory,
8
+ guidanceSectionClass,
9
+ parseGuidance,
10
+ } from '../../../.storybook/guidance';
11
+ import guidanceMarkdown from './UiPagination.guidance.md?raw';
12
+
13
+ const guidance = parseGuidance(guidanceMarkdown);
14
+
15
+ // `UiPagination` reports page changes through `update:page`, so plays assert
16
+ // against this module-level spy bound via `@update:page`. Each `play` clears
17
+ // it first, so the shared spy is safe.
18
+ const onPageChange = fn();
19
+
20
+ /**
21
+ * UiPagination lets users move through content split across pages. It renders
22
+ * a labelled `nav` landmark with previous/next controls, page numbers, and
23
+ * ellipses for skipped ranges. Bind the current page with `v-model:page`.
24
+ */
25
+ const meta: Meta<typeof UiPagination> = {
26
+ title: 'Components/UiPagination',
27
+ component: UiPagination,
28
+ tags: ['autodocs'],
29
+ argTypes: {
30
+ page: {
31
+ control: { type: 'number', min: 1 },
32
+ description: 'The current page (1-based). Bind with `v-model:page`.',
33
+ },
34
+ total: {
35
+ control: { type: 'number', min: 0 },
36
+ description: 'Total number of items across all pages.',
37
+ },
38
+ itemsPerPage: {
39
+ control: { type: 'number', min: 1 },
40
+ },
41
+ siblingCount: {
42
+ control: { type: 'number', min: 0 },
43
+ description: 'Page buttons shown on each side of the current page.',
44
+ },
45
+ showEdges: {
46
+ control: 'boolean',
47
+ description:
48
+ 'Always show the first and last page numbers, collapsing gaps with an ellipsis.',
49
+ },
50
+ showFirstLast: {
51
+ control: 'boolean',
52
+ description:
53
+ 'Show icon-only buttons that jump to the first and last page.',
54
+ },
55
+ disabled: {
56
+ control: 'boolean',
57
+ },
58
+ labels: {
59
+ control: false,
60
+ description:
61
+ 'Overrides for visible and screen-reader text, e.g. for translations.',
62
+ },
63
+ },
64
+ args: {
65
+ page: 1,
66
+ total: 100,
67
+ itemsPerPage: 10,
68
+ siblingCount: 1,
69
+ showEdges: true,
70
+ showFirstLast: false,
71
+ disabled: false,
72
+ },
73
+ };
74
+
75
+ export default meta;
76
+
77
+ type Story = StoryObj<typeof UiPagination>;
78
+
79
+ // Test-only stories drive the test-runner (interactive/a11y checks) but are
80
+ // hidden from the Storybook sidebar and docs via the `!dev` / `!autodocs`
81
+ // tags. They keep the implicit `test` tag, so they still run in CI and appear
82
+ // in the automated report under their `test - …` name. `name`/`tags` must be
83
+ // literal properties so Storybook's static CSF indexer can read them.
84
+
85
+ const defaultTemplateSource = `<script setup lang="ts">
86
+ import { ref } from 'vue'
87
+ import { UiPagination } from '@aleph-alpha/ui-library'
88
+
89
+ const page = ref(1)
90
+ </script>
91
+
92
+ <template>
93
+ <UiPagination v-model:page="page" :total="100" :items-per-page="10" />
94
+ </template>`;
95
+
96
+ /**
97
+ * Default pagination for a list of results. Previous and Next step one page;
98
+ * page buttons jump directly. The current page is marked with `aria-current`.
99
+ */
100
+ export const Default: Story = {
101
+ render: (args) => ({
102
+ components: { UiPagination },
103
+ setup() {
104
+ const page = ref(args.page);
105
+ watch(
106
+ () => args.page,
107
+ (value) => {
108
+ page.value = value;
109
+ },
110
+ );
111
+ return { args, page, onPageChange };
112
+ },
113
+ template: `
114
+ <UiPagination
115
+ v-model:page="page"
116
+ :total="args.total"
117
+ :items-per-page="args.itemsPerPage"
118
+ :sibling-count="args.siblingCount"
119
+ :show-edges="args.showEdges"
120
+ :show-first-last="args.showFirstLast"
121
+ :disabled="args.disabled"
122
+ @update:page="onPageChange"
123
+ />
124
+ `,
125
+ }),
126
+ parameters: {
127
+ docs: {
128
+ source: {
129
+ code: defaultTemplateSource,
130
+ },
131
+ },
132
+ },
133
+ play: async ({ canvasElement, step }) => {
134
+ // Scenario (UiPagination): a user moves forward with Next, jumps to a page
135
+ // number, and steps back with Previous.
136
+ onPageChange.mockClear();
137
+ const canvas = within(canvasElement);
138
+ const previous = canvas.getByRole('button', { name: 'Previous page' });
139
+ const next = canvas.getByRole('button', { name: 'Next page' });
140
+
141
+ await step(
142
+ 'interaction: previous is disabled on the first page',
143
+ async () => {
144
+ await expect(previous).toBeDisabled();
145
+ await expect(
146
+ canvas.getByRole('button', { name: 'Page 1' }),
147
+ ).toHaveAttribute('aria-current', 'page');
148
+ },
149
+ );
150
+
151
+ await step('interaction: next advances one page', async () => {
152
+ await userEvent.click(next);
153
+ await expect(onPageChange).toHaveBeenLastCalledWith(2);
154
+ await expect(
155
+ canvas.getByRole('button', { name: 'Page 2' }),
156
+ ).toHaveAttribute('aria-current', 'page');
157
+ });
158
+
159
+ await step('interaction: a page button jumps to that page', async () => {
160
+ await userEvent.click(canvas.getByRole('button', { name: 'Page 3' }));
161
+ await expect(onPageChange).toHaveBeenLastCalledWith(3);
162
+ });
163
+
164
+ await step('interaction: previous steps back one page', async () => {
165
+ await userEvent.click(previous);
166
+ await expect(onPageChange).toHaveBeenLastCalledWith(2);
167
+ });
168
+ },
169
+ };
170
+
171
+ /**
172
+ * Design guidance for when and how to use pagination.
173
+ */
174
+ export const DesignNotes: Story = {
175
+ ...designNotesStory(guidance),
176
+ tags: ['!autodocs'],
177
+ };
178
+
179
+ /**
180
+ * Accessibility guidance for the landmark, current page, and labels.
181
+ */
182
+ export const Accessibility: Story = {
183
+ tags: ['!autodocs'],
184
+ parameters: {
185
+ surface: 'primary',
186
+ a11y: { test: 'off' },
187
+ chromatic: { disableSnapshot: true },
188
+ docs: {
189
+ canvas: {
190
+ sourceState: 'none',
191
+ },
192
+ },
193
+ },
194
+ render: () => ({
195
+ components: { UiPagination },
196
+ template: `
197
+ <section class="${guidanceSectionClass}">
198
+ <div>
199
+ <h2 class="heading-m font-bold text-content-on-surface-primary">
200
+ Accessibility
201
+ </h2>
202
+ </div>
203
+
204
+ ${accessibilityRequirementsTemplate(guidance.accessibility, 'Requirements')}
205
+
206
+ <div class="flex flex-col gap-6">
207
+ <div class="flex flex-col gap-2">
208
+ <h3 class="body-m-medium text-content-on-surface-primary">
209
+ The control is already a named landmark
210
+ </h3>
211
+ <p class="body-m-regular text-content-on-surface-primary">
212
+ <code>UiPagination</code> renders a <code>nav</code> labelled
213
+ "Pagination". When a page has more than one pagination control,
214
+ give each a distinct name through <code>labels.navigation</code>
215
+ (for example "Search results pages") so landmark navigation can
216
+ tell them apart.
217
+ </p>
218
+ </div>
219
+
220
+ <div class="flex flex-col gap-2">
221
+ <h3 class="body-m-medium text-content-on-surface-primary">
222
+ The current page is announced
223
+ </h3>
224
+ <p class="body-m-regular text-content-on-surface-primary">
225
+ The active page button carries <code>aria-current="page"</code>,
226
+ so screen readers announce it as the current page, not just the
227
+ page number (WCAG 4.1.2).
228
+ </p>
229
+ </div>
230
+
231
+ <div class="flex flex-col gap-2">
232
+ <h3 class="body-m-medium text-content-on-surface-primary">
233
+ Move focus after a page change
234
+ </h3>
235
+ <p class="body-m-regular text-content-on-surface-primary">
236
+ When new content loads, move focus to the heading or first item of
237
+ the updated content, or announce the change in a live region, so
238
+ screen-reader users know the page changed (WCAG 4.1.3).
239
+ </p>
240
+ </div>
241
+
242
+ <div class="flex flex-col gap-2">
243
+ <h3 class="body-m-medium text-content-on-surface-primary">
244
+ Translate labels together
245
+ </h3>
246
+ <p class="body-m-regular text-content-on-surface-primary">
247
+ Below the <code>sm</code> breakpoint Previous and Next show only
248
+ an icon and rely on their accessible names. When translating,
249
+ keep the visible word inside the accessible name, e.g. "Weiter"
250
+ and "Weiter zur nächsten Seite" (WCAG 2.5.3).
251
+ </p>
252
+ </div>
253
+
254
+ <div class="flex flex-col gap-2">
255
+ <h3 class="body-m-medium text-content-on-surface-primary">
256
+ Enable accessibility theme
257
+ </h3>
258
+ <p class="body-m-regular text-content-on-surface-primary">
259
+ When accessibility is required, enable our accessibility theme.
260
+ This increases contrast and makes sure there are no color
261
+ contrast issues.
262
+ </p>
263
+ </div>
264
+ </div>
265
+
266
+ <div class="grid gap-4 md:grid-cols-2">
267
+ <div class="flex flex-col gap-3">
268
+ <h3 class="label-m-medium text-center text-content-on-surface-primary">
269
+ Default
270
+ </h3>
271
+ <div class="flex min-h-20 items-center justify-center border border-border-surface-default p-6">
272
+ <UiPagination :page="1" :total="30" />
273
+ </div>
274
+ </div>
275
+
276
+ <div class="accessible-theme flex flex-col gap-3">
277
+ <h3 class="label-m-medium text-center text-content-on-surface-primary">
278
+ Accessible
279
+ </h3>
280
+ <div class="flex min-h-20 items-center justify-center border border-border-surface-default p-6">
281
+ <UiPagination :page="1" :total="30" />
282
+ </div>
283
+ </div>
284
+ </div>
285
+ </section>
286
+ `,
287
+ }),
288
+ };
289
+
290
+ const withContentTemplateSource = `<script setup lang="ts">
291
+ import { computed, ref } from 'vue'
292
+ import { UiPagination } from '@aleph-alpha/ui-library'
293
+
294
+ const items = Array.from({ length: 42 }, (_, i) => \`Result \${i + 1}\`)
295
+ const itemsPerPage = 5
296
+ const page = ref(1)
297
+
298
+ const visibleItems = computed(() =>
299
+ items.slice((page.value - 1) * itemsPerPage, page.value * itemsPerPage),
300
+ )
301
+ </script>
302
+
303
+ <template>
304
+ <div class="flex flex-col gap-4">
305
+ <ul class="flex flex-col gap-1 body-s-regular">
306
+ <li v-for="item in visibleItems" :key="item">{{ item }}</li>
307
+ </ul>
308
+ <UiPagination
309
+ v-model:page="page"
310
+ :total="items.length"
311
+ :items-per-page="itemsPerPage"
312
+ />
313
+ </div>
314
+ </template>`;
315
+
316
+ /**
317
+ * Pagination driving a list: slice your data with the bound `page` and
318
+ * `itemsPerPage`. Place the control directly below the content it controls.
319
+ */
320
+ export const WithContent: Story = {
321
+ render: () => ({
322
+ components: { UiPagination },
323
+ setup() {
324
+ const items = Array.from({ length: 42 }, (_, i) => `Result ${i + 1}`);
325
+ const itemsPerPage = 5;
326
+ const page = ref(1);
327
+ const visibleItems = computed(() =>
328
+ items.slice((page.value - 1) * itemsPerPage, page.value * itemsPerPage),
329
+ );
330
+ return { items, itemsPerPage, page, visibleItems };
331
+ },
332
+ template: `
333
+ <div class="flex flex-col gap-4">
334
+ <ul class="flex flex-col gap-1 body-s-regular text-content-on-surface-primary">
335
+ <li v-for="item in visibleItems" :key="item">{{ item }}</li>
336
+ </ul>
337
+ <UiPagination
338
+ v-model:page="page"
339
+ :total="items.length"
340
+ :items-per-page="itemsPerPage"
341
+ />
342
+ </div>
343
+ `,
344
+ }),
345
+ parameters: {
346
+ docs: {
347
+ source: {
348
+ code: withContentTemplateSource,
349
+ },
350
+ },
351
+ },
352
+ play: async ({ canvasElement, step }) => {
353
+ // Scenario (UiPagination): changing page swaps the visible slice of results.
354
+ const canvas = within(canvasElement);
355
+
356
+ await step('interaction: shows the first slice initially', async () => {
357
+ await expect(canvas.getByText('Result 1')).toBeInTheDocument();
358
+ await expect(canvas.queryByText('Result 6')).not.toBeInTheDocument();
359
+ });
360
+
361
+ await step('interaction: the last page shows the remainder', async () => {
362
+ await userEvent.click(canvas.getByRole('button', { name: 'Page 9' }));
363
+ await expect(canvas.getByText('Result 42')).toBeInTheDocument();
364
+ await expect(canvas.queryByText('Result 1')).not.toBeInTheDocument();
365
+ await expect(
366
+ canvas.getByRole('button', { name: 'Next page' }),
367
+ ).toBeDisabled();
368
+ });
369
+ },
370
+ };
371
+
372
+ const manyPagesTemplateSource = `<script setup lang="ts">
373
+ import { ref } from 'vue'
374
+ import { UiPagination } from '@aleph-alpha/ui-library'
375
+
376
+ const page = ref(10)
377
+ </script>
378
+
379
+ <template>
380
+ <UiPagination v-model:page="page" :total="500" />
381
+ </template>`;
382
+
383
+ /**
384
+ * Long sets collapse the skipped ranges into ellipses while keeping the first
385
+ * page, last page, and the current page with its siblings visible.
386
+ */
387
+ export const ManyPages: Story = {
388
+ render: () => ({
389
+ components: { UiPagination },
390
+ setup() {
391
+ const page = ref(10);
392
+ return { page };
393
+ },
394
+ template: `<UiPagination v-model:page="page" :total="500" />`,
395
+ }),
396
+ parameters: {
397
+ docs: {
398
+ source: {
399
+ code: manyPagesTemplateSource,
400
+ },
401
+ },
402
+ },
403
+ };
404
+
405
+ const withoutEdgesTemplateSource = `<script setup lang="ts">
406
+ import { ref } from 'vue'
407
+ import { UiPagination } from '@aleph-alpha/ui-library'
408
+
409
+ const page = ref(10)
410
+ </script>
411
+
412
+ <template>
413
+ <UiPagination v-model:page="page" :total="200" :show-edges="false" />
414
+ </template>`;
415
+
416
+ /**
417
+ * With `show-edges` off, only a window of pages around the current page is
418
+ * shown, without the first/last page numbers or ellipses. Pair it with
419
+ * `show-first-last` when users still need to reach either end.
420
+ */
421
+ export const WithoutEdges: Story = {
422
+ render: () => ({
423
+ components: { UiPagination },
424
+ setup() {
425
+ const page = ref(10);
426
+ return { page };
427
+ },
428
+ template: `<UiPagination v-model:page="page" :total="200" :show-edges="false" />`,
429
+ }),
430
+ parameters: {
431
+ docs: {
432
+ source: {
433
+ code: withoutEdgesTemplateSource,
434
+ },
435
+ },
436
+ },
437
+ play: async ({ canvasElement, step }) => {
438
+ // Scenario (UiPagination): without edges the row shows only the current
439
+ // page and its siblings, and the window slides as the user pages.
440
+ const canvas = within(canvasElement);
441
+
442
+ await step(
443
+ 'interaction: shows only the current page and its siblings',
444
+ async () => {
445
+ await expect(
446
+ canvas.getByRole('button', { name: 'Page 9' }),
447
+ ).toBeInTheDocument();
448
+ await expect(
449
+ canvas.getByRole('button', { name: 'Page 10' }),
450
+ ).toHaveAttribute('aria-current', 'page');
451
+ await expect(
452
+ canvas.getByRole('button', { name: 'Page 11' }),
453
+ ).toBeInTheDocument();
454
+ await expect(
455
+ canvas.queryByRole('button', { name: 'Page 1' }),
456
+ ).not.toBeInTheDocument();
457
+ await expect(
458
+ canvas.queryByRole('button', { name: 'Page 20' }),
459
+ ).not.toBeInTheDocument();
460
+ await expect(canvas.queryByText('More pages')).not.toBeInTheDocument();
461
+ },
462
+ );
463
+
464
+ await step('interaction: the window slides with the page', async () => {
465
+ await userEvent.click(canvas.getByRole('button', { name: 'Next page' }));
466
+ await expect(
467
+ canvas.getByRole('button', { name: 'Page 12' }),
468
+ ).toBeInTheDocument();
469
+ await expect(
470
+ canvas.queryByRole('button', { name: 'Page 9' }),
471
+ ).not.toBeInTheDocument();
472
+ });
473
+ },
474
+ };
475
+
476
+ const emptyTemplateSource = `<script setup lang="ts">
477
+ import { ref } from 'vue'
478
+ import { UiPagination } from '@aleph-alpha/ui-library'
479
+
480
+ const page = ref(1)
481
+ </script>
482
+
483
+ <template>
484
+ <UiPagination v-model:page="page" :total="0" />
485
+ </template>`;
486
+
487
+ /**
488
+ * With no items (`total` of 0) the control still renders a single current
489
+ * page with Previous and Next disabled, so the row keeps its position and
490
+ * width instead of disappearing while results load or after a filter.
491
+ */
492
+ export const Empty: Story = {
493
+ render: () => ({
494
+ components: { UiPagination },
495
+ setup() {
496
+ const page = ref(1);
497
+ return { page, onPageChange };
498
+ },
499
+ template: `<UiPagination v-model:page="page" :total="0" @update:page="onPageChange" />`,
500
+ }),
501
+ parameters: {
502
+ docs: {
503
+ source: {
504
+ code: emptyTemplateSource,
505
+ },
506
+ },
507
+ },
508
+ play: async ({ canvasElement, step }) => {
509
+ // Scenario (UiPagination): an empty set renders one current page and
510
+ // disables both directions, so nothing can page past it.
511
+ onPageChange.mockClear();
512
+ const canvas = within(canvasElement);
513
+ const previous = canvas.getByRole('button', { name: 'Previous page' });
514
+ const next = canvas.getByRole('button', { name: 'Next page' });
515
+
516
+ await step('interaction: renders a single current page', async () => {
517
+ const pages = canvas
518
+ .getAllByRole('button')
519
+ .filter((button) => button.dataset.type === 'page');
520
+ await expect(pages).toHaveLength(1);
521
+ await expect(
522
+ canvas.getByRole('button', { name: 'Page 1' }),
523
+ ).toHaveAttribute('aria-current', 'page');
524
+ });
525
+
526
+ await step(
527
+ 'interaction: previous and next are disabled, not removed',
528
+ async () => {
529
+ await expect(previous).toBeDisabled();
530
+ await expect(next).toBeDisabled();
531
+ },
532
+ );
533
+
534
+ await step('interaction: forced clicks do not change page', async () => {
535
+ await userEvent.click(next, { pointerEventsCheck: 0 });
536
+ await expect(onPageChange).not.toHaveBeenCalled();
537
+ });
538
+ },
539
+ };
540
+
541
+ const withFirstLastTemplateSource = `<script setup lang="ts">
542
+ import { ref } from 'vue'
543
+ import { UiPagination } from '@aleph-alpha/ui-library'
544
+
545
+ const page = ref(25)
546
+ </script>
547
+
548
+ <template>
549
+ <UiPagination v-model:page="page" :total="500" show-first-last />
550
+ </template>`;
551
+
552
+ /**
553
+ * Adds icon-only buttons that jump to the first and last page. Use for very
554
+ * long sets where users often need to reach either end.
555
+ */
556
+ export const WithFirstLast: Story = {
557
+ render: () => ({
558
+ components: { UiPagination },
559
+ setup() {
560
+ const page = ref(25);
561
+ return { page };
562
+ },
563
+ template: `<UiPagination v-model:page="page" :total="500" show-first-last />`,
564
+ }),
565
+ parameters: {
566
+ docs: {
567
+ source: {
568
+ code: withFirstLastTemplateSource,
569
+ },
570
+ },
571
+ },
572
+ play: async ({ canvasElement, step }) => {
573
+ // Scenario (UiPagination): the edge buttons jump straight to either end.
574
+ const canvas = within(canvasElement);
575
+
576
+ await step('interaction: last page button jumps to the end', async () => {
577
+ await userEvent.click(canvas.getByRole('button', { name: 'Last page' }));
578
+ await expect(
579
+ canvas.getByRole('button', { name: 'Page 50' }),
580
+ ).toHaveAttribute('aria-current', 'page');
581
+ await expect(
582
+ canvas.getByRole('button', { name: 'Last page' }),
583
+ ).toBeDisabled();
584
+ });
585
+
586
+ await step(
587
+ 'interaction: first page button jumps to the start',
588
+ async () => {
589
+ await userEvent.click(
590
+ canvas.getByRole('button', { name: 'First page' }),
591
+ );
592
+ await expect(
593
+ canvas.getByRole('button', { name: 'Page 1' }),
594
+ ).toHaveAttribute('aria-current', 'page');
595
+ },
596
+ );
597
+ },
598
+ };
599
+
600
+ const disabledTemplateSource = `<script setup lang="ts">
601
+ import { UiPagination } from '@aleph-alpha/ui-library'
602
+ </script>
603
+
604
+ <template>
605
+ <UiPagination :page="2" :total="50" disabled />
606
+ </template>`;
607
+
608
+ /**
609
+ * Disables every control, e.g. while the next page is loading. Disabled
610
+ * controls are skipped by keyboard navigation and ignore clicks.
611
+ */
612
+ export const Disabled: Story = {
613
+ render: () => ({
614
+ components: { UiPagination },
615
+ setup() {
616
+ return { onPageChange };
617
+ },
618
+ template: `<UiPagination :page="2" :total="50" disabled @update:page="onPageChange" />`,
619
+ }),
620
+ parameters: {
621
+ // Focus moves during the play function; skip the visual snapshot.
622
+ chromatic: { disableSnapshot: true },
623
+ docs: {
624
+ source: {
625
+ code: disabledTemplateSource,
626
+ },
627
+ },
628
+ },
629
+ play: async ({ canvasElement, step }) => {
630
+ // Scenario (UiPagination): a disabled pagination exposes its state, is
631
+ // skipped by Tab, and ignores forced clicks.
632
+ onPageChange.mockClear();
633
+ const canvas = within(canvasElement);
634
+ const buttons = canvas.getAllByRole('button');
635
+
636
+ await step(
637
+ 'interaction: every control exposes the disabled state (WCAG 4.1.2)',
638
+ async () => {
639
+ for (const button of buttons) {
640
+ await expect(button).toBeDisabled();
641
+ }
642
+ },
643
+ );
644
+
645
+ await step(
646
+ 'keyboard: disabled controls are removed from the tab order',
647
+ async () => {
648
+ await userEvent.tab();
649
+ for (const button of buttons) {
650
+ await expect(button).not.toHaveFocus();
651
+ }
652
+ },
653
+ );
654
+
655
+ await step('interaction: ignores forced clicks', async () => {
656
+ await userEvent.click(canvas.getByRole('button', { name: 'Page 3' }), {
657
+ pointerEventsCheck: 0,
658
+ });
659
+ await expect(onPageChange).not.toHaveBeenCalled();
660
+ });
661
+ },
662
+ };
663
+
664
+ const customLabelsTemplateSource = `<script setup lang="ts">
665
+ import { ref } from 'vue'
666
+ import { UiPagination } from '@aleph-alpha/ui-library'
667
+
668
+ const page = ref(1)
669
+
670
+ const labels = {
671
+ navigation: 'Seitennavigation',
672
+ previous: 'Zurück',
673
+ next: 'Weiter',
674
+ previousPage: 'Zurück zur vorherigen Seite',
675
+ nextPage: 'Weiter zur nächsten Seite',
676
+ firstPage: 'Erste Seite',
677
+ lastPage: 'Letzte Seite',
678
+ morePages: 'Weitere Seiten',
679
+ page: (n: number) => \`Seite \${n}\`,
680
+ }
681
+ </script>
682
+
683
+ <template>
684
+ <UiPagination v-model:page="page" :total="200" :labels="labels" show-first-last />
685
+ </template>`;
686
+
687
+ /**
688
+ * Translate every visible and screen-reader label through `labels`. Keep the
689
+ * visible word inside the matching accessible name (WCAG 2.5.3 Label in Name).
690
+ */
691
+ export const CustomLabels: Story = {
692
+ render: () => ({
693
+ components: { UiPagination },
694
+ setup() {
695
+ const page = ref(1);
696
+ const labels = {
697
+ navigation: 'Seitennavigation',
698
+ previous: 'Zurück',
699
+ next: 'Weiter',
700
+ previousPage: 'Zurück zur vorherigen Seite',
701
+ nextPage: 'Weiter zur nächsten Seite',
702
+ firstPage: 'Erste Seite',
703
+ lastPage: 'Letzte Seite',
704
+ morePages: 'Weitere Seiten',
705
+ page: (n: number) => `Seite ${n}`,
706
+ };
707
+ return { page, labels };
708
+ },
709
+ template: `<UiPagination v-model:page="page" :total="200" :labels="labels" show-first-last />`,
710
+ }),
711
+ parameters: {
712
+ docs: {
713
+ source: {
714
+ code: customLabelsTemplateSource,
715
+ },
716
+ },
717
+ },
718
+ };
719
+
720
+ const keyboardNavigationTemplateSource = `<script setup lang="ts">
721
+ import { ref } from 'vue'
722
+ import { UiPagination } from '@aleph-alpha/ui-library'
723
+
724
+ const page = ref(1)
725
+ </script>
726
+
727
+ <template>
728
+ <UiPagination v-model:page="page" :total="50" />
729
+ </template>`;
730
+
731
+ /**
732
+ * Every control is a native button: `Tab` moves through them in visual order
733
+ * and `Enter` or `Space` activates the focused one (WCAG 2.1.1, 2.4.3).
734
+ */
735
+ export const KeyboardNavigation: Story = {
736
+ name: 'test - Keyboard Navigation',
737
+ tags: ['!dev', '!autodocs'],
738
+ render: () => ({
739
+ components: { UiPagination },
740
+ setup() {
741
+ const page = ref(1);
742
+ return { page, onPageChange };
743
+ },
744
+ template: `<UiPagination v-model:page="page" :total="50" @update:page="onPageChange" />`,
745
+ }),
746
+ parameters: {
747
+ // Focus moves during the play function; skip the visual snapshot so the
748
+ // focus ring doesn't register as a Chromatic diff.
749
+ chromatic: { disableSnapshot: true },
750
+ docs: {
751
+ description: {
752
+ story:
753
+ 'Press `Tab` to move between the controls, then `Enter` or `Space` to change page.',
754
+ },
755
+ source: {
756
+ code: keyboardNavigationTemplateSource,
757
+ },
758
+ },
759
+ },
760
+ play: async ({ canvasElement, step }) => {
761
+ // Scenario (UiPagination): a keyboard user tabs past the disabled Previous
762
+ // button, through the page numbers, and changes page with Enter and Space.
763
+ onPageChange.mockClear();
764
+ const canvas = within(canvasElement);
765
+ const page1 = canvas.getByRole('button', { name: 'Page 1' });
766
+ const page2 = canvas.getByRole('button', { name: 'Page 2' });
767
+ const page3 = canvas.getByRole('button', { name: 'Page 3' });
768
+
769
+ await step(
770
+ 'keyboard: Tab skips the disabled Previous button and lands on page 1',
771
+ async () => {
772
+ await userEvent.tab();
773
+ await expect(page1).toHaveFocus();
774
+ },
775
+ );
776
+
777
+ await step(
778
+ 'keyboard: Tab moves through the pages in order (WCAG 2.4.3)',
779
+ async () => {
780
+ await userEvent.tab();
781
+ await expect(page2).toHaveFocus();
782
+ },
783
+ );
784
+
785
+ await step('keyboard: Enter activates the focused page', async () => {
786
+ await userEvent.keyboard('{Enter}');
787
+ await expect(onPageChange).toHaveBeenLastCalledWith(2);
788
+ await expect(page2).toHaveAttribute('aria-current', 'page');
789
+ await expect(page2).toHaveFocus();
790
+ });
791
+
792
+ await step('keyboard: Space activates the focused page', async () => {
793
+ await userEvent.tab();
794
+ await expect(page3).toHaveFocus();
795
+ await userEvent.keyboard(' ');
796
+ await expect(onPageChange).toHaveBeenLastCalledWith(3);
797
+ await expect(page3).toHaveAttribute('aria-current', 'page');
798
+ });
799
+
800
+ await step(
801
+ 'keyboard: Previous becomes reachable once it is enabled',
802
+ async () => {
803
+ const previous = canvas.getByRole('button', { name: 'Previous page' });
804
+ await expect(previous).toBeEnabled();
805
+ await userEvent.tab({ shift: true });
806
+ await userEvent.tab({ shift: true });
807
+ await userEvent.tab({ shift: true });
808
+ await expect(previous).toHaveFocus();
809
+ },
810
+ );
811
+ },
812
+ };
813
+
814
+ const zoomMagnificationTemplateSource = `<script setup lang="ts">
815
+ import { ref } from 'vue'
816
+ import { UiPagination } from '@aleph-alpha/ui-library'
817
+
818
+ const page = ref(5)
819
+ </script>
820
+
821
+ <template>
822
+ <UiPagination v-model:page="page" :total="200" />
823
+ </template>`;
824
+
825
+ /**
826
+ * Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
827
+ * try 400% reflow (WCAG 1.4.10); the controls wrap instead of overflowing.
828
+ */
829
+ export const ZoomMagnification: Story = {
830
+ name: 'test - Zoom Magnification',
831
+ tags: ['!dev', '!autodocs'],
832
+ globals: { zoom: '200' },
833
+ parameters: {
834
+ // Zoom changes the layout scale; the accessible-reflow Chromatic mode
835
+ // already covers magnified snapshots, so skip this one.
836
+ chromatic: { disableSnapshot: true },
837
+ docs: {
838
+ description: {
839
+ story:
840
+ 'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
841
+ },
842
+ source: {
843
+ code: zoomMagnificationTemplateSource,
844
+ },
845
+ },
846
+ },
847
+ render: () => ({
848
+ components: { UiPagination },
849
+ setup() {
850
+ const page = ref(5);
851
+ return { page, onPageChange };
852
+ },
853
+ template: `<UiPagination v-model:page="page" :total="200" @update:page="onPageChange" />`,
854
+ }),
855
+ play: async ({ canvasElement, step }) => {
856
+ // Scenario (UiPagination): at 200% zoom every control stays visible, keeps
857
+ // its accessible name, and remains operable.
858
+ onPageChange.mockClear();
859
+ const canvas = within(canvasElement);
860
+ const next = canvas.getByRole('button', { name: 'Next page' });
861
+
862
+ await step(
863
+ 'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
864
+ async () => {
865
+ await expect(document.documentElement.style.zoom).toBe('200%');
866
+ },
867
+ );
868
+
869
+ await step(
870
+ 'zoom: every control stays visible with its accessible name',
871
+ async () => {
872
+ for (const button of canvas.getAllByRole('button')) {
873
+ await expect(button).toBeVisible();
874
+ await expect(button.getAttribute('aria-label')).toBeTruthy();
875
+ }
876
+ },
877
+ );
878
+
879
+ await step('zoom: remains operable when magnified', async () => {
880
+ await userEvent.click(next);
881
+ await expect(onPageChange).toHaveBeenLastCalledWith(6);
882
+ });
883
+ },
884
+ };
885
+
886
+ const screenReaderTemplateSource = `<script setup lang="ts">
887
+ import { ref } from 'vue'
888
+ import { UiPagination } from '@aleph-alpha/ui-library'
889
+
890
+ const page = ref(10)
891
+ </script>
892
+
893
+ <template>
894
+ <UiPagination v-model:page="page" :total="200" />
895
+ </template>`;
896
+
897
+ /**
898
+ * Screen-reader semantics: a named navigation landmark, page buttons that name
899
+ * their page, `aria-current` on the active page, and ellipses that announce
900
+ * skipped pages (WCAG 1.3.1, 4.1.2).
901
+ */
902
+ export const ScreenReader: Story = {
903
+ name: 'test - Screen Reader',
904
+ tags: ['!dev', '!autodocs'],
905
+ parameters: {
906
+ // The current page changes during the play function.
907
+ chromatic: { disableSnapshot: true },
908
+ docs: {
909
+ description: {
910
+ story:
911
+ 'Verifies the landmark, names, and state that assistive technology announces.',
912
+ },
913
+ source: {
914
+ code: screenReaderTemplateSource,
915
+ },
916
+ },
917
+ },
918
+ render: () => ({
919
+ components: { UiPagination },
920
+ setup() {
921
+ const page = ref(10);
922
+ return { page };
923
+ },
924
+ template: `<UiPagination v-model:page="page" :total="200" />`,
925
+ }),
926
+ play: async ({ canvasElement, step }) => {
927
+ // Scenario (UiPagination): assistive tech finds the landmark, hears which
928
+ // page is current, and hears that ranges of pages were skipped.
929
+ const canvas = within(canvasElement);
930
+
931
+ await step(
932
+ 'screen-reader: exposes a navigation landmark named "Pagination"',
933
+ async () => {
934
+ await expect(
935
+ canvas.getByRole('navigation', { name: 'Pagination' }),
936
+ ).toBeInTheDocument();
937
+ },
938
+ );
939
+
940
+ await step(
941
+ 'screen-reader: pages are announced as a list of buttons',
942
+ async () => {
943
+ const list = canvas.getByRole('list');
944
+ await expect(
945
+ within(list).getAllByRole('listitem').length,
946
+ ).toBeGreaterThan(2);
947
+ },
948
+ );
949
+
950
+ await step(
951
+ 'screen-reader: the current page is announced via aria-current (WCAG 4.1.2)',
952
+ async () => {
953
+ const current = canvas.getByRole('button', { name: 'Page 10' });
954
+ await expect(current).toHaveAttribute('aria-current', 'page');
955
+ await expect(
956
+ canvas.getByRole('button', { name: 'Page 9' }),
957
+ ).not.toHaveAttribute('aria-current');
958
+ },
959
+ );
960
+
961
+ await step(
962
+ 'screen-reader: icon-only previous/next keep accessible names',
963
+ async () => {
964
+ await expect(
965
+ canvas.getByRole('button', { name: 'Previous page' }),
966
+ ).toBeInTheDocument();
967
+ await expect(
968
+ canvas.getByRole('button', { name: 'Next page' }),
969
+ ).toBeInTheDocument();
970
+ },
971
+ );
972
+
973
+ await step(
974
+ 'screen-reader: ellipses announce the skipped pages',
975
+ async () => {
976
+ await expect(canvas.getAllByText('More pages')).toHaveLength(2);
977
+ },
978
+ );
979
+
980
+ await step(
981
+ 'screen-reader: aria-current moves with the page change',
982
+ async () => {
983
+ await userEvent.click(canvas.getByRole('button', { name: 'Page 11' }));
984
+ await expect(
985
+ canvas.getByRole('button', { name: 'Page 11' }),
986
+ ).toHaveAttribute('aria-current', 'page');
987
+ await expect(
988
+ canvas.getByRole('button', { name: 'Page 10' }),
989
+ ).not.toHaveAttribute('aria-current');
990
+ },
991
+ );
992
+ },
993
+ };
994
+
995
+ const mobileBreakpointTemplateSource = `<script setup lang="ts">
996
+ import { ref } from 'vue'
997
+ import { UiPagination } from '@aleph-alpha/ui-library'
998
+
999
+ const page = ref(10)
1000
+ </script>
1001
+
1002
+ <template>
1003
+ <UiPagination v-model:page="page" :total="200" />
1004
+ </template>`;
1005
+
1006
+ /**
1007
+ * Rendered at the mobile (320px reflow) breakpoint. Previous and Next collapse
1008
+ * to icons, the controls wrap instead of scrolling sideways, and every target
1009
+ * stays at least 24px (WCAG 1.4.10, 2.5.8).
1010
+ */
1011
+ export const MobileBreakpoint: Story = {
1012
+ name: 'test - Mobile Breakpoint',
1013
+ tags: ['!dev', '!autodocs'],
1014
+ globals: { mediaBreakpoint: 'reflow' },
1015
+ parameters: {
1016
+ // Reflow snapshots are already covered by the accessible-reflow mode.
1017
+ chromatic: { disableSnapshot: true },
1018
+ docs: {
1019
+ description: {
1020
+ story:
1021
+ 'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
1022
+ },
1023
+ source: {
1024
+ code: mobileBreakpointTemplateSource,
1025
+ },
1026
+ },
1027
+ },
1028
+ render: () => ({
1029
+ components: { UiPagination },
1030
+ setup() {
1031
+ const page = ref(10);
1032
+ return { page, onPageChange };
1033
+ },
1034
+ template: `<UiPagination v-model:page="page" :total="200" @update:page="onPageChange" />`,
1035
+ }),
1036
+ play: async ({ canvasElement, step }) => {
1037
+ // Scenario (UiPagination): at 320px every control fits inside the viewport,
1038
+ // meets the touch-target size, and stays operable.
1039
+ onPageChange.mockClear();
1040
+ const canvas = within(canvasElement);
1041
+ const buttons = canvas.getAllByRole('button');
1042
+
1043
+ await step(
1044
+ 'mobile: no control overflows the 320px viewport (WCAG 1.4.10)',
1045
+ async () => {
1046
+ for (const button of buttons) {
1047
+ const { left, right } = button.getBoundingClientRect();
1048
+ await expect(left).toBeGreaterThanOrEqual(0);
1049
+ await expect(right).toBeLessThanOrEqual(window.innerWidth);
1050
+ }
1051
+ },
1052
+ );
1053
+
1054
+ await step(
1055
+ 'mobile: every control meets the minimum touch-target size (WCAG 2.5.8)',
1056
+ async () => {
1057
+ for (const button of buttons) {
1058
+ const { width, height } = button.getBoundingClientRect();
1059
+ await expect(width).toBeGreaterThanOrEqual(24);
1060
+ await expect(height).toBeGreaterThanOrEqual(24);
1061
+ }
1062
+ },
1063
+ );
1064
+
1065
+ await step('mobile: stays operable at the 320px breakpoint', async () => {
1066
+ await userEvent.click(canvas.getByRole('button', { name: 'Next page' }));
1067
+ await expect(onPageChange).toHaveBeenLastCalledWith(11);
1068
+ });
1069
+ },
1070
+ };