@aleph-alpha/ui-library 5.5.0 → 5.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/config.js +5 -0
  2. package/dist/system/components/UiAutocomplete/UiAutocomplete.vue.d.ts +2 -0
  3. package/dist/system/components/UiButtonGroup/UiButtonGroup.vue.d.ts +20 -0
  4. package/dist/system/components/UiButtonGroup/index.d.ts +2 -0
  5. package/dist/system/components/UiButtonGroup/types.d.ts +20 -0
  6. package/dist/system/components/UiField/types.d.ts +2 -1
  7. package/dist/system/components/core/button-group/ButtonGroup.vue.d.ts +23 -0
  8. package/dist/system/components/core/button-group/ButtonGroupSeparator.vue.d.ts +9 -0
  9. package/dist/system/components/core/button-group/ButtonGroupText.vue.d.ts +26 -0
  10. package/dist/system/components/core/button-group/index.d.ts +8 -0
  11. package/dist/system/components/index.d.ts +1 -0
  12. package/dist/system/lib.js +7855 -7732
  13. package/dist/system/story-sidebar-icons.json +3 -0
  14. package/package.json +5 -5
  15. package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +619 -0
  16. package/src/components/UiAutocomplete/UiAutocomplete.vue +28 -3
  17. package/src/components/UiAutocomplete/__tests__/UiAutocomplete.test.ts +14 -69
  18. package/src/components/UiButtonGroup/UiButtonGroup.stories.ts +690 -0
  19. package/src/components/UiButtonGroup/UiButtonGroup.vue +18 -0
  20. package/src/components/UiButtonGroup/__tests__/UiButtonGroup.test.ts +68 -0
  21. package/src/components/UiButtonGroup/index.ts +2 -0
  22. package/src/components/UiButtonGroup/types.ts +21 -0
  23. package/src/components/UiCheckbox/UiCheckbox.stories.ts +625 -74
  24. package/src/components/UiField/UiField.stories.ts +1 -1
  25. package/src/components/UiField/types.ts +2 -1
  26. package/src/components/UiRadioGroup/UiRadioGroup.stories.ts +995 -0
  27. package/src/components/UiSelect/UiSelect.stories.ts +769 -0
  28. package/src/components/UiSelect/__tests__/UiSelect.test.ts +4 -73
  29. package/src/components/UiSelect/__tests__/UiSelectItem.test.ts +3 -31
  30. package/src/components/UiSelect/__tests__/UiSelectTrigger.test.ts +14 -5
  31. package/src/components/core/button-group/ButtonGroup.vue +24 -0
  32. package/src/components/core/button-group/ButtonGroupSeparator.vue +29 -0
  33. package/src/components/core/button-group/ButtonGroupText.vue +33 -0
  34. package/src/components/core/button-group/index.ts +25 -0
  35. package/src/components/core/field/FieldDescription.vue +1 -1
  36. package/src/components/core/field/FieldLabel.vue +3 -2
  37. package/src/components/core/field/FieldTitle.vue +1 -1
  38. package/src/components/core/select/SelectTrigger.vue +1 -1
  39. package/src/components/index.ts +1 -0
  40. package/src/components/UiCheckbox/__tests__/UiCheckbox.test.ts +0 -14
  41. package/src/components/UiRadioGroup/__tests__/UiRadioGroup.test.ts +0 -412
