@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.
- package/config.d.ts +9 -0
- package/config.js +12 -3
- package/dist/system/components/UiAutocomplete/UiAutocomplete.vue.d.ts +2 -0
- package/dist/system/components/UiButtonGroup/UiButtonGroup.vue.d.ts +20 -0
- package/dist/system/components/UiButtonGroup/index.d.ts +2 -0
- package/dist/system/components/UiButtonGroup/types.d.ts +20 -0
- package/dist/system/components/core/button-group/ButtonGroup.vue.d.ts +23 -0
- package/dist/system/components/core/button-group/ButtonGroupSeparator.vue.d.ts +9 -0
- package/dist/system/components/core/button-group/ButtonGroupText.vue.d.ts +26 -0
- package/dist/system/components/core/button-group/index.d.ts +8 -0
- package/dist/system/components/index.d.ts +1 -0
- package/dist/system/lib.js +8878 -8692
- 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 +8 -1
- package/package.json +5 -3
- package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +620 -0
- package/src/components/UiAutocomplete/UiAutocomplete.vue +28 -3
- package/src/components/UiAutocomplete/__tests__/UiAutocomplete.test.ts +14 -69
- package/src/components/UiButton/UiButton.stories.ts +9 -9
- package/src/components/UiButtonGroup/UiButtonGroup.stories.ts +690 -0
- package/src/components/UiButtonGroup/UiButtonGroup.vue +18 -0
- package/src/components/UiButtonGroup/__tests__/UiButtonGroup.test.ts +68 -0
- package/src/components/UiButtonGroup/index.ts +2 -0
- package/src/components/UiButtonGroup/types.ts +21 -0
- 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/UiSelect/UiSelect.stories.ts +769 -0
- package/src/components/UiSelect/__tests__/UiSelect.test.ts +4 -73
- package/src/components/UiSelect/__tests__/UiSelectItem.test.ts +3 -31
- package/src/components/UiSelect/__tests__/UiSelectTrigger.test.ts +14 -5
- 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/button-group/ButtonGroup.vue +24 -0
- package/src/components/core/button-group/ButtonGroupSeparator.vue +29 -0
- package/src/components/core/button-group/ButtonGroupText.vue +33 -0
- package/src/components/core/button-group/index.ts +25 -0
- package/src/components/core/checkbox/Checkbox.vue +0 -1
- package/src/components/core/select/SelectTrigger.vue +1 -1
- package/src/components/core/tabs/TabsTrigger.vue +1 -1
- package/src/components/index.ts +1 -0
- 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 UiItem from './UiItem.vue';
|
|
3
4
|
import {
|
|
4
5
|
UiItemGroup,
|
|
@@ -87,6 +88,12 @@ export default meta;
|
|
|
87
88
|
|
|
88
89
|
type Story = StoryObj<typeof UiItem>;
|
|
89
90
|
|
|
91
|
+
// `UiItem` emits an `action` event from its built-in trailing action button.
|
|
92
|
+
// Play functions assert against this module-level spy bound via `@action`
|
|
93
|
+
// rather than through `args`. Each `play` clears it first, so it is safe to
|
|
94
|
+
// share across the interaction and keyboard test stories.
|
|
95
|
+
const onAction = fn();
|
|
96
|
+
|
|
90
97
|
const createSource = (
|
|
91
98
|
imports: string[],
|
|
92
99
|
template: string,
|
|
@@ -662,7 +669,15 @@ export const Actions: Story = {
|
|
|
662
669
|
UiIcon,
|
|
663
670
|
UiItem,
|
|
664
671
|
},
|
|
665
|
-
|
|
672
|
+
setup() {
|
|
673
|
+
return { onAction };
|
|
674
|
+
},
|
|
675
|
+
// Wire the first item's action to the spy for the play function while
|
|
676
|
+
// keeping the docs source snippet unchanged.
|
|
677
|
+
template: actionsTemplate.replace(
|
|
678
|
+
'@action="() => {}"',
|
|
679
|
+
'@action="onAction"',
|
|
680
|
+
),
|
|
666
681
|
}),
|
|
667
682
|
parameters: {
|
|
668
683
|
docs: {
|
|
@@ -671,6 +686,28 @@ export const Actions: Story = {
|
|
|
671
686
|
},
|
|
672
687
|
},
|
|
673
688
|
},
|
|
689
|
+
play: async ({ canvasElement, step }) => {
|
|
690
|
+
// Scenario (UiItem): the built-in trailing action exposes an accessible name and
|
|
691
|
+
// emits the `action` event when a pointer user activates it.
|
|
692
|
+
onAction.mockClear();
|
|
693
|
+
const canvas = within(canvasElement);
|
|
694
|
+
const [action] = canvas.getAllByRole('button', { name: 'More actions' });
|
|
695
|
+
|
|
696
|
+
await step(
|
|
697
|
+
'interaction: default action exposes an accessible name (WCAG 4.1.2)',
|
|
698
|
+
async () => {
|
|
699
|
+
await expect(action).toHaveAccessibleName('More actions');
|
|
700
|
+
},
|
|
701
|
+
);
|
|
702
|
+
|
|
703
|
+
await step(
|
|
704
|
+
'interaction: clicking the default action emits the action event',
|
|
705
|
+
async () => {
|
|
706
|
+
await userEvent.click(action);
|
|
707
|
+
await expect(onAction).toHaveBeenCalledTimes(1);
|
|
708
|
+
},
|
|
709
|
+
);
|
|
710
|
+
},
|
|
674
711
|
};
|
|
675
712
|
|
|
676
713
|
/**
|
|
@@ -803,6 +840,126 @@ export const AsLink: Story = {
|
|
|
803
840
|
},
|
|
804
841
|
},
|
|
805
842
|
},
|
|
843
|
+
play: async ({ canvasElement, step }) => {
|
|
844
|
+
// Scenario (UiItem): rendered as an anchor via `asChild`, the row exposes a link
|
|
845
|
+
// role with the child accessible name and preserves the destination,
|
|
846
|
+
// without leaking a redundant button role.
|
|
847
|
+
const canvas = within(canvasElement);
|
|
848
|
+
|
|
849
|
+
await step(
|
|
850
|
+
'interaction: asChild exposes a link role with the child accessible name (WCAG 4.1.2)',
|
|
851
|
+
async () => {
|
|
852
|
+
const link = canvas.getByRole('link', { name: /Documentation/ });
|
|
853
|
+
await expect(link).toHaveAttribute('href', '#');
|
|
854
|
+
},
|
|
855
|
+
);
|
|
856
|
+
|
|
857
|
+
await step(
|
|
858
|
+
'interaction: does not expose a redundant button role',
|
|
859
|
+
async () => {
|
|
860
|
+
await expect(canvas.queryByRole('button')).not.toBeInTheDocument();
|
|
861
|
+
},
|
|
862
|
+
);
|
|
863
|
+
},
|
|
864
|
+
};
|
|
865
|
+
|
|
866
|
+
/**
|
|
867
|
+
* The built-in trailing action is fully keyboard operable: `Tab` moves focus to
|
|
868
|
+
* it and `Enter` / `Space` activate it. Hidden test-only story.
|
|
869
|
+
*/
|
|
870
|
+
export const KeyboardNavigation: Story = {
|
|
871
|
+
name: 'test - Keyboard Navigation',
|
|
872
|
+
tags: ['!dev', '!autodocs'],
|
|
873
|
+
render: () => ({
|
|
874
|
+
components: { UiItem },
|
|
875
|
+
setup() {
|
|
876
|
+
return { onAction };
|
|
877
|
+
},
|
|
878
|
+
template: `
|
|
879
|
+
<div class="w-full max-w-md">
|
|
880
|
+
<UiItem title="Weekly report" description="Summary of this week's activity" @action="onAction" />
|
|
881
|
+
</div>
|
|
882
|
+
`,
|
|
883
|
+
}),
|
|
884
|
+
parameters: {
|
|
885
|
+
// Focus moves during the play function; skip the visual snapshot so the
|
|
886
|
+
// focus ring doesn't register as a Chromatic diff.
|
|
887
|
+
chromatic: { disableSnapshot: true },
|
|
888
|
+
docs: {
|
|
889
|
+
description: {
|
|
890
|
+
story:
|
|
891
|
+
'Press `Tab` to focus the trailing action, then `Enter` or `Space` to activate it.',
|
|
892
|
+
},
|
|
893
|
+
},
|
|
894
|
+
},
|
|
895
|
+
play: async ({ canvasElement, step }) => {
|
|
896
|
+
// Scenario (UiItem): a keyboard user tabs to the trailing action and activates it
|
|
897
|
+
// with Enter and Space.
|
|
898
|
+
onAction.mockClear();
|
|
899
|
+
const canvas = within(canvasElement);
|
|
900
|
+
const action = canvas.getByRole('button', { name: 'More actions' });
|
|
901
|
+
|
|
902
|
+
await step(
|
|
903
|
+
'keyboard: trailing action is reachable via Tab (WCAG 2.1.1)',
|
|
904
|
+
async () => {
|
|
905
|
+
await userEvent.tab();
|
|
906
|
+
await expect(action).toHaveFocus();
|
|
907
|
+
},
|
|
908
|
+
);
|
|
909
|
+
|
|
910
|
+
await step('keyboard: activates with Enter', async () => {
|
|
911
|
+
await userEvent.keyboard('{Enter}');
|
|
912
|
+
await expect(onAction).toHaveBeenCalledTimes(1);
|
|
913
|
+
});
|
|
914
|
+
|
|
915
|
+
await step('keyboard: activates with Space', async () => {
|
|
916
|
+
await userEvent.keyboard(' ');
|
|
917
|
+
await expect(onAction).toHaveBeenCalledTimes(2);
|
|
918
|
+
});
|
|
919
|
+
},
|
|
920
|
+
};
|
|
921
|
+
|
|
922
|
+
/**
|
|
923
|
+
* `withListSemantics` opts an item into `role="listitem"` so it can be a
|
|
924
|
+
* semantic child of a `role="list"` container, while omitting it keeps the item
|
|
925
|
+
* roleless. Hidden test-only story.
|
|
926
|
+
*/
|
|
927
|
+
export const ListSemantics: Story = {
|
|
928
|
+
name: 'test - List Semantics',
|
|
929
|
+
tags: ['!dev', '!autodocs'],
|
|
930
|
+
render: () => ({
|
|
931
|
+
components: { UiItem },
|
|
932
|
+
template: `
|
|
933
|
+
<div class="flex w-full max-w-md flex-col gap-3">
|
|
934
|
+
<div role="list">
|
|
935
|
+
<UiItem with-list-semantics title="List item" description="Exposes role=listitem" />
|
|
936
|
+
</div>
|
|
937
|
+
<UiItem title="Plain item" description="Stays roleless by default" />
|
|
938
|
+
</div>
|
|
939
|
+
`,
|
|
940
|
+
}),
|
|
941
|
+
parameters: {
|
|
942
|
+
docs: {
|
|
943
|
+
description: {
|
|
944
|
+
story:
|
|
945
|
+
'Only items with `withListSemantics` expose `role="listitem"`; the default item stays roleless.',
|
|
946
|
+
},
|
|
947
|
+
},
|
|
948
|
+
},
|
|
949
|
+
play: async ({ canvasElement, step }) => {
|
|
950
|
+
// Scenario (UiItem): assistive tech only sees a listitem for the item that opted in
|
|
951
|
+
// via `withListSemantics`; the default item exposes no list role.
|
|
952
|
+
const canvas = within(canvasElement);
|
|
953
|
+
|
|
954
|
+
await step(
|
|
955
|
+
'screen-reader: only the opted-in item exposes role=listitem (WCAG 1.3.1)',
|
|
956
|
+
async () => {
|
|
957
|
+
const listItems = canvas.getAllByRole('listitem');
|
|
958
|
+
await expect(listItems).toHaveLength(1);
|
|
959
|
+
await expect(listItems[0]).toHaveTextContent('List item');
|
|
960
|
+
},
|
|
961
|
+
);
|
|
962
|
+
},
|
|
806
963
|
};
|
|
807
964
|
|
|
808
965
|
/**
|
|
@@ -829,3 +986,81 @@ export const AllVariants: Story = {
|
|
|
829
986
|
},
|
|
830
987
|
},
|
|
831
988
|
};
|
|
989
|
+
|
|
990
|
+
const mobileBreakpointTemplate = `
|
|
991
|
+
<div class="w-full max-w-md">
|
|
992
|
+
<UiItem
|
|
993
|
+
title="Weekly report"
|
|
994
|
+
description="Summary of this week's activity"
|
|
995
|
+
/>
|
|
996
|
+
</div>
|
|
997
|
+
`;
|
|
998
|
+
|
|
999
|
+
/**
|
|
1000
|
+
* Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
|
|
1001
|
+
* toolbar. The row and its trailing action stay operable and keyboard
|
|
1002
|
+
* navigable at 320px. Hidden test-only story.
|
|
1003
|
+
*/
|
|
1004
|
+
export const MobileBreakpoint: Story = {
|
|
1005
|
+
name: 'test - Mobile Breakpoint',
|
|
1006
|
+
tags: ['!dev', '!autodocs'],
|
|
1007
|
+
globals: { mediaBreakpoint: 'reflow' },
|
|
1008
|
+
render: () => ({
|
|
1009
|
+
components: { UiItem },
|
|
1010
|
+
setup() {
|
|
1011
|
+
return { onAction };
|
|
1012
|
+
},
|
|
1013
|
+
template: `
|
|
1014
|
+
<div class="w-full max-w-md">
|
|
1015
|
+
<UiItem title="Weekly report" description="Summary of this week's activity" @action="onAction" />
|
|
1016
|
+
</div>
|
|
1017
|
+
`,
|
|
1018
|
+
}),
|
|
1019
|
+
parameters: {
|
|
1020
|
+
// The play function focuses and activates the action; skip the snapshot.
|
|
1021
|
+
chromatic: { disableSnapshot: true },
|
|
1022
|
+
docs: {
|
|
1023
|
+
description: {
|
|
1024
|
+
story:
|
|
1025
|
+
'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
|
|
1026
|
+
},
|
|
1027
|
+
source: {
|
|
1028
|
+
code: createSource(['UiItem'], mobileBreakpointTemplate),
|
|
1029
|
+
},
|
|
1030
|
+
},
|
|
1031
|
+
},
|
|
1032
|
+
play: async ({ canvasElement, step }) => {
|
|
1033
|
+
// Scenario (UiItem): at the 320px mobile breakpoint the item's trailing action stays
|
|
1034
|
+
// labelled, keyboard operable, and sized for touch.
|
|
1035
|
+
onAction.mockClear();
|
|
1036
|
+
const canvas = within(canvasElement);
|
|
1037
|
+
const action = canvas.getByRole('button', { name: 'More actions' });
|
|
1038
|
+
|
|
1039
|
+
await step(
|
|
1040
|
+
'mobile: the trailing action exposes an accessible name at the 320px breakpoint (WCAG 4.1.2)',
|
|
1041
|
+
async () => {
|
|
1042
|
+
await expect(action).toBeVisible();
|
|
1043
|
+
await expect(action).toHaveAccessibleName('More actions');
|
|
1044
|
+
},
|
|
1045
|
+
);
|
|
1046
|
+
|
|
1047
|
+
await step(
|
|
1048
|
+
'mobile: stays keyboard operable — Tab focuses and Enter activates (WCAG 2.1.1)',
|
|
1049
|
+
async () => {
|
|
1050
|
+
await userEvent.tab();
|
|
1051
|
+
await expect(action).toHaveFocus();
|
|
1052
|
+
await userEvent.keyboard('{Enter}');
|
|
1053
|
+
await expect(onAction).toHaveBeenCalledTimes(1);
|
|
1054
|
+
},
|
|
1055
|
+
);
|
|
1056
|
+
|
|
1057
|
+
await step(
|
|
1058
|
+
'mobile: the action control stays visible and sized at the mobile breakpoint',
|
|
1059
|
+
async () => {
|
|
1060
|
+
const { width, height } = action.getBoundingClientRect();
|
|
1061
|
+
await expect(width).toBeGreaterThanOrEqual(16);
|
|
1062
|
+
await expect(height).toBeGreaterThanOrEqual(16);
|
|
1063
|
+
},
|
|
1064
|
+
);
|
|
1065
|
+
},
|
|
1066
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { describe, expect, test
|
|
1
|
+
import { render } from '@testing-library/vue';
|
|
2
|
+
import { describe, expect, test } from 'vitest';
|
|
3
3
|
import {
|
|
4
4
|
UiItem,
|
|
5
5
|
UiItemGroup,
|
|
@@ -16,31 +16,9 @@ import { ItemActionVariants, ItemMediaVariants } from '../constants';
|
|
|
16
16
|
|
|
17
17
|
describe('UiItem', () => {
|
|
18
18
|
describe('Rendering', () => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
default: 'Item content',
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
const element = container.querySelector('[data-slot="item"]');
|
|
27
|
-
expect(element?.tagName).toBe('DIV');
|
|
28
|
-
expect(element).not.toHaveAttribute('role');
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test('applies listitem role only when list semantics are requested', () => {
|
|
32
|
-
const { container } = render(UiItem, {
|
|
33
|
-
props: {
|
|
34
|
-
withListSemantics: true,
|
|
35
|
-
},
|
|
36
|
-
slots: {
|
|
37
|
-
default: 'Item content',
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
const element = container.querySelector('[data-slot="item"]');
|
|
42
|
-
expect(element).toHaveAttribute('role', 'listitem');
|
|
43
|
-
});
|
|
19
|
+
// Keyboard, focus, and a11y/role behavior (role="listitem" via
|
|
20
|
+
// withListSemantics, roleless by default) is covered by the `test - List
|
|
21
|
+
// Semantics` play story in UiItem.stories.ts.
|
|
44
22
|
|
|
45
23
|
test('renders slot content', () => {
|
|
46
24
|
const { getByText } = render(UiItem, {
|
|
@@ -303,20 +281,9 @@ describe('UiItem', () => {
|
|
|
303
281
|
expect(defaultAction.className).toContain('[&_svg]:size-3');
|
|
304
282
|
});
|
|
305
283
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
props: {
|
|
310
|
-
title: 'Item title',
|
|
311
|
-
onAction,
|
|
312
|
-
},
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
await fireEvent.click(getByRole('button', { name: 'More actions' }));
|
|
316
|
-
|
|
317
|
-
expect(onAction).toHaveBeenCalledTimes(1);
|
|
318
|
-
expect(onAction.mock.calls[0]?.[0]).toBeInstanceOf(MouseEvent);
|
|
319
|
-
});
|
|
284
|
+
// The default action's click/keyboard activation and accessible name are
|
|
285
|
+
// covered by the `Actions` and `test - Keyboard Navigation` play stories in
|
|
286
|
+
// UiItem.stories.ts.
|
|
320
287
|
|
|
321
288
|
test('does not infer hover background when action slot is present', () => {
|
|
322
289
|
const { container } = render(UiItem, {
|
|
@@ -336,37 +303,9 @@ describe('UiItem', () => {
|
|
|
336
303
|
});
|
|
337
304
|
|
|
338
305
|
describe('asChild behavior', () => {
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
asChild: true,
|
|
343
|
-
},
|
|
344
|
-
slots: {
|
|
345
|
-
default: '<a href="/test">Link Item</a>',
|
|
346
|
-
},
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
const element = container.querySelector('[data-slot="item"]');
|
|
350
|
-
expect(element).toBeInTheDocument();
|
|
351
|
-
expect(element?.tagName).toBe('A');
|
|
352
|
-
expect(element).toHaveAttribute('href', '/test');
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
test('renders child element as root when asChild is true with button tag', () => {
|
|
356
|
-
const { container } = render(UiItem, {
|
|
357
|
-
props: {
|
|
358
|
-
asChild: true,
|
|
359
|
-
},
|
|
360
|
-
slots: {
|
|
361
|
-
default: '<button type="button">Button Item</button>',
|
|
362
|
-
},
|
|
363
|
-
});
|
|
364
|
-
|
|
365
|
-
const element = container.querySelector('[data-slot="item"]');
|
|
366
|
-
expect(element).toBeInTheDocument();
|
|
367
|
-
expect(element?.tagName).toBe('BUTTON');
|
|
368
|
-
expect(element).toHaveAttribute('type', 'button');
|
|
369
|
-
});
|
|
306
|
+
// The accessible role/name of the rendered child (link role + href) is
|
|
307
|
+
// covered by the `AsLink` play story in UiItem.stories.ts. Rendering a child
|
|
308
|
+
// button uses the same asChild passthrough, so it needs no separate test.
|
|
370
309
|
|
|
371
310
|
test('applies computed classes to child element when asChild is true', () => {
|
|
372
311
|
const { container } = render(UiItem, {
|