@aleph-alpha/ui-library 5.8.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 +8 -7
- 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/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/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 +1 -0
- package/dist/system/lib.js +22249 -21090
- package/dist/system/mobile-device-frame.png +0 -0
- 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 +4 -1
- package/package.json +2 -1
- 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/UiDropdownMenu/UiDropdownMenu.stories.ts +760 -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 +121 -0
- package/src/components/UiListbox/UiListboxVirtualizer.vue +42 -0
- 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/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/ListboxItem.vue +1 -1
- package/src/components/index.ts +1 -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,35 @@
|
|
|
1
|
+
export type UiFadeMaskBackground = 'primary' | 'secondary';
|
|
2
|
+
|
|
3
|
+
export type UiFadeMaskPosition = 'top' | 'bottom';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Wraps content and lays a gradient band over one of its edges, so scrolling or
|
|
7
|
+
* clipped content dissolves into the surface instead of ending on a hard cut.
|
|
8
|
+
* Put a scroll container in the slot and the band stays pinned to the wrapper's
|
|
9
|
+
* top or bottom edge.
|
|
10
|
+
*
|
|
11
|
+
* The band is decorative and lets pointer events through, so the wrapped
|
|
12
|
+
* content stays scrollable and clickable underneath it. Its height defaults to
|
|
13
|
+
* 4rem on mobile and 6rem from the medium breakpoint up, and can be retuned per
|
|
14
|
+
* usage with the `--ui-fade-mask-height` custom property.
|
|
15
|
+
* @category Layout
|
|
16
|
+
* @useCases scroll fade, overflow hint, clipped text fade, scroll edge indicator, sticky header backdrop
|
|
17
|
+
* @keywords fade, mask, gradient, scrim, overlay, scroll, overflow, edge
|
|
18
|
+
* @related UiSeparator, UiSheet
|
|
19
|
+
*/
|
|
20
|
+
export interface UiFadeMaskProps {
|
|
21
|
+
/**
|
|
22
|
+
* Surface the gradient fades into. Match it to the background the wrapped
|
|
23
|
+
* content sits on, otherwise the fade ends on a visible edge.
|
|
24
|
+
* @default 'secondary'
|
|
25
|
+
*/
|
|
26
|
+
background?: UiFadeMaskBackground;
|
|
27
|
+
/**
|
|
28
|
+
* Edge the band is pinned to. `top` is opaque at the top and fades downwards,
|
|
29
|
+
* `bottom` is opaque at the bottom and fades upwards. The bottom fade ramps
|
|
30
|
+
* across the whole band on desktop and turns opaque near the top edge on
|
|
31
|
+
* mobile, so it reads the same at both band heights.
|
|
32
|
+
* @default 'top'
|
|
33
|
+
*/
|
|
34
|
+
position?: UiFadeMaskPosition;
|
|
35
|
+
}
|
|
@@ -9,6 +9,7 @@ import UiListboxItem from './UiListboxItem.vue';
|
|
|
9
9
|
import UiListboxItemIndicator from './UiListboxItemIndicator.vue';
|
|
10
10
|
import UiListboxGroup from './UiListboxGroup.vue';
|
|
11
11
|
import UiListboxGroupLabel from './UiListboxGroupLabel.vue';
|
|
12
|
+
import UiListboxVirtualizer from './UiListboxVirtualizer.vue';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* UiListbox is a scrollable, single- or multi-select option list with optional filtering and grouping.
|
|
@@ -528,6 +529,126 @@ export const Scrollable: Story = {
|
|
|
528
529
|
},
|
|
529
530
|
};
|
|
530
531
|
|
|
532
|
+
const virtualizedTemplateSource = `<script setup lang="ts">
|
|
533
|
+
import { ref } from 'vue'
|
|
534
|
+
import {
|
|
535
|
+
UiListbox,
|
|
536
|
+
UiListboxContent,
|
|
537
|
+
UiListboxItem,
|
|
538
|
+
UiListboxItemIndicator,
|
|
539
|
+
UiListboxVirtualizer
|
|
540
|
+
} from '@aleph-alpha/ui-library'
|
|
541
|
+
|
|
542
|
+
const selected = ref('Option 1')
|
|
543
|
+
const options = Array.from({ length: 10000 }, (_, index) => 'Option ' + (index + 1))
|
|
544
|
+
</script>
|
|
545
|
+
|
|
546
|
+
<template>
|
|
547
|
+
<UiListbox v-model="selected" class="w-[220px] p-1">
|
|
548
|
+
<UiListboxContent aria-label="Options">
|
|
549
|
+
<UiListboxVirtualizer v-slot="{ option }" :options="options">
|
|
550
|
+
<UiListboxItem :value="option">
|
|
551
|
+
<span>{{ option }}</span>
|
|
552
|
+
<UiListboxItemIndicator />
|
|
553
|
+
</UiListboxItem>
|
|
554
|
+
</UiListboxVirtualizer>
|
|
555
|
+
</UiListboxContent>
|
|
556
|
+
</UiListbox>
|
|
557
|
+
</template>`;
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* `UiListboxVirtualizer` mounts only the options that are in view, so a list of
|
|
561
|
+
* thousands stays as fast as a short one. The scrollbar, keyboard navigation
|
|
562
|
+
* and type-ahead still cover the full list. Pass `textContent` when the options
|
|
563
|
+
* are objects, so type-ahead knows what to match on, and `estimateSize` when an
|
|
564
|
+
* option is not the default 28px tall.
|
|
565
|
+
*/
|
|
566
|
+
export const Virtualized: Story = {
|
|
567
|
+
render: () => ({
|
|
568
|
+
components: {
|
|
569
|
+
UiListbox,
|
|
570
|
+
UiListboxContent,
|
|
571
|
+
UiListboxItem,
|
|
572
|
+
UiListboxItemIndicator,
|
|
573
|
+
UiListboxVirtualizer,
|
|
574
|
+
},
|
|
575
|
+
setup() {
|
|
576
|
+
const selected = ref('Option 1');
|
|
577
|
+
const options = Array.from(
|
|
578
|
+
{ length: 10000 },
|
|
579
|
+
(_, index) => `Option ${index + 1}`,
|
|
580
|
+
);
|
|
581
|
+
return { selected, options };
|
|
582
|
+
},
|
|
583
|
+
template: `
|
|
584
|
+
<UiListbox v-model="selected" class="w-[220px] p-1">
|
|
585
|
+
<UiListboxContent aria-label="Options">
|
|
586
|
+
<UiListboxVirtualizer v-slot="{ option }" :options="options">
|
|
587
|
+
<UiListboxItem :value="option">
|
|
588
|
+
<span>{{ option }}</span>
|
|
589
|
+
<UiListboxItemIndicator />
|
|
590
|
+
</UiListboxItem>
|
|
591
|
+
</UiListboxVirtualizer>
|
|
592
|
+
</UiListboxContent>
|
|
593
|
+
</UiListbox>
|
|
594
|
+
`,
|
|
595
|
+
}),
|
|
596
|
+
parameters: {
|
|
597
|
+
docs: {
|
|
598
|
+
source: {
|
|
599
|
+
code: virtualizedTemplateSource,
|
|
600
|
+
},
|
|
601
|
+
},
|
|
602
|
+
},
|
|
603
|
+
play: async ({ canvasElement, step }) => {
|
|
604
|
+
// Scenario (List content): a 10,000 option list keeps only the visible
|
|
605
|
+
// options in the DOM, and scrolling swaps in the ones further down while
|
|
606
|
+
// every option keeps its place in the full list.
|
|
607
|
+
const canvas = within(canvasElement);
|
|
608
|
+
const list = canvas.getByRole('listbox', { name: 'Options' });
|
|
609
|
+
|
|
610
|
+
await step(
|
|
611
|
+
'interaction: only the options in view are in the DOM',
|
|
612
|
+
async () => {
|
|
613
|
+
const rendered = canvas.getAllByRole('option');
|
|
614
|
+
await expect(rendered.length).toBeGreaterThan(0);
|
|
615
|
+
await expect(rendered.length).toBeLessThan(100);
|
|
616
|
+
},
|
|
617
|
+
);
|
|
618
|
+
|
|
619
|
+
await step(
|
|
620
|
+
'screen-reader: an option announces its place in the full list (WCAG 4.1.2)',
|
|
621
|
+
async () => {
|
|
622
|
+
const first = canvas.getByRole('option', { name: 'Option 1' });
|
|
623
|
+
await expect(first).toHaveAttribute('aria-setsize', '10000');
|
|
624
|
+
await expect(first).toHaveAttribute('aria-posinset', '1');
|
|
625
|
+
},
|
|
626
|
+
);
|
|
627
|
+
|
|
628
|
+
await step(
|
|
629
|
+
'interaction: scrolling mounts the options further down the list',
|
|
630
|
+
async () => {
|
|
631
|
+
list.scrollTop = list.scrollHeight;
|
|
632
|
+
await waitFor(async () => {
|
|
633
|
+
await expect(
|
|
634
|
+
canvas.getByRole('option', { name: 'Option 10000' }),
|
|
635
|
+
).toBeVisible();
|
|
636
|
+
});
|
|
637
|
+
await expect(canvas.queryByRole('option', { name: 'Option 1' })).toBe(
|
|
638
|
+
null,
|
|
639
|
+
);
|
|
640
|
+
// Restore the resting state so the visual snapshot stays stable.
|
|
641
|
+
list.scrollTop = 0;
|
|
642
|
+
await waitFor(async () => {
|
|
643
|
+
await expect(
|
|
644
|
+
canvas.getByRole('option', { name: 'Option 1' }),
|
|
645
|
+
).toBeVisible();
|
|
646
|
+
});
|
|
647
|
+
},
|
|
648
|
+
);
|
|
649
|
+
},
|
|
650
|
+
};
|
|
651
|
+
|
|
531
652
|
const emptyStateTemplateSource = `<script setup lang="ts">
|
|
532
653
|
import { ref } from 'vue'
|
|
533
654
|
import { UiListbox, UiListboxContent } from '@aleph-alpha/ui-library'
|
|
@@ -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>
|
|
@@ -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
|