@@ -0,0 +1,690 @@
1
+ import type { Meta, StoryObj } from '@storybook/vue3-vite';
2
+ import { expect, fn, userEvent, within } from 'storybook/test';
3
+ import UiButtonGroup from './UiButtonGroup.vue';
4
+ import { UiButton } from '../UiButton';
5
+ import { UiIcon } from '../UiIcon';
6
+ import { UiInput } from '../UiInput';
7
+
8
+ const onClick = fn();
9
+
10
+ /**
11
+ * `UiButtonGroup` visually joins a set of related actions into a single,
12
+ * connected control. It renders a `role="group"` container and merges the
13
+ * borders and radii of its children so they read as one unit.
14
+ */
15
+ const meta: Meta<typeof UiButtonGroup> = {
16
+ title: 'Components/UiButtonGroup',
17
+ component: UiButtonGroup,
18
+ tags: ['autodocs'],
19
+ argTypes: {
20
+ orientation: {
21
+ control: 'select',
22
+ options: ['horizontal', 'vertical'],
23
+ description: 'The layout direction of the grouped buttons',
24
+ },
25
+ },
26
+ args: {
27
+ orientation: 'horizontal',
28
+ },
29
+ };
30
+
31
+ export default meta;
32
+
33
+ type Story = StoryObj<typeof UiButtonGroup>;
34
+
35
+ const defaultTemplateSource = `<script setup lang="ts">
36
+ import { UiButtonGroup, UiButton } from '@aleph-alpha/ui-library'
37
+ </script>
38
+
39
+ <template>
40
+ <UiButtonGroup>
41
+ <UiButton variant="outline">Left</UiButton>
42
+ <UiButton variant="outline">Center</UiButton>
43
+ <UiButton variant="outline">Right</UiButton>
44
+ </UiButtonGroup>
45
+ </template>`;
46
+
47
+ /**
48
+ * A horizontal group of related actions.
49
+ */
50
+ export const Default: Story = {
51
+ render: (args) => ({
52
+ components: { UiButtonGroup, UiButton },
53
+ setup() {
54
+ return { args };
55
+ },
56
+ template: `
57
+ <UiButtonGroup :orientation="args.orientation">
58
+ <UiButton variant="outline">Left</UiButton>
59
+ <UiButton variant="outline">Center</UiButton>
60
+ <UiButton variant="outline">Right</UiButton>
61
+ </UiButtonGroup>
62
+ `,
63
+ }),
64
+ parameters: {
65
+ docs: {
66
+ source: {
67
+ code: defaultTemplateSource,
68
+ },
69
+ },
70
+ },
71
+ };
72
+
73
+ const verticalTemplateSource = `<script setup lang="ts">
74
+ import { UiButtonGroup, UiButton } from '@aleph-alpha/ui-library'
75
+ </script>
76
+
77
+ <template>
78
+ <UiButtonGroup orientation="vertical">
79
+ <UiButton variant="outline">Top</UiButton>
80
+ <UiButton variant="outline">Middle</UiButton>
81
+ <UiButton variant="outline">Bottom</UiButton>
82
+ </UiButtonGroup>
83
+ </template>`;
84
+
85
+ /**
86
+ * Set `orientation="vertical"` to stack the grouped buttons.
87
+ */
88
+ export const Vertical: Story = {
89
+ render: () => ({
90
+ components: { UiButtonGroup, UiButton },
91
+ template: `
92
+ <UiButtonGroup orientation="vertical">
93
+ <UiButton variant="outline">Top</UiButton>
94
+ <UiButton variant="outline">Middle</UiButton>
95
+ <UiButton variant="outline">Bottom</UiButton>
96
+ </UiButtonGroup>
97
+ `,
98
+ }),
99
+ parameters: {
100
+ docs: {
101
+ source: {
102
+ code: verticalTemplateSource,
103
+ },
104
+ },
105
+ },
106
+ };
107
+
108
+ const withInputTemplateSource = `<script setup lang="ts">
109
+ import { UiButtonGroup, UiButton, UiInput } from '@aleph-alpha/ui-library'
110
+ </script>
111
+
112
+ <template>
113
+ <div class="flex flex-col gap-6">
114
+ <UiButtonGroup>
115
+ <UiButton variant="outline">Button</UiButton>
116
+ <UiInput name="leading" placeholder="Type something" />
117
+ </UiButtonGroup>
118
+
119
+ <UiButtonGroup>
120
+ <UiButton variant="outline">Button</UiButton>
121
+ <UiInput name="both" placeholder="Type something" />
122
+ <UiButton variant="outline">Button</UiButton>
123
+ </UiButtonGroup>
124
+
125
+ <UiButtonGroup>
126
+ <UiInput name="trailing" placeholder="Type something" />
127
+ <UiButton variant="outline">Button</UiButton>
128
+ </UiButtonGroup>
129
+ </div>
130
+ </template>`;
131
+
132
+ /**
133
+ * `UiButtonGroup` can join `UiInput` fields with buttons to build search bars,
134
+ * prefixed/suffixed inputs, and other composite controls. The input grows to
135
+ * fill the remaining space while the borders and radii merge into one unit.
136
+ */
137
+ export const WithInput: Story = {
138
+ render: () => ({
139
+ components: { UiButtonGroup, UiButton, UiInput },
140
+ template: `
141
+ <div class="flex flex-col gap-6">
142
+ <UiButtonGroup>
143
+ <UiButton variant="outline">Button</UiButton>
144
+ <UiInput name="leading" placeholder="Type something" />
145
+ </UiButtonGroup>
146
+
147
+ <UiButtonGroup>
148
+ <UiButton variant="outline">Button</UiButton>
149
+ <UiInput name="both" placeholder="Type something" />
150
+ <UiButton variant="outline">Button</UiButton>
151
+ </UiButtonGroup>
152
+
153
+ <UiButtonGroup>
154
+ <UiInput name="trailing" placeholder="Type something" />
155
+ <UiButton variant="outline">Button</UiButton>
156
+ </UiButtonGroup>
157
+ </div>
158
+ `,
159
+ }),
160
+ parameters: {
161
+ docs: {
162
+ source: {
163
+ code: withInputTemplateSource,
164
+ },
165
+ },
166
+ },
167
+ };
168
+
169
+ const variantsTemplateSource = `<script setup lang="ts">
170
+ import { UiButtonGroup, UiButton, UiIcon } from '@aleph-alpha/ui-library'
171
+
172
+ const variants = ['default', 'outline', 'secondary'] as const
173
+ const labels = ['One', 'Two', 'Three', 'Four', 'Five']
174
+
175
+ // Trailing image icon; the button keeps its text label as the accessible name.
176
+ const ImageIcon = {
177
+ components: { UiIcon },
178
+ template: '<UiIcon name="image" :size="16" />',
179
+ }
180
+ </script>
181
+
182
+ <template>
183
+ <div class="flex flex-col gap-10">
184
+ <div v-for="orientation in ['horizontal', 'vertical']" :key="orientation" class="flex flex-col gap-4">
185
+ <h3 class="body-14-medium capitalize">{{ orientation }}</h3>
186
+ <div class="flex flex-wrap items-start gap-6">
187
+ <UiButtonGroup v-for="variant in variants" :key="variant" :orientation="orientation">
188
+ <UiButton
189
+ v-for="(label, index) in labels"
190
+ :key="label"
191
+ :variant="variant"
192
+ :end-icon="index === labels.length - 1 ? ImageIcon : undefined"
193
+ >
194
+ {{ label }}
195
+ </UiButton>
196
+ </UiButtonGroup>
197
+ </div>
198
+ </div>
199
+ </div>
200
+ </template>`;
201
+
202
+ const VARIANTS = ['default', 'outline', 'secondary'] as const;
203
+ const ORIENTATIONS = ['horizontal', 'vertical'] as const;
204
+ const LABELS = ['One', 'Two', 'Three', 'Four', 'Five'] as const;
205
+
206
+ /**
207
+ * Trailing image icon rendered via `UiButton`'s `endIcon` prop, so the button
208
+ * keeps its visible text label as its accessible name.
209
+ */
210
+ const ImageIcon = {
211
+ components: { UiIcon },
212
+ template: '<UiIcon name="image" :size="16" />',
213
+ };
214
+
215
+ /**
216
+ * Groups of five buttons shown for the `default`, `outline`, and `secondary`
217
+ * variants in both horizontal and vertical orientations. The last button in
218
+ * each group carries a trailing image icon.
219
+ */
220
+ export const Variants: Story = {
221
+ render: () => ({
222
+ components: { UiButtonGroup, UiButton },
223
+ setup() {
224
+ return {
225
+ variants: VARIANTS,
226
+ orientations: ORIENTATIONS,
227
+ labels: LABELS,
228
+ ImageIcon,
229
+ };
230
+ },
231
+ template: `
232
+ <div class="flex flex-col gap-10">
233
+ <div
234
+ v-for="orientation in orientations"
235
+ :key="orientation"
236
+ class="flex flex-col gap-4"
237
+ >
238
+ <h3 class="body-14-medium capitalize text-content-on-surface-primary">
239
+ {{ orientation }}
240
+ </h3>
241
+ <div class="flex flex-wrap items-start gap-6">
242
+ <UiButtonGroup
243
+ v-for="variant in variants"
244
+ :key="variant"
245
+ :orientation="orientation"
246
+ >
247
+ <UiButton
248
+ v-for="(label, index) in labels"
249
+ :key="label"
250
+ :variant="variant"
251
+ :end-icon="index === labels.length - 1 ? ImageIcon : undefined"
252
+ >
253
+ {{ label }}
254
+ </UiButton>
255
+ </UiButtonGroup>
256
+ </div>
257
+ </div>
258
+ </div>
259
+ `,
260
+ }),
261
+ parameters: {
262
+ docs: {
263
+ source: {
264
+ code: variantsTemplateSource,
265
+ },
266
+ },
267
+ },
268
+ };
269
+
270
+ const sizesTemplateSource = `<script setup lang="ts">
271
+ import { UiButtonGroup, UiButton } from '@aleph-alpha/ui-library'
272
+
273
+ const sizes = ['sm', 'default', 'lg'] as const
274
+ const labels = ['One', 'Two', 'Three', 'Four', 'Five']
275
+ </script>
276
+
277
+ <template>
278
+ <div class="flex flex-col gap-6">
279
+ <UiButtonGroup v-for="size in sizes" :key="size">
280
+ <UiButton v-for="label in labels" :key="label" variant="outline" :size="size">
281
+ {{ label }}
282
+ </UiButton>
283
+ </UiButtonGroup>
284
+ </div>
285
+ </template>`;
286
+
287
+ const SIZES = ['sm', 'default', 'lg'] as const;
288
+
289
+ /**
290
+ * Groups of five `outline` buttons, one row per size (`sm`, `default`, `lg`).
291
+ */
292
+ export const Sizes: Story = {
293
+ render: () => ({
294
+ components: { UiButtonGroup, UiButton },
295
+ setup() {
296
+ return { sizes: SIZES, labels: LABELS };
297
+ },
298
+ template: `
299
+ <div class="flex flex-col gap-6">
300
+ <UiButtonGroup v-for="size in sizes" :key="size">
301
+ <UiButton
302
+ v-for="label in labels"
303
+ :key="label"
304
+ variant="outline"
305
+ :size="size"
306
+ >
307
+ {{ label }}
308
+ </UiButton>
309
+ </UiButtonGroup>
310
+ </div>
311
+ `,
312
+ }),
313
+ parameters: {
314
+ docs: {
315
+ source: {
316
+ code: sizesTemplateSource,
317
+ },
318
+ },
319
+ },
320
+ };
321
+
322
+ /**
323
+ * Accessibility guidance for labelling groups and keyboard use.
324
+ */
325
+ export const Accessibility: Story = {
326
+ render: () => ({
327
+ components: { UiButtonGroup, UiButton, UiIcon },
328
+ template: `
329
+ <section class="flex flex-col gap-6 p-4">
330
+ <div>
331
+ <h2 class="heading-m font-bold text-content-on-surface-primary">
332
+ Accessibility
333
+ </h2>
334
+ </div>
335
+
336
+ <div class="flex flex-col gap-6">
337
+ <div class="flex flex-col gap-2">
338
+ <h3 class="body-16-medium text-content-on-surface-primary">
339
+ Give the group an accessible name
340
+ </h3>
341
+ <p class="body-16-regular text-content-on-surface-primary">
342
+ <code>UiButtonGroup</code> renders a <code>role="group"</code>.
343
+ For toolbars or segmented controls, add an <code>aria-label</code>
344
+ so screen-reader users know what the buttons share. Icon-only
345
+ buttons still need their own <code>aria-label</code>.
346
+ </p>
347
+ </div>
348
+
349
+ <div class="flex flex-col gap-2">
350
+ <h3 class="body-16-medium text-content-on-surface-primary">
351
+ Keyboard operability
352
+ </h3>
353
+ <p class="body-16-regular text-content-on-surface-primary">
354
+ Each button is a normal tab stop: <code>Tab</code> moves between
355
+ them in DOM order and <code>Enter</code>/<code>Space</code>
356
+ activates the focused one.
357
+ </p>
358
+ </div>
359
+ </div>
360
+
361
+ <UiButtonGroup aria-label="Text alignment">
362
+ <UiButton variant="outline" size="icon-sm" aria-label="Align left">
363
+ <UiIcon name="align-left" :size="16" />
364
+ </UiButton>
365
+ <UiButton variant="outline" size="icon-sm" aria-label="Align center">
366
+ <UiIcon name="align-center" :size="16" />
367
+ </UiButton>
368
+ <UiButton variant="outline" size="icon-sm" aria-label="Align right">
369
+ <UiIcon name="align-right" :size="16" />
370
+ </UiButton>
371
+ </UiButtonGroup>
372
+ </section>
373
+ `,
374
+ }),
375
+ tags: ['!autodocs'],
376
+ parameters: {
377
+ a11y: { test: 'off' },
378
+ chromatic: {
379
+ disableSnapshot: true,
380
+ },
381
+ docs: {
382
+ canvas: {
383
+ sourceState: 'none',
384
+ },
385
+ },
386
+ },
387
+ };
388
+
389
+ const keyboardNavigationTemplateSource = `<script setup lang="ts">
390
+ import { UiButtonGroup, UiButton } from '@aleph-alpha/ui-library'
391
+ </script>
392
+
393
+ <template>
394
+ <UiButtonGroup>
395
+ <UiButton variant="outline">Previous</UiButton>
396
+ <UiButton>Play</UiButton>
397
+ <UiButton variant="outline">Next</UiButton>
398
+ </UiButtonGroup>
399
+ </template>`;
400
+
401
+ /**
402
+ * The group exposes `role="group"` and its buttons are reachable with `Tab` in
403
+ * DOM order, activating with `Space` (WCAG 2.1.1, 2.4.3).
404
+ */
405
+ export const KeyboardNavigation: Story = {
406
+ name: 'test - Keyboard Navigation',
407
+ tags: ['!dev', '!autodocs'],
408
+ parameters: {
409
+ chromatic: { disableSnapshot: true },
410
+ docs: {
411
+ description: {
412
+ story:
413
+ 'Tab between the grouped buttons in DOM order, then press Space to activate the focused one.',
414
+ },
415
+ source: {
416
+ code: keyboardNavigationTemplateSource,
417
+ },
418
+ },
419
+ },
420
+ render: () => ({
421
+ components: { UiButtonGroup, UiButton },
422
+ setup() {
423
+ return { onClick };
424
+ },
425
+ template: `
426
+ <UiButtonGroup>
427
+ <UiButton variant="outline" @click="onClick">Previous</UiButton>
428
+ <UiButton @click="onClick">Play</UiButton>
429
+ <UiButton variant="outline" @click="onClick">Next</UiButton>
430
+ </UiButtonGroup>
431
+ `,
432
+ }),
433
+ play: async ({ canvasElement, step }) => {
434
+ // Scenario (UiButtonGroup): a keyboard user tabs across the grouped buttons in DOM
435
+ // order and activates the focused control with Space.
436
+ onClick.mockClear();
437
+ const canvas = within(canvasElement);
438
+ const group = canvas.getByRole('group');
439
+ const previous = canvas.getByRole('button', { name: 'Previous' });
440
+ const play = canvas.getByRole('button', { name: 'Play' });
441
+ const next = canvas.getByRole('button', { name: 'Next' });
442
+
443
+ await step('interaction: exposes a group role', async () => {
444
+ await expect(group).toBeInTheDocument();
445
+ });
446
+
447
+ await step(
448
+ 'keyboard: Tab enters the group and focuses the first control',
449
+ async () => {
450
+ await userEvent.tab();
451
+ await expect(previous).toHaveFocus();
452
+ },
453
+ );
454
+
455
+ await step(
456
+ 'keyboard: Tab moves focus through the group in order (WCAG 2.4.3)',
457
+ async () => {
458
+ await userEvent.tab();
459
+ await expect(play).toHaveFocus();
460
+ await userEvent.tab();
461
+ await expect(next).toHaveFocus();
462
+ },
463
+ );
464
+
465
+ await step(
466
+ 'keyboard: Space activates the focused control (WCAG 2.1.1)',
467
+ async () => {
468
+ await userEvent.keyboard(' ');
469
+ await expect(onClick).toHaveBeenCalledTimes(1);
470
+ },
471
+ );
472
+ },
473
+ };
474
+
475
+ const screenReaderTemplateSource = `<script setup lang="ts">
476
+ import { UiButtonGroup, UiButton } from '@aleph-alpha/ui-library'
477
+ </script>
478
+
479
+ <template>
480
+ <UiButtonGroup aria-label="Text alignment">
481
+ <UiButton variant="outline">Left</UiButton>
482
+ <UiButton variant="outline">Center</UiButton>
483
+ <UiButton variant="outline">Right</UiButton>
484
+ </UiButtonGroup>
485
+ </template>`;
486
+
487
+ /**
488
+ * Screen-reader semantics: the container exposes a `group` role with an
489
+ * accessible name (via `aria-label`), and every child button exposes its own
490
+ * role and name (WCAG 4.1.2 Name, Role, Value).
491
+ */
492
+ export const ScreenReader: Story = {
493
+ name: 'test - Screen Reader',
494
+ tags: ['!dev', '!autodocs'],
495
+ parameters: {
496
+ chromatic: { disableSnapshot: true },
497
+ docs: {
498
+ description: {
499
+ story:
500
+ 'Verifies the group role/name and the roles and names of the buttons that assistive technology announces.',
501
+ },
502
+ source: {
503
+ code: screenReaderTemplateSource,
504
+ },
505
+ },
506
+ },
507
+ render: () => ({
508
+ components: { UiButtonGroup, UiButton },
509
+ template: `
510
+ <UiButtonGroup aria-label="Text alignment">
511
+ <UiButton variant="outline">Left</UiButton>
512
+ <UiButton variant="outline">Center</UiButton>
513
+ <UiButton variant="outline">Right</UiButton>
514
+ </UiButtonGroup>
515
+ `,
516
+ }),
517
+ play: async ({ canvasElement, step }) => {
518
+ // Scenario (UiButtonGroup): assistive tech reads the group's role and name, then each
519
+ // child button's role and name.
520
+ const canvas = within(canvasElement);
521
+
522
+ await step(
523
+ 'screen-reader: exposes a group role with an accessible name (WCAG 4.1.2)',
524
+ async () => {
525
+ const group = canvas.getByRole('group', { name: 'Text alignment' });
526
+ await expect(group).toHaveAccessibleName('Text alignment');
527
+ },
528
+ );
529
+
530
+ await step(
531
+ 'screen-reader: each child exposes a button role with its name',
532
+ async () => {
533
+ await expect(
534
+ canvas.getByRole('button', { name: 'Left' }),
535
+ ).toBeInTheDocument();
536
+ await expect(
537
+ canvas.getByRole('button', { name: 'Center' }),
538
+ ).toBeInTheDocument();
539
+ await expect(
540
+ canvas.getByRole('button', { name: 'Right' }),
541
+ ).toBeInTheDocument();
542
+ },
543
+ );
544
+ },
545
+ };
546
+
547
+ const zoomMagnificationTemplateSource = `<script setup lang="ts">
548
+ import { UiButtonGroup, UiButton } from '@aleph-alpha/ui-library'
549
+ </script>
550
+
551
+ <template>
552
+ <UiButtonGroup aria-label="Text alignment">
553
+ <UiButton variant="outline">Left</UiButton>
554
+ <UiButton variant="outline">Center</UiButton>
555
+ <UiButton variant="outline">Right</UiButton>
556
+ </UiButtonGroup>
557
+ </template>`;
558
+
559
+ /**
560
+ * Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
561
+ * try 400% reflow (WCAG 1.4.10); the group must stay visible and operable.
562
+ */
563
+ export const ZoomMagnification: Story = {
564
+ name: 'test - Zoom Magnification',
565
+ tags: ['!dev', '!autodocs'],
566
+ globals: { zoom: '200' },
567
+ parameters: {
568
+ chromatic: { disableSnapshot: true },
569
+ docs: {
570
+ description: {
571
+ story:
572
+ 'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
573
+ },
574
+ source: {
575
+ code: zoomMagnificationTemplateSource,
576
+ },
577
+ },
578
+ },
579
+ render: () => ({
580
+ components: { UiButtonGroup, UiButton },
581
+ setup() {
582
+ return { onClick };
583
+ },
584
+ template: `
585
+ <UiButtonGroup aria-label="Text alignment">
586
+ <UiButton variant="outline" @click="onClick">Left</UiButton>
587
+ <UiButton variant="outline">Center</UiButton>
588
+ <UiButton variant="outline">Right</UiButton>
589
+ </UiButtonGroup>
590
+ `,
591
+ }),
592
+ play: async ({ canvasElement, step }) => {
593
+ // Scenario (UiButtonGroup): at 200% page zoom the group stays visible, keeps its
594
+ // structure, and remains operable.
595
+ onClick.mockClear();
596
+ const canvas = within(canvasElement);
597
+ const group = canvas.getByRole('group', { name: 'Text alignment' });
598
+ const left = canvas.getByRole('button', { name: 'Left' });
599
+
600
+ await step(
601
+ 'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
602
+ async () => {
603
+ await expect(document.documentElement.style.zoom).toBe('200%');
604
+ },
605
+ );
606
+
607
+ await step('zoom: group stays visible when magnified', async () => {
608
+ await expect(group).toBeVisible();
609
+ await expect(left).toBeVisible();
610
+ });
611
+
612
+ await step('zoom: remains operable when magnified', async () => {
613
+ await userEvent.click(left);
614
+ await expect(onClick).toHaveBeenCalledTimes(1);
615
+ });
616
+ },
617
+ };
618
+
619
+ const mobileBreakpointTemplateSource = `<script setup lang="ts">
620
+ import { UiButtonGroup, UiButton } from '@aleph-alpha/ui-library'
621
+ </script>
622
+
623
+ <template>
624
+ <UiButtonGroup aria-label="Text alignment">
625
+ <UiButton variant="outline">Left</UiButton>
626
+ <UiButton variant="outline">Center</UiButton>
627
+ <UiButton variant="outline">Right</UiButton>
628
+ </UiButtonGroup>
629
+ </template>`;
630
+
631
+ /**
632
+ * Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
633
+ * toolbar. Stays operable and each control meets the minimum touch-target size
634
+ * (WCAG 1.4.10 Reflow, 2.5.8 Target Size (Minimum)).
635
+ */
636
+ export const MobileBreakpoint: Story = {
637
+ name: 'test - Mobile Breakpoint',
638
+ tags: ['!dev', '!autodocs'],
639
+ globals: { mediaBreakpoint: 'reflow' },
640
+ parameters: {
641
+ chromatic: { disableSnapshot: true },
642
+ docs: {
643
+ description: {
644
+ story:
645
+ 'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
646
+ },
647
+ source: {
648
+ code: mobileBreakpointTemplateSource,
649
+ },
650
+ },
651
+ },
652
+ render: () => ({
653
+ components: { UiButtonGroup, UiButton },
654
+ setup() {
655
+ return { onClick };
656
+ },
657
+ template: `
658
+ <UiButtonGroup aria-label="Text alignment">
659
+ <UiButton variant="outline" @click="onClick">Left</UiButton>
660
+ <UiButton variant="outline">Center</UiButton>
661
+ <UiButton variant="outline">Right</UiButton>
662
+ </UiButtonGroup>
663
+ `,
664
+ }),
665
+ play: async ({ canvasElement, step }) => {
666
+ // Scenario (UiButtonGroup): at the 320px mobile breakpoint the group stays operable and
667
+ // each button meets the minimum touch-target size.
668
+ onClick.mockClear();
669
+ const canvas = within(canvasElement);
670
+ const left = canvas.getByRole('button', { name: 'Left' });
671
+
672
+ await step(
673
+ 'mobile: renders and stays operable at the 320px breakpoint (WCAG 1.4.10)',
674
+ async () => {
675
+ await expect(left).toBeVisible();
676
+ await userEvent.click(left);
677
+ await expect(onClick).toHaveBeenCalledTimes(1);
678
+ },
679
+ );
680
+
681
+ await step(
682
+ 'mobile: each control meets the minimum touch-target size (WCAG 2.5.8)',
683
+ async () => {
684
+ const { width, height } = left.getBoundingClientRect();
685
+ await expect(width).toBeGreaterThanOrEqual(24);
686
+ await expect(height).toBeGreaterThanOrEqual(24);
687
+ },
688
+ );
689
+ },
690
+ };
@@ -0,0 +1,18 @@
1
+ <script setup lang="ts">
2
+ import { ButtonGroup as ShadcnButtonGroup } from '@/components/core/button-group';
3
+ import type { UiButtonGroupProps } from './types';
4
+
5
+ defineOptions({
6
+ name: 'UiButtonGroup',
7
+ });
8
+
9
+ withDefaults(defineProps<UiButtonGroupProps>(), {
10
+ orientation: 'horizontal',
11
+ });
12
+ </script>
13
+
14
+ <template>
15
+ <ShadcnButtonGroup :orientation="orientation">
16
+ <slot />
17
+ </ShadcnButtonGroup>
18
+ </template>