@aleph-alpha/ui-library 5.7.0 → 5.9.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/README.md +12 -7
- package/config.d.ts +5 -1
- package/config.js +18 -1
- package/dist/system/__tests__/test-utils.d.ts +24 -0
- package/dist/system/components/UiAutocomplete/UiAutocomplete.vue.d.ts +8 -4
- package/dist/system/components/UiAutocomplete/types.d.ts +11 -0
- package/dist/system/components/UiBreadcrumb/UiBreadcrumb.vue.d.ts +17 -0
- package/dist/system/components/UiBreadcrumb/UiBreadcrumbEllipsis.vue.d.ts +17 -0
- package/dist/system/components/UiBreadcrumb/UiBreadcrumbItem.vue.d.ts +17 -0
- package/dist/system/components/UiBreadcrumb/UiBreadcrumbLink.vue.d.ts +18 -0
- package/dist/system/components/UiBreadcrumb/UiBreadcrumbList.vue.d.ts +17 -0
- package/dist/system/components/UiBreadcrumb/UiBreadcrumbPage.vue.d.ts +17 -0
- package/dist/system/components/UiBreadcrumb/UiBreadcrumbSeparator.vue.d.ts +17 -0
- package/dist/system/components/UiBreadcrumb/index.d.ts +8 -0
- package/dist/system/components/UiBreadcrumb/types.d.ts +22 -0
- package/dist/system/components/UiFadeMask/UiFadeMask.vue.d.ts +21 -0
- package/dist/system/components/UiFadeMask/index.d.ts +2 -0
- package/dist/system/components/UiFadeMask/types.d.ts +33 -0
- package/dist/system/components/UiListbox/UiListboxVirtualizer.vue.d.ts +21 -0
- package/dist/system/components/UiListbox/index.d.ts +1 -0
- package/dist/system/components/UiListbox/types.d.ts +36 -0
- package/dist/system/components/UiSelect/UiSelectVirtualizer.vue.d.ts +21 -0
- package/dist/system/components/UiSelect/index.d.ts +1 -0
- package/dist/system/components/UiSelect/types.d.ts +36 -0
- package/dist/system/components/UiToggleGroup/types.d.ts +0 -5
- package/dist/system/components/core/breadcrumb/Breadcrumb.vue.d.ts +21 -0
- package/dist/system/components/core/breadcrumb/BreadcrumbEllipsis.vue.d.ts +21 -0
- package/dist/system/components/core/breadcrumb/BreadcrumbItem.vue.d.ts +21 -0
- package/dist/system/components/core/breadcrumb/BreadcrumbLink.vue.d.ts +24 -0
- package/dist/system/components/core/breadcrumb/BreadcrumbList.vue.d.ts +21 -0
- package/dist/system/components/core/breadcrumb/BreadcrumbPage.vue.d.ts +21 -0
- package/dist/system/components/core/breadcrumb/BreadcrumbSeparator.vue.d.ts +21 -0
- package/dist/system/components/core/breadcrumb/index.d.ts +7 -0
- package/dist/system/components/core/listbox/Listbox.vue.d.ts +28 -2
- package/dist/system/components/core/listbox/context.d.ts +21 -0
- package/dist/system/components/core/native-select/NativeSelectOptGroup.vue.d.ts +2 -2
- package/dist/system/components/core/native-select/NativeSelectOption.vue.d.ts +2 -2
- package/dist/system/components/index.d.ts +2 -0
- package/dist/system/lib.js +22570 -21061
- package/dist/system/mobile-device-frame.png +0 -0
- package/dist/system/patterns/UiDatePicker/UiDatePicker.vue.d.ts +1 -1
- package/dist/system/patterns/UiFloatActions/types.d.ts +2 -1
- package/dist/system/patterns/UiProfileCard/index.d.ts +7 -0
- package/dist/system/patterns/UiTopBar/UiTopBar.vue.d.ts +23 -0
- package/dist/system/patterns/UiTopBar/index.d.ts +2 -0
- package/dist/system/patterns/UiTopBar/types.d.ts +28 -0
- package/dist/system/patterns/index.d.ts +2 -0
- package/dist/system/story-sidebar-icons.json +10 -1
- package/package.json +3 -2
- package/src/__tests__/test-utils.ts +74 -0
- package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +94 -0
- package/src/components/UiAutocomplete/UiAutocomplete.vue +164 -44
- package/src/components/UiAutocomplete/__tests__/UiAutocompleteVirtualized.test.ts +107 -0
- package/src/components/UiAutocomplete/types.ts +11 -0
- package/src/components/UiBreadcrumb/UiBreadcrumb.stories.ts +1419 -0
- package/src/components/UiBreadcrumb/UiBreadcrumb.vue +19 -0
- package/src/components/UiBreadcrumb/UiBreadcrumbEllipsis.vue +22 -0
- package/src/components/UiBreadcrumb/UiBreadcrumbItem.vue +19 -0
- package/src/components/UiBreadcrumb/UiBreadcrumbLink.vue +26 -0
- package/src/components/UiBreadcrumb/UiBreadcrumbList.vue +19 -0
- package/src/components/UiBreadcrumb/UiBreadcrumbPage.vue +19 -0
- package/src/components/UiBreadcrumb/UiBreadcrumbSeparator.vue +22 -0
- package/src/components/UiBreadcrumb/index.ts +8 -0
- package/src/components/UiBreadcrumb/types.ts +28 -0
- package/src/components/UiDropdownMenu/UiDropdownMenu.stories.ts +760 -0
- package/src/components/UiDropdownMenu/UiDropdownMenuTrigger.vue +2 -0
- package/src/components/UiFadeMask/UiFadeMask.stories.ts +563 -0
- package/src/components/UiFadeMask/UiFadeMask.vue +86 -0
- package/src/components/UiFadeMask/__tests__/UiFadeMask.test.ts +52 -0
- package/src/components/UiFadeMask/index.ts +6 -0
- package/src/components/UiFadeMask/types.ts +35 -0
- package/src/components/UiListbox/UiListbox.stories.ts +1404 -30
- package/src/components/UiListbox/UiListboxVirtualizer.vue +42 -0
- package/src/components/UiListbox/__tests__/UiListbox.test.ts +70 -35
- package/src/components/UiListbox/__tests__/UiListboxVirtualizer.test.ts +96 -0
- package/src/components/UiListbox/index.ts +1 -0
- package/src/components/UiListbox/types.ts +42 -0
- package/src/components/UiSelect/UiSelect.stories.ts +109 -1
- package/src/components/UiSelect/UiSelectVirtualizer.vue +373 -0
- package/src/components/UiSelect/__tests__/UiSelectVirtualizer.test.ts +185 -0
- package/src/components/UiSelect/index.ts +1 -0
- package/src/components/UiSelect/types.ts +38 -0
- package/src/components/UiSwitch/UiSwitch.stories.ts +706 -9
- package/src/components/UiSwitch/__tests__/UiSwitch.test.ts +2 -6
- package/src/components/UiToggle/UiToggle.stories.ts +961 -130
- package/src/components/UiToggle/UiToggle.vue +8 -1
- package/src/components/UiToggle/__tests__/UiToggle.test.ts +55 -65
- package/src/components/UiToggleGroup/UiToggleGroup.stories.ts +1060 -173
- package/src/components/UiToggleGroup/UiToggleGroup.vue +4 -2
- package/src/components/UiToggleGroup/__tests__/UiToggleGroup.test.ts +117 -325
- package/src/components/UiToggleGroup/types.ts +0 -5
- package/src/components/core/breadcrumb/Breadcrumb.vue +13 -0
- package/src/components/core/breadcrumb/BreadcrumbEllipsis.vue +23 -0
- package/src/components/core/breadcrumb/BreadcrumbItem.vue +17 -0
- package/src/components/core/breadcrumb/BreadcrumbLink.vue +29 -0
- package/src/components/core/breadcrumb/BreadcrumbList.vue +22 -0
- package/src/components/core/breadcrumb/BreadcrumbPage.vue +20 -0
- package/src/components/core/breadcrumb/BreadcrumbSeparator.vue +22 -0
- package/src/components/core/breadcrumb/index.ts +7 -0
- package/src/components/core/dropdown-menu/DropdownMenuCheckboxItem.vue +8 -2
- package/src/components/core/dropdown-menu/DropdownMenuItem.vue +1 -1
- package/src/components/core/dropdown-menu/DropdownMenuRadioItem.vue +8 -2
- package/src/components/core/dropdown-menu/DropdownMenuSubTrigger.vue +1 -1
- package/src/components/core/listbox/Listbox.vue +14 -2
- package/src/components/core/listbox/ListboxContent.vue +61 -3
- package/src/components/core/listbox/ListboxItem.vue +6 -1
- package/src/components/core/listbox/context.ts +34 -0
- package/src/components/core/toggle/Toggle.vue +15 -1
- package/src/components/core/toggle/index.ts +2 -2
- package/src/components/core/toggle-group/ToggleGroup.vue +1 -1
- package/src/components/core/toggle-group/index.ts +5 -2
- package/src/components/index.ts +2 -0
- package/src/patterns/UiFloatActions/UiFloatActions.stories.ts +4 -5
- package/src/patterns/UiFloatActions/UiFloatActions.vue +23 -11
- package/src/patterns/UiFloatActions/__tests__/UiFloatActions.test.ts +23 -0
- package/src/patterns/UiFloatActions/types.ts +2 -1
- package/src/patterns/UiProfileCard/UiProfileCard.stories.ts +1064 -0
- package/src/patterns/UiProfileCard/index.ts +7 -0
- package/src/patterns/UiTopBar/UiTopBar.stories.ts +1121 -0
- package/src/patterns/UiTopBar/UiTopBar.vue +166 -0
- package/src/patterns/UiTopBar/__tests__/UiTopBar.test.ts +245 -0
- package/src/patterns/UiTopBar/index.ts +2 -0
- package/src/patterns/UiTopBar/types.ts +29 -0
- package/src/patterns/index.ts +2 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import '@testing-library/jest-dom/vitest';
|
|
2
|
+
import { render, waitFor } from '@testing-library/vue';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
import { afterAll, beforeAll, describe, expect, test } from 'vitest';
|
|
5
|
+
import { nextTick } from 'vue';
|
|
6
|
+
import { stubScrollLayout } from '@/__tests__/test-utils';
|
|
7
|
+
import { UiAutocomplete } from '../index';
|
|
8
|
+
|
|
9
|
+
const OPTION_COUNT = 500;
|
|
10
|
+
const VIEWPORT_HEIGHT = 300;
|
|
11
|
+
|
|
12
|
+
const options = Array.from({ length: OPTION_COUNT }, (_, index) => ({
|
|
13
|
+
value: `option-${index + 1}`,
|
|
14
|
+
label: `Option ${index + 1}`,
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
let restoreScrollLayout: () => void;
|
|
18
|
+
|
|
19
|
+
// jsdom neither lays elements out nor scrolls them, so without a stand-in the
|
|
20
|
+
// virtualizer would measure a zero-height container and never see the scrolling
|
|
21
|
+
// that brings the options further down the list into range.
|
|
22
|
+
beforeAll(() => {
|
|
23
|
+
restoreScrollLayout = stubScrollLayout(VIEWPORT_HEIGHT);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
afterAll(() => {
|
|
27
|
+
restoreScrollLayout();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Renders an open autocomplete over a long option list.
|
|
32
|
+
* @param virtualized Whether to mount only the options in view.
|
|
33
|
+
* @returns The testing-library render result.
|
|
34
|
+
*/
|
|
35
|
+
async function renderAutocomplete(virtualized: boolean) {
|
|
36
|
+
const result = render(UiAutocomplete, {
|
|
37
|
+
props: { options, virtualized, defaultOpen: true, placeholder: 'Search' },
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// The scroll container is only measurable once mounted, so the first render
|
|
41
|
+
// still comes out empty.
|
|
42
|
+
await nextTick();
|
|
43
|
+
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
describe('UiAutocomplete virtualized', () => {
|
|
48
|
+
test('mounts only the options in view instead of the whole list', async () => {
|
|
49
|
+
const { getAllByRole } = await renderAutocomplete(true);
|
|
50
|
+
|
|
51
|
+
const rendered = getAllByRole('option');
|
|
52
|
+
expect(rendered.length).toBeGreaterThan(0);
|
|
53
|
+
expect(rendered.length).toBeLessThan(OPTION_COUNT);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('mounts the whole list when virtualization is off', async () => {
|
|
57
|
+
const { getAllByRole } = await renderAutocomplete(false);
|
|
58
|
+
|
|
59
|
+
expect(getAllByRole('option')).toHaveLength(OPTION_COUNT);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Only a fraction of the options is in the DOM, so each one has to carry its
|
|
63
|
+
// place in the full list for screen readers to announce it correctly.
|
|
64
|
+
test('announces the position of an option within the full list', async () => {
|
|
65
|
+
const { getAllByRole } = await renderAutocomplete(true);
|
|
66
|
+
|
|
67
|
+
const [first] = getAllByRole('option');
|
|
68
|
+
expect(first).toHaveAttribute('aria-setsize', String(OPTION_COUNT));
|
|
69
|
+
expect(first).toHaveAttribute('aria-posinset', '1');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('leaves the option list unannotated when virtualization is off', async () => {
|
|
73
|
+
const { getAllByRole } = await renderAutocomplete(false);
|
|
74
|
+
|
|
75
|
+
const [first] = getAllByRole('option');
|
|
76
|
+
expect(first).not.toHaveAttribute('aria-setsize');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// The options are stacked by transform inside a spacer, so the listbox has to
|
|
80
|
+
// scroll over the full list rather than only the mounted slice.
|
|
81
|
+
test('sizes the scroll container for the full list', async () => {
|
|
82
|
+
const { getByRole } = await renderAutocomplete(true);
|
|
83
|
+
|
|
84
|
+
const spacer = getByRole('listbox').firstElementChild as HTMLElement;
|
|
85
|
+
expect(spacer.style.height).toBe(`${OPTION_COUNT * 32}px`);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// The list opens on the selected option, which under virtualization is only
|
|
89
|
+
// in the DOM once it has been scrolled to.
|
|
90
|
+
test('opens on a selection that sits outside the mounted range', async () => {
|
|
91
|
+
const user = userEvent.setup();
|
|
92
|
+
const { getByRole } = render(UiAutocomplete, {
|
|
93
|
+
props: {
|
|
94
|
+
options,
|
|
95
|
+
virtualized: true,
|
|
96
|
+
defaultValue: 'option-400',
|
|
97
|
+
placeholder: 'Search',
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
await user.click(getByRole('textbox'));
|
|
102
|
+
|
|
103
|
+
await waitFor(() => {
|
|
104
|
+
expect(getByRole('option', { name: 'Option 400' })).toBeInTheDocument();
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
});
|
|
@@ -58,6 +58,17 @@ export type UiAutocompleteProps = {
|
|
|
58
58
|
startIcon?: UiIconProps['name'];
|
|
59
59
|
/** Whether to show the default right-side selected indicator. */
|
|
60
60
|
showIndicator?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Whether to mount only the options in view, for lists too long to render at
|
|
63
|
+
* once. Applies to `options` only, not to items provided through the slot.
|
|
64
|
+
*/
|
|
65
|
+
virtualized?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* The expected height of an option in pixels while virtualizing, used to size
|
|
68
|
+
* the scrollbar before the options are measured. Raise it for taller custom
|
|
69
|
+
* items.
|
|
70
|
+
*/
|
|
71
|
+
estimateSize?: number;
|
|
61
72
|
};
|
|
62
73
|
|
|
63
74
|
export type UiAutocompleteEmits = {
|