@aleph-alpha/ui-library 5.4.0 → 5.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/config.d.ts +9 -0
  2. package/config.js +12 -3
  3. package/dist/system/components/UiAutocomplete/UiAutocomplete.vue.d.ts +2 -0
  4. package/dist/system/components/UiButtonGroup/UiButtonGroup.vue.d.ts +20 -0
  5. package/dist/system/components/UiButtonGroup/index.d.ts +2 -0
  6. package/dist/system/components/UiButtonGroup/types.d.ts +20 -0
  7. package/dist/system/components/core/button-group/ButtonGroup.vue.d.ts +23 -0
  8. package/dist/system/components/core/button-group/ButtonGroupSeparator.vue.d.ts +9 -0
  9. package/dist/system/components/core/button-group/ButtonGroupText.vue.d.ts +26 -0
  10. package/dist/system/components/core/button-group/index.d.ts +8 -0
  11. package/dist/system/components/index.d.ts +1 -0
  12. package/dist/system/lib.js +8878 -8692
  13. package/dist/system/patterns/UiFloatActions/UiFloatActionItems.vue.d.ts +173 -2
  14. package/dist/system/patterns/UiFloatActions/floatActionItemContext.d.ts +15 -1
  15. package/dist/system/patterns/UiFloatActions/types.d.ts +25 -1
  16. package/dist/system/story-sidebar-icons.json +8 -1
  17. package/package.json +5 -3
  18. package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +620 -0
  19. package/src/components/UiAutocomplete/UiAutocomplete.vue +28 -3
  20. package/src/components/UiAutocomplete/__tests__/UiAutocomplete.test.ts +14 -69
  21. package/src/components/UiButton/UiButton.stories.ts +9 -9
  22. package/src/components/UiButtonGroup/UiButtonGroup.stories.ts +690 -0
  23. package/src/components/UiButtonGroup/UiButtonGroup.vue +18 -0
  24. package/src/components/UiButtonGroup/__tests__/UiButtonGroup.test.ts +68 -0
  25. package/src/components/UiButtonGroup/index.ts +2 -0
  26. package/src/components/UiButtonGroup/types.ts +21 -0
  27. package/src/components/UiCheckbox/UiCheckbox.stories.ts +253 -0
  28. package/src/components/UiCheckbox/__tests__/UiCheckbox.test.ts +3 -18
  29. package/src/components/UiField/UiField.stories.ts +608 -1
  30. package/src/components/UiField/UiFieldDescription.vue +7 -2
  31. package/src/components/UiInput/UiInput.stories.ts +336 -2
  32. package/src/components/UiInput/__tests__/UiInput.test.ts +20 -28
  33. package/src/components/UiItem/UiItem.stories.ts +236 -1
  34. package/src/components/UiItem/__tests__/UiItem.test.ts +11 -72
  35. package/src/components/UiSelect/UiSelect.stories.ts +769 -0
  36. package/src/components/UiSelect/__tests__/UiSelect.test.ts +4 -73
  37. package/src/components/UiSelect/__tests__/UiSelectItem.test.ts +3 -31
  38. package/src/components/UiSelect/__tests__/UiSelectTrigger.test.ts +14 -5
  39. package/src/components/UiSnackbar/UiSnackbar.stories.ts +6 -6
  40. package/src/components/UiSnackbar/UiSnackbar.vue +4 -4
  41. package/src/components/UiSnackbar/UiSnackbarContent.vue +4 -4
  42. package/src/components/core/button-group/ButtonGroup.vue +24 -0
  43. package/src/components/core/button-group/ButtonGroupSeparator.vue +29 -0
  44. package/src/components/core/button-group/ButtonGroupText.vue +33 -0
  45. package/src/components/core/button-group/index.ts +25 -0
  46. package/src/components/core/checkbox/Checkbox.vue +0 -1
  47. package/src/components/core/select/SelectTrigger.vue +1 -1
  48. package/src/components/core/tabs/TabsTrigger.vue +1 -1
  49. package/src/components/index.ts +1 -0
  50. package/src/patterns/UiDataTable/UiDataTable.stories.ts +495 -8
  51. package/src/patterns/UiDataTable/UiDataTableFilterMenu.vue +1 -1
  52. package/src/patterns/UiDataTable/__tests__/UiDataTable.test.ts +7 -184
  53. package/src/patterns/UiFloatActions/UiFloatActionItems.vue +138 -11
  54. package/src/patterns/UiFloatActions/UiFloatActions.stories.ts +890 -3
  55. package/src/patterns/UiFloatActions/__tests__/UiFloatActionItems.test.ts +46 -24
  56. package/src/patterns/UiFloatActions/floatActionItemContext.ts +16 -1
  57. package/src/patterns/UiFloatActions/types.ts +28 -1
  58. package/src/components/UiField/__tests__/UiFieldError.test.ts +0 -39
  59. package/src/patterns/UiFloatActions/__tests__/UiFloatActions.a11y.test.ts +0 -152
