@aleph-alpha/ui-library 5.4.0 → 5.5.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.
- package/config.d.ts +9 -0
- package/config.js +12 -3
- package/dist/system/lib.js +6461 -6397
- package/dist/system/patterns/UiFloatActions/UiFloatActionItems.vue.d.ts +173 -2
- package/dist/system/patterns/UiFloatActions/floatActionItemContext.d.ts +15 -1
- package/dist/system/patterns/UiFloatActions/types.d.ts +25 -1
- package/dist/system/story-sidebar-icons.json +5 -1
- package/package.json +5 -3
- package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +1 -0
- package/src/components/UiButton/UiButton.stories.ts +9 -9
- package/src/components/UiCheckbox/UiCheckbox.stories.ts +253 -0
- package/src/components/UiCheckbox/__tests__/UiCheckbox.test.ts +3 -18
- package/src/components/UiField/UiField.stories.ts +608 -1
- package/src/components/UiField/UiFieldDescription.vue +7 -2
- package/src/components/UiInput/UiInput.stories.ts +336 -2
- package/src/components/UiInput/__tests__/UiInput.test.ts +20 -28
- package/src/components/UiItem/UiItem.stories.ts +236 -1
- package/src/components/UiItem/__tests__/UiItem.test.ts +11 -72
- package/src/components/UiSnackbar/UiSnackbar.stories.ts +6 -6
- package/src/components/UiSnackbar/UiSnackbar.vue +4 -4
- package/src/components/UiSnackbar/UiSnackbarContent.vue +4 -4
- package/src/components/core/checkbox/Checkbox.vue +0 -1
- package/src/components/core/tabs/TabsTrigger.vue +1 -1
- package/src/patterns/UiDataTable/UiDataTable.stories.ts +495 -8
- package/src/patterns/UiDataTable/UiDataTableFilterMenu.vue +1 -1
- package/src/patterns/UiDataTable/__tests__/UiDataTable.test.ts +7 -184
- package/src/patterns/UiFloatActions/UiFloatActionItems.vue +138 -11
- package/src/patterns/UiFloatActions/UiFloatActions.stories.ts +890 -3
- package/src/patterns/UiFloatActions/__tests__/UiFloatActionItems.test.ts +46 -24
- package/src/patterns/UiFloatActions/floatActionItemContext.ts +16 -1
- package/src/patterns/UiFloatActions/types.ts +28 -1
- package/src/components/UiField/__tests__/UiFieldError.test.ts +0 -39
- package/src/patterns/UiFloatActions/__tests__/UiFloatActions.a11y.test.ts +0 -152
|
@@ -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
|
-
|
|
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
|
});
|