@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,42 @@
|
|
|
1
|
+
<script setup lang="ts" generic="T extends AcceptableValue">
|
|
2
|
+
import type { AcceptableValue } from 'reka-ui';
|
|
3
|
+
import { ListboxVirtualizer } from 'reka-ui';
|
|
4
|
+
import {
|
|
5
|
+
type UiListboxVirtualizerProps,
|
|
6
|
+
type UiListboxVirtualizerSlotProps,
|
|
7
|
+
} from './types';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Unlike the other listbox parts, this one wraps reka-ui directly instead of
|
|
11
|
+
* going through `core/listbox`. reka-ui clones the first node of the slot to
|
|
12
|
+
* position the option and label it with its index, and it looks through a
|
|
13
|
+
* single layer of slot forwarding only, so a second wrapper would leave it
|
|
14
|
+
* cloning an empty fragment.
|
|
15
|
+
*/
|
|
16
|
+
defineOptions({
|
|
17
|
+
name: 'UiListboxVirtualizer',
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const props = defineProps<UiListboxVirtualizerProps<T>>();
|
|
21
|
+
|
|
22
|
+
defineSlots<{
|
|
23
|
+
/** A single option, which has to render exactly one `UiListboxItem`. */
|
|
24
|
+
default(props: UiListboxVirtualizerSlotProps<T>): unknown;
|
|
25
|
+
}>();
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<template>
|
|
29
|
+
<!--
|
|
30
|
+
reka-ui positions each option absolutely, which shrinks it to its content,
|
|
31
|
+
so the options are stretched back to the row width to keep hover and
|
|
32
|
+
selection as wide as in a plain list.
|
|
33
|
+
-->
|
|
34
|
+
<ListboxVirtualizer
|
|
35
|
+
v-slot="{ option, virtualItem }"
|
|
36
|
+
data-slot="listbox-virtualizer"
|
|
37
|
+
class="[&>*]:w-full"
|
|
38
|
+
v-bind="props"
|
|
39
|
+
>
|
|
40
|
+
<slot :option="option" :index="virtualItem.index" />
|
|
41
|
+
</ListboxVirtualizer>
|
|
42
|
+
</template>
|
|
@@ -1,46 +1,81 @@
|
|
|
1
1
|
import { render } from '@testing-library/vue';
|
|
2
2
|
import { describe, expect, test } from 'vitest';
|
|
3
|
+
import { nextTick } from 'vue';
|
|
3
4
|
import UiListbox from '../UiListbox.vue';
|
|
4
5
|
import UiListboxContent from '../UiListboxContent.vue';
|
|
5
6
|
import UiListboxItem from '../UiListboxItem.vue';
|
|
6
|
-
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Renders a two-option listbox.
|
|
10
|
+
* @param listboxAttrs Extra attributes for the listbox root.
|
|
11
|
+
* @param itemAttrs Extra attributes for the second option.
|
|
12
|
+
* @returns The testing-library render result.
|
|
13
|
+
*/
|
|
14
|
+
function renderListbox(listboxAttrs = '', itemAttrs = '') {
|
|
15
|
+
return render({
|
|
16
|
+
components: { UiListbox, UiListboxContent, UiListboxItem },
|
|
17
|
+
template: `
|
|
18
|
+
<UiListbox model-value="apple" ${listboxAttrs}>
|
|
19
|
+
<UiListboxContent aria-label="Fruits">
|
|
20
|
+
<UiListboxItem value="apple">Apple</UiListboxItem>
|
|
21
|
+
<UiListboxItem value="banana" ${itemAttrs}>Banana</UiListboxItem>
|
|
22
|
+
</UiListboxContent>
|
|
23
|
+
</UiListbox>
|
|
24
|
+
`,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
7
27
|
|
|
8
28
|
describe('UiListbox', () => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
expect(
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
// reka-ui only renders `data-disabled` for styling, so the wrapper mirrors
|
|
30
|
+
// the state onto `aria-disabled` for assistive technology.
|
|
31
|
+
test('marks the list and every option as disabled when the listbox is disabled', () => {
|
|
32
|
+
const { getByRole, getAllByRole } = renderListbox('disabled');
|
|
33
|
+
|
|
34
|
+
expect(getByRole('listbox', { name: 'Fruits' })).toHaveAttribute(
|
|
35
|
+
'aria-disabled',
|
|
36
|
+
'true',
|
|
37
|
+
);
|
|
38
|
+
for (const option of getAllByRole('option')) {
|
|
39
|
+
expect(option).toHaveAttribute('aria-disabled', 'true');
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('marks only the disabled option when a single option is disabled', () => {
|
|
44
|
+
const { getByRole } = renderListbox('', 'disabled');
|
|
45
|
+
|
|
46
|
+
expect(getByRole('listbox', { name: 'Fruits' })).not.toHaveAttribute(
|
|
47
|
+
'aria-disabled',
|
|
48
|
+
);
|
|
49
|
+
expect(getByRole('option', { name: 'Banana' })).toHaveAttribute(
|
|
50
|
+
'aria-disabled',
|
|
51
|
+
'true',
|
|
52
|
+
);
|
|
53
|
+
expect(getByRole('option', { name: 'Apple' })).not.toHaveAttribute(
|
|
54
|
+
'aria-disabled',
|
|
55
|
+
);
|
|
32
56
|
});
|
|
33
57
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
)
|
|
58
|
+
// reka-ui derives the container tabindex from its roving-focus state alone,
|
|
59
|
+
// which left a disabled listbox in the tab order, where it picked up the
|
|
60
|
+
// browser's default focus ring.
|
|
61
|
+
test('takes a disabled listbox out of the tab order', async () => {
|
|
62
|
+
const { getByRole } = renderListbox('disabled');
|
|
63
|
+
await nextTick();
|
|
64
|
+
|
|
65
|
+
expect(getByRole('listbox', { name: 'Fruits' })).toHaveAttribute(
|
|
66
|
+
'tabindex',
|
|
67
|
+
'-1',
|
|
68
|
+
);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('leaves an enabled listbox without a disabled state', () => {
|
|
72
|
+
const { getByRole, getAllByRole } = renderListbox();
|
|
73
|
+
|
|
74
|
+
expect(getByRole('listbox', { name: 'Fruits' })).not.toHaveAttribute(
|
|
75
|
+
'aria-disabled',
|
|
76
|
+
);
|
|
77
|
+
for (const option of getAllByRole('option')) {
|
|
78
|
+
expect(option).not.toHaveAttribute('aria-disabled');
|
|
79
|
+
}
|
|
45
80
|
});
|
|
46
81
|
});
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { render } from '@testing-library/vue';
|
|
2
|
+
import { afterAll, beforeAll, describe, expect, test } from 'vitest';
|
|
3
|
+
import { nextTick } from 'vue';
|
|
4
|
+
import UiListbox from '../UiListbox.vue';
|
|
5
|
+
import UiListboxContent from '../UiListboxContent.vue';
|
|
6
|
+
import UiListboxItem from '../UiListboxItem.vue';
|
|
7
|
+
import UiListboxVirtualizer from '../UiListboxVirtualizer.vue';
|
|
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
|
+
// The virtualizer derives its range from the measured height of the scroll
|
|
18
|
+
// container, and jsdom lays nothing out, so every element reports zero height
|
|
19
|
+
// and no option would ever come into range.
|
|
20
|
+
beforeAll(() => {
|
|
21
|
+
Object.defineProperty(HTMLElement.prototype, 'offsetHeight', {
|
|
22
|
+
configurable: true,
|
|
23
|
+
get: () => VIEWPORT_HEIGHT,
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
afterAll(() => {
|
|
28
|
+
Reflect.deleteProperty(HTMLElement.prototype, 'offsetHeight');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Renders a virtualized listbox over a long option list.
|
|
33
|
+
* @returns The testing-library render result.
|
|
34
|
+
*/
|
|
35
|
+
async function renderVirtualizedListbox() {
|
|
36
|
+
const result = render({
|
|
37
|
+
components: {
|
|
38
|
+
UiListbox,
|
|
39
|
+
UiListboxContent,
|
|
40
|
+
UiListboxItem,
|
|
41
|
+
UiListboxVirtualizer,
|
|
42
|
+
},
|
|
43
|
+
setup: () => ({ options }),
|
|
44
|
+
template: `
|
|
45
|
+
<UiListbox model-value="option-1">
|
|
46
|
+
<UiListboxContent aria-label="Options">
|
|
47
|
+
<UiListboxVirtualizer
|
|
48
|
+
v-slot="{ option }"
|
|
49
|
+
:options="options"
|
|
50
|
+
:text-content="(option) => option.label"
|
|
51
|
+
>
|
|
52
|
+
<UiListboxItem :value="option">{{ option.label }}</UiListboxItem>
|
|
53
|
+
</UiListboxVirtualizer>
|
|
54
|
+
</UiListboxContent>
|
|
55
|
+
</UiListbox>
|
|
56
|
+
`,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// The scroll container is only measurable once mounted, so the first render
|
|
60
|
+
// still comes out empty.
|
|
61
|
+
await nextTick();
|
|
62
|
+
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
describe('UiListboxVirtualizer', () => {
|
|
67
|
+
test('mounts only the options in view instead of the whole list', async () => {
|
|
68
|
+
const { getAllByRole } = await renderVirtualizedListbox();
|
|
69
|
+
|
|
70
|
+
const rendered = getAllByRole('option');
|
|
71
|
+
expect(rendered.length).toBeGreaterThan(0);
|
|
72
|
+
expect(rendered.length).toBeLessThan(OPTION_COUNT);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// Only a fraction of the options is in the DOM, so each one has to carry its
|
|
76
|
+
// place in the full list for screen readers to announce it correctly.
|
|
77
|
+
test('announces the position of an option within the full list', async () => {
|
|
78
|
+
const { getAllByRole } = await renderVirtualizedListbox();
|
|
79
|
+
|
|
80
|
+
const [first] = getAllByRole('option');
|
|
81
|
+
expect(first).toHaveAttribute('aria-setsize', String(OPTION_COUNT));
|
|
82
|
+
expect(first).toHaveAttribute('aria-posinset', '1');
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// The virtualizer positions the options it mounts, and finds them again by
|
|
86
|
+
// index for type-ahead and Home/End, both of which it applies to the option
|
|
87
|
+
// element itself rather than to any wrapper around it.
|
|
88
|
+
test('positions every mounted option and keeps it addressable by index', async () => {
|
|
89
|
+
const { getAllByRole } = await renderVirtualizedListbox();
|
|
90
|
+
|
|
91
|
+
for (const [index, option] of getAllByRole('option').entries()) {
|
|
92
|
+
expect(option).toHaveAttribute('data-index', String(index));
|
|
93
|
+
expect(option.style.position).toBe('absolute');
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -3,6 +3,7 @@ export { default as UiListboxContent } from './UiListboxContent.vue';
|
|
|
3
3
|
export { default as UiListboxFilter } from './UiListboxFilter.vue';
|
|
4
4
|
export { default as UiListboxItem } from './UiListboxItem.vue';
|
|
5
5
|
export { default as UiListboxItemIndicator } from './UiListboxItemIndicator.vue';
|
|
6
|
+
export { default as UiListboxVirtualizer } from './UiListboxVirtualizer.vue';
|
|
6
7
|
export { default as UiListboxGroup } from './UiListboxGroup.vue';
|
|
7
8
|
export { default as UiListboxGroupLabel } from './UiListboxGroupLabel.vue';
|
|
8
9
|
export type * from './types';
|
|
@@ -90,6 +90,48 @@ export interface UiListboxItemProps {
|
|
|
90
90
|
disabled?: boolean;
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Props for the UiListboxVirtualizer component.
|
|
95
|
+
* Renders only the options in view, for lists too long to mount at once.
|
|
96
|
+
*/
|
|
97
|
+
export interface UiListboxVirtualizerProps<
|
|
98
|
+
T extends AcceptableValue = AcceptableValue,
|
|
99
|
+
> {
|
|
100
|
+
/**
|
|
101
|
+
* The full list of options to virtualize.
|
|
102
|
+
*/
|
|
103
|
+
options: T[];
|
|
104
|
+
/**
|
|
105
|
+
* How many options to render outside the visible area, as a scroll buffer.
|
|
106
|
+
* @default 12
|
|
107
|
+
*/
|
|
108
|
+
overscan?: number;
|
|
109
|
+
/**
|
|
110
|
+
* The expected height of an option in pixels, used to size the scrollbar
|
|
111
|
+
* before the options are measured.
|
|
112
|
+
* @default 28
|
|
113
|
+
*/
|
|
114
|
+
estimateSize?: number | ((index: number) => number);
|
|
115
|
+
/**
|
|
116
|
+
* The text of an option, used for type-ahead. Required for object options,
|
|
117
|
+
* which have no meaningful string form.
|
|
118
|
+
*/
|
|
119
|
+
textContent?: (option: T) => string;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Slot props for the UiListboxVirtualizer default slot.
|
|
124
|
+
* Describes the option to render.
|
|
125
|
+
*/
|
|
126
|
+
export interface UiListboxVirtualizerSlotProps<
|
|
127
|
+
T extends AcceptableValue = AcceptableValue,
|
|
128
|
+
> {
|
|
129
|
+
/** The option to render. */
|
|
130
|
+
option: T;
|
|
131
|
+
/** The position of the option in the full list, starting at 0. */
|
|
132
|
+
index: number;
|
|
133
|
+
}
|
|
134
|
+
|
|
93
135
|
/**
|
|
94
136
|
* Props for the UiListboxItemIndicator component.
|
|
95
137
|
* Displays a visual indicator when the item is selected.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/vue3-vite';
|
|
2
2
|
import { expect, userEvent, waitFor, within } from 'storybook/test';
|
|
3
|
-
import { ref } from 'vue';
|
|
3
|
+
import { computed, ref } from 'vue';
|
|
4
4
|
import {
|
|
5
5
|
UiSelect,
|
|
6
6
|
UiSelectTrigger,
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
UiSelectLabel,
|
|
11
11
|
UiSelectGroup,
|
|
12
12
|
UiSelectSeparator,
|
|
13
|
+
UiSelectVirtualizer,
|
|
13
14
|
} from './index';
|
|
14
15
|
import { UiIcon } from '@/components/UiIcon';
|
|
15
16
|
|
|
@@ -880,6 +881,113 @@ async function waitForDropdownClosed(body: ReturnType<typeof within>) {
|
|
|
880
881
|
});
|
|
881
882
|
}
|
|
882
883
|
|
|
884
|
+
/**
|
|
885
|
+
* Long option lists can be handed to `UiSelectVirtualizer`, which mounts only
|
|
886
|
+
* the options in view. Arrow keys, Home, End and type-ahead still move through
|
|
887
|
+
* the full list, and the select opens on the current selection wherever it sits.
|
|
888
|
+
*
|
|
889
|
+
* The trigger reads its label from the options it has mounted, and a virtualized
|
|
890
|
+
* list has mounted none of them while it is closed, so the label for the current
|
|
891
|
+
* value is passed to `UiSelectValue` from the same data the list is built from.
|
|
892
|
+
*/
|
|
893
|
+
export const Virtualized: Story = {
|
|
894
|
+
render: () => ({
|
|
895
|
+
components: {
|
|
896
|
+
UiSelect,
|
|
897
|
+
UiSelectTrigger,
|
|
898
|
+
UiSelectContent,
|
|
899
|
+
UiSelectItem,
|
|
900
|
+
UiSelectValue,
|
|
901
|
+
UiSelectVirtualizer,
|
|
902
|
+
},
|
|
903
|
+
setup() {
|
|
904
|
+
const selected = ref('option-5000');
|
|
905
|
+
const options = Array.from({ length: 10000 }, (_, index) => ({
|
|
906
|
+
value: `option-${index + 1}`,
|
|
907
|
+
label: `Option ${index + 1}`,
|
|
908
|
+
}));
|
|
909
|
+
const selectedLabel = computed(
|
|
910
|
+
() =>
|
|
911
|
+
options.find((option) => option.value === selected.value)?.label ??
|
|
912
|
+
'Select option',
|
|
913
|
+
);
|
|
914
|
+
return { selected, options, selectedLabel };
|
|
915
|
+
},
|
|
916
|
+
template: `
|
|
917
|
+
<UiSelect v-model="selected">
|
|
918
|
+
<UiSelectTrigger class="w-[220px]" ariaLabel="Select option">
|
|
919
|
+
<UiSelectValue placeholder="Select option">
|
|
920
|
+
{{ selectedLabel }}
|
|
921
|
+
</UiSelectValue>
|
|
922
|
+
</UiSelectTrigger>
|
|
923
|
+
<UiSelectContent>
|
|
924
|
+
<UiSelectVirtualizer
|
|
925
|
+
v-slot="{ option }"
|
|
926
|
+
:options="options"
|
|
927
|
+
:option-value="(option) => option.value"
|
|
928
|
+
:text-content="(option) => option.label"
|
|
929
|
+
>
|
|
930
|
+
<UiSelectItem :value="option.value">{{ option.label }}</UiSelectItem>
|
|
931
|
+
</UiSelectVirtualizer>
|
|
932
|
+
</UiSelectContent>
|
|
933
|
+
</UiSelect>
|
|
934
|
+
`,
|
|
935
|
+
}),
|
|
936
|
+
play: async ({ canvasElement, step }) => {
|
|
937
|
+
// Scenario (UiSelect): a 10,000 option select keeps only the visible
|
|
938
|
+
// options in the DOM, opens on the current selection, and still reaches the
|
|
939
|
+
// end of the list from the keyboard.
|
|
940
|
+
const canvas = within(canvasElement);
|
|
941
|
+
const body = within(document.body);
|
|
942
|
+
const trigger = canvas.getByRole('combobox');
|
|
943
|
+
|
|
944
|
+
await userEvent.click(trigger);
|
|
945
|
+
await findOpenListbox(body);
|
|
946
|
+
|
|
947
|
+
await step(
|
|
948
|
+
'interaction: only the options in view are in the DOM',
|
|
949
|
+
async () => {
|
|
950
|
+
const rendered = body.getAllByRole('option');
|
|
951
|
+
await expect(rendered.length).toBeGreaterThan(0);
|
|
952
|
+
await expect(rendered.length).toBeLessThan(100);
|
|
953
|
+
},
|
|
954
|
+
);
|
|
955
|
+
|
|
956
|
+
await step('interaction: the list opens on the selection', async () => {
|
|
957
|
+
await waitFor(async () => {
|
|
958
|
+
await expect(
|
|
959
|
+
body.getByRole('option', { name: 'Option 5000' }),
|
|
960
|
+
).toHaveFocus();
|
|
961
|
+
});
|
|
962
|
+
});
|
|
963
|
+
|
|
964
|
+
await step(
|
|
965
|
+
'screen-reader: an option announces its place in the full list (WCAG 4.1.2)',
|
|
966
|
+
async () => {
|
|
967
|
+
const option = body.getByRole('option', { name: 'Option 5000' });
|
|
968
|
+
await expect(option).toHaveAttribute('aria-setsize', '10000');
|
|
969
|
+
await expect(option).toHaveAttribute('aria-posinset', '5000');
|
|
970
|
+
},
|
|
971
|
+
);
|
|
972
|
+
|
|
973
|
+
await step(
|
|
974
|
+
'keyboard: End reaches the last option of the full list (WCAG 2.1.1)',
|
|
975
|
+
async () => {
|
|
976
|
+
await userEvent.keyboard('{End}');
|
|
977
|
+
await waitFor(async () => {
|
|
978
|
+
await expect(
|
|
979
|
+
body.getByRole('option', { name: 'Option 10000' }),
|
|
980
|
+
).toHaveFocus();
|
|
981
|
+
});
|
|
982
|
+
|
|
983
|
+
// Close again so the end-of-play axe audit sees the resting state.
|
|
984
|
+
await userEvent.keyboard('{Escape}');
|
|
985
|
+
await waitForDropdownClosed(body);
|
|
986
|
+
},
|
|
987
|
+
);
|
|
988
|
+
},
|
|
989
|
+
};
|
|
990
|
+
|
|
883
991
|
/**
|
|
884
992
|
* Accessibility guidance for selects: an accessible trigger name, labelled
|
|
885
993
|
* groups, and visible disabled options — shown side by side in the default
|