@@ -0,0 +1,68 @@
1
+ import { render } from '@testing-library/vue';
2
+ import { describe, expect, test } from 'vitest';
3
+ import UiButtonGroup from '../UiButtonGroup.vue';
4
+
5
+ describe('UiButtonGroup', () => {
6
+ test('renders as a group with slot content', () => {
7
+ const { getByRole } = render(UiButtonGroup, {
8
+ slots: { default: '<button type="button">Click me</button>' },
9
+ });
10
+ const group = getByRole('group');
11
+ expect(group).toBeInTheDocument();
12
+ expect(group).toHaveTextContent('Click me');
13
+ });
14
+
15
+ test('defaults to horizontal orientation', () => {
16
+ const { getByRole } = render(UiButtonGroup, {
17
+ slots: { default: '<button type="button">Button</button>' },
18
+ });
19
+ expect(getByRole('group')).toHaveAttribute(
20
+ 'data-orientation',
21
+ 'horizontal',
22
+ );
23
+ });
24
+
25
+ describe('Orientation (contract test)', () => {
26
+ const orientations = ['horizontal', 'vertical'] as const;
27
+
28
+ test.each(orientations)('accepts orientation="%s"', (orientation) => {
29
+ const { getByRole } = render(UiButtonGroup, {
30
+ props: { orientation },
31
+ slots: { default: '<button type="button">Button</button>' },
32
+ });
33
+ expect(getByRole('group')).toHaveAttribute(
34
+ 'data-orientation',
35
+ orientation,
36
+ );
37
+ });
38
+ });
39
+
40
+ test('renders multiple children', () => {
41
+ const { getAllByRole } = render(UiButtonGroup, {
42
+ slots: {
43
+ default: `
44
+ <button type="button">One</button>
45
+ <button type="button">Two</button>
46
+ <button type="button">Three</button>
47
+ `,
48
+ },
49
+ });
50
+ expect(getAllByRole('button')).toHaveLength(3);
51
+ });
52
+
53
+ test('forwards a custom class to the group container', () => {
54
+ const { getByRole } = render(UiButtonGroup, {
55
+ attrs: { class: 'custom-class' },
56
+ slots: { default: '<button type="button">Button</button>' },
57
+ });
58
+ expect(getByRole('group')).toHaveClass('custom-class');
59
+ });
60
+
61
+ test('forwards aria-label to the group container for an accessible name', () => {
62
+ const { getByRole } = render(UiButtonGroup, {
63
+ attrs: { 'aria-label': 'Text alignment' },
64
+ slots: { default: '<button type="button">Left</button>' },
65
+ });
66
+ expect(getByRole('group')).toHaveAccessibleName('Text alignment');
67
+ });
68
+ });
@@ -0,0 +1,2 @@
1
+ export { default as UiButtonGroup } from './UiButtonGroup.vue';
2
+ export type { UiButtonGroupProps, UiButtonGroupOrientation } from './types';
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Layout direction for the buttons inside a `UiButtonGroup`.
3
+ */
4
+ export type UiButtonGroupOrientation = 'horizontal' | 'vertical';
5
+
6
+ /**
7
+ * Visually joins a set of related actions (and inputs) into a single, connected
8
+ * control. Renders a `role="group"` container and merges the borders and radii
9
+ * of its children so they read as one unit.
10
+ * @category Actions
11
+ * @useCases toolbar, segmented actions, split button, input with buttons, pagination controls
12
+ * @keywords button group, group, toolbar, segmented, joined, split button
13
+ * @related UiButton, UiInput
14
+ */
15
+ export interface UiButtonGroupProps {
16
+ /**
17
+ * The layout direction of the grouped buttons.
18
+ * @default 'horizontal'
19
+ */
20
+ orientation?: UiButtonGroupOrientation;
21
+ }
@@ -1,4 +1,5 @@
1
1
  import type { Meta, StoryObj } from '@storybook/vue3-vite';
2
+ import { expect, fn, userEvent, within } from 'storybook/test';
2
3
  import UiCheckbox from './UiCheckbox.vue';
3
4
  import { ref } from 'vue';
4
5
 
@@ -30,6 +31,11 @@ export default meta;
30
31
 
31
32
  type Story = StoryObj<typeof UiCheckbox>;
32
33
 
34
+ // `UiCheckbox` forwards `defineModel`, so it emits `update:modelValue`. Play
35
+ // functions that need to assert the emit bind this module-level spy via
36
+ // `@update:model-value` and `mockClear()` it first.
37
+ const onUpdate = fn();
38
+
33
39
  const defaultTemplateSource = `<script setup lang="ts">
34
40
  import { ref } from 'vue'
35
41
  import { UiCheckbox } from '@aleph-alpha/ui-library'
@@ -70,6 +76,31 @@ export const Default: Story = {
70
76
  },
71
77
  },
72
78
  },
79
+ play: async ({ canvasElement, step }) => {
80
+ // Scenario (UiCheckbox): assistive tech sees a checkbox role, the label as its accessible
81
+ // name, and its unchecked state. These checks don't mutate state, so the
82
+ // visual snapshot stays stable.
83
+ const canvas = within(canvasElement);
84
+ const checkbox = canvas.getByRole('checkbox', {
85
+ name: 'Accept terms and conditions',
86
+ });
87
+
88
+ await step(
89
+ 'screen-reader: exposes a checkbox role with its label as the accessible name (WCAG 1.3.1 / 4.1.2)',
90
+ async () => {
91
+ await expect(checkbox).toHaveAccessibleName(
92
+ 'Accept terms and conditions',
93
+ );
94
+ },
95
+ );
96
+
97
+ await step(
98
+ 'screen-reader: announces the unchecked state via aria-checked',
99
+ async () => {
100
+ await expect(checkbox).toHaveAttribute('aria-checked', 'false');
101
+ },
102
+ );
103
+ },
73
104
  };
74
105
 
75
106
  /**
@@ -322,6 +353,21 @@ export const Disabled: Story = {
322
353
  },
323
354
  },
324
355
  },
356
+ play: async ({ canvasElement, step }) => {
357
+ // Scenario (UiCheckbox): a disabled checkbox reports its disabled state to assistive
358
+ // tech (a disabled control is inherently out of the tab order).
359
+ const canvas = within(canvasElement);
360
+ const checkbox = canvas.getByRole('checkbox', {
361
+ name: 'Enable notifications',
362
+ });
363
+
364
+ await step(
365
+ 'interaction: exposes the disabled state (WCAG 4.1.2)',
366
+ async () => {
367
+ await expect(checkbox).toBeDisabled();
368
+ },
369
+ );
370
+ },
325
371
  };
326
372
 
327
373
  const cardTemplateSource = `<script setup lang="ts">
@@ -389,3 +435,210 @@ export const Card: Story = {
389
435
  },
390
436
  },
391
437
  };
438
+
439
+ const indeterminateTemplateSource = `<script setup lang="ts">
440
+ import { ref } from 'vue'
441
+ import { UiCheckbox } from '@aleph-alpha/ui-library'
442
+
443
+ const checked = ref<'indeterminate' | boolean>('indeterminate')
444
+ </script>
445
+
446
+ <template>
447
+ <div class="flex items-center gap-3">
448
+ <UiCheckbox id="select-all" name="select-all" v-model="checked" />
449
+ <label for="select-all" class="body-14-medium">
450
+ Select all
451
+ </label>
452
+ </div>
453
+ </template>`;
454
+
455
+ /**
456
+ * Indeterminate (mixed) state, typically used for "select all" controls whose
457
+ * children are only partially selected. It exposes `aria-checked="mixed"`.
458
+ */
459
+ export const Indeterminate: Story = {
460
+ render: () => ({
461
+ components: { UiCheckbox },
462
+ setup() {
463
+ const checked = ref<'indeterminate' | boolean>('indeterminate');
464
+ return { checked };
465
+ },
466
+ template: `<div class="flex items-center gap-3">
467
+ <UiCheckbox id="select-all" name="select-all" v-model="checked" />
468
+ <label for="select-all" class="body-14-medium">
469
+ Select all
470
+ </label>
471
+ </div>`,
472
+ }),
473
+ parameters: {
474
+ docs: {
475
+ source: {
476
+ code: indeterminateTemplateSource,
477
+ },
478
+ },
479
+ },
480
+ play: async ({ canvasElement, step }) => {
481
+ // Scenario (UiCheckbox): the mixed selection state is announced to assistive tech via
482
+ // aria-checked="mixed".
483
+ const canvas = within(canvasElement);
484
+ const checkbox = canvas.getByRole('checkbox', { name: 'Select all' });
485
+
486
+ await step(
487
+ 'screen-reader: announces the mixed state via aria-checked (WCAG 4.1.2)',
488
+ async () => {
489
+ await expect(checkbox).toHaveAttribute('aria-checked', 'mixed');
490
+ },
491
+ );
492
+ },
493
+ };
494
+
495
+ /**
496
+ * `UiCheckbox` is keyboard operable: `Tab` moves focus to it and `Space`
497
+ * toggles the checked state. Hidden test-only story.
498
+ */
499
+ export const KeyboardNavigation: Story = {
500
+ name: 'test - Keyboard Navigation',
501
+ tags: ['!dev', '!autodocs'],
502
+ render: () => ({
503
+ components: { UiCheckbox },
504
+ setup() {
505
+ const checked = ref(false);
506
+ return { checked, onUpdate };
507
+ },
508
+ template: `<div class="flex items-center gap-3">
509
+ <UiCheckbox id="subscribe" name="subscribe" v-model="checked" @update:model-value="onUpdate" />
510
+ <label for="subscribe" class="body-14-medium">
511
+ Subscribe to updates
512
+ </label>
513
+ </div>`,
514
+ }),
515
+ parameters: {
516
+ // Focus moves during the play function; skip the visual snapshot so the
517
+ // focus ring doesn't register as a Chromatic diff.
518
+ chromatic: { disableSnapshot: true },
519
+ docs: {
520
+ description: {
521
+ story:
522
+ 'Press `Tab` to focus the checkbox, then `Space` to toggle it on and off.',
523
+ },
524
+ },
525
+ },
526
+ play: async ({ canvasElement, step }) => {
527
+ // Scenario (UiCheckbox): a keyboard user tabs to the checkbox and toggles it with Space,
528
+ // which flips aria-checked and emits update:modelValue.
529
+ onUpdate.mockClear();
530
+ const canvas = within(canvasElement);
531
+ const checkbox = canvas.getByRole('checkbox', {
532
+ name: 'Subscribe to updates',
533
+ });
534
+
535
+ await step(
536
+ 'keyboard: checkbox is reachable via Tab (WCAG 2.1.1)',
537
+ async () => {
538
+ await userEvent.tab();
539
+ await expect(checkbox).toHaveFocus();
540
+ },
541
+ );
542
+
543
+ await step(
544
+ 'keyboard: Space toggles the checked state (WCAG 2.1.1)',
545
+ async () => {
546
+ await userEvent.keyboard(' ');
547
+ await expect(checkbox).toHaveAttribute('aria-checked', 'true');
548
+ await expect(onUpdate).toHaveBeenCalledWith(true);
549
+ },
550
+ );
551
+ },
552
+ };
553
+
554
+ const mobileBreakpointTemplateSource = `<script setup lang="ts">
555
+ import { ref } from 'vue'
556
+ import { UiCheckbox } from '@aleph-alpha/ui-library'
557
+
558
+ const checked = ref(false)
559
+ </script>
560
+
561
+ <template>
562
+ <div class="flex items-center gap-3">
563
+ <UiCheckbox id="mobile-terms" name="terms" v-model="checked" />
564
+ <label for="mobile-terms" class="body-14-medium">
565
+ Accept terms and conditions
566
+ </label>
567
+ </div>
568
+ </template>`;
569
+
570
+ /**
571
+ * Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
572
+ * toolbar. Stays operable, keyboard navigable, and remains sized for touch.
573
+ * Hidden test-only story.
574
+ */
575
+ export const MobileBreakpoint: Story = {
576
+ name: 'test - Mobile Breakpoint',
577
+ tags: ['!dev', '!autodocs'],
578
+ globals: { mediaBreakpoint: 'reflow' },
579
+ render: () => ({
580
+ components: { UiCheckbox },
581
+ setup() {
582
+ const checked = ref(false);
583
+ return { checked, onUpdate };
584
+ },
585
+ template: `<div class="flex items-center gap-3">
586
+ <UiCheckbox id="mobile-terms" name="terms" v-model="checked" @update:model-value="onUpdate" />
587
+ <label for="mobile-terms" class="body-14-medium">
588
+ Accept terms and conditions
589
+ </label>
590
+ </div>`,
591
+ }),
592
+ parameters: {
593
+ // Focus moves and state toggles during the play function; skip the snapshot.
594
+ chromatic: { disableSnapshot: true },
595
+ docs: {
596
+ description: {
597
+ story:
598
+ 'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
599
+ },
600
+ source: { code: mobileBreakpointTemplateSource },
601
+ },
602
+ },
603
+ play: async ({ canvasElement, step }) => {
604
+ // Scenario (UiCheckbox): at the 320px mobile breakpoint the checkbox stays labelled,
605
+ // keyboard operable, and visible.
606
+ onUpdate.mockClear();
607
+ const canvas = within(canvasElement);
608
+ const checkbox = canvas.getByRole('checkbox', {
609
+ name: 'Accept terms and conditions',
610
+ });
611
+
612
+ await step(
613
+ 'mobile: exposes a labelled, unchecked checkbox at the 320px breakpoint (WCAG 4.1.2)',
614
+ async () => {
615
+ await expect(checkbox).toBeVisible();
616
+ await expect(checkbox).toHaveAccessibleName(
617
+ 'Accept terms and conditions',
618
+ );
619
+ await expect(checkbox).toHaveAttribute('aria-checked', 'false');
620
+ },
621
+ );
622
+
623
+ await step(
624
+ 'mobile: stays keyboard operable — Tab focuses and Space toggles (WCAG 2.1.1)',
625
+ async () => {
626
+ await userEvent.tab();
627
+ await expect(checkbox).toHaveFocus();
628
+ await userEvent.keyboard(' ');
629
+ await expect(checkbox).toHaveAttribute('aria-checked', 'true');
630
+ await expect(onUpdate).toHaveBeenCalledWith(true);
631
+ },
632
+ );
633
+
634
+ await step(
635
+ 'mobile: the checkbox control stays visible and rendered at the mobile breakpoint',
636
+ async () => {
637
+ await expect(checkbox).toBeVisible();
638
+ const { width, height } = checkbox.getBoundingClientRect();
639
+ await expect(width).toBeGreaterThan(0);
640
+ await expect(height).toBeGreaterThan(0);
641
+ },
642
+ );
643
+ },
644
+ };
@@ -4,26 +4,11 @@ import { describe, expect, test } from 'vitest';
4
4
  import UiCheckbox from '../UiCheckbox.vue';
5
5
 
6
6
  describe('UiCheckbox', () => {
7
- test('renders enabled and emits update:modelValue on click', async () => {
7
+ // v-model wiring (the wrapper's own integration work) is unit-tested here.
8
+ test('emits update:modelValue on click', async () => {
8
9
  const { getByRole, emitted } = render(UiCheckbox);
9
- const checkbox = getByRole('checkbox');
10
- expect(checkbox).toBeEnabled();
11
10
 
12
- await userEvent.click(checkbox);
11
+ await userEvent.click(getByRole('checkbox'));
13
12
  expect(emitted('update:modelValue')?.[0][0]).toBe(true);
14
13
  });
15
-
16
- test('renders disabled when disabled prop is true', () => {
17
- const { getByRole } = render(UiCheckbox, {
18
- props: { disabled: true },
19
- });
20
- expect(getByRole('checkbox')).toBeDisabled();
21
- });
22
-
23
- test('renders indeterminate state with aria-checked="mixed"', () => {
24
- const { getByRole } = render(UiCheckbox, {
25
- props: { modelValue: 'indeterminate' },
26
- });
27
- expect(getByRole('checkbox')).toHaveAttribute('aria-checked', 'mixed');
28
- });
29
14
  });