@aleph-alpha/ui-library 2.10.0 → 2.11.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/dist/system/components/UiAutocomplete/UiAutocomplete.vue.d.ts +0 -1
- package/dist/system/components/UiAutocomplete/types.d.ts +0 -2
- package/dist/system/components/UiSelect/UiSelect.vue.d.ts +4 -5
- package/dist/system/components/UiSelect/UiSelectContent.vue.d.ts +0 -1
- package/dist/system/components/UiSelect/UiSelectItem.vue.d.ts +2 -9
- package/dist/system/components/UiSelect/UiSelectTrigger.vue.d.ts +0 -2
- package/dist/system/components/UiSelect/UiSelectValue.vue.d.ts +0 -3
- package/dist/system/components/UiSelect/types.d.ts +26 -6
- package/dist/system/lib.js +18370 -18530
- package/package.json +1 -1
- package/src/components/UiAutocomplete/UiAutocomplete.vue +9 -9
- package/src/components/UiAutocomplete/__tests__/UiAutocomplete.test.ts +76 -5
- package/src/components/UiAutocomplete/types.ts +0 -2
- package/src/components/UiSelect/UiSelect.stories.ts +4 -90
- package/src/components/UiSelect/UiSelect.vue +66 -144
- package/src/components/UiSelect/UiSelectContent.vue +10 -21
- package/src/components/UiSelect/UiSelectItem.vue +0 -82
- package/src/components/UiSelect/UiSelectTrigger.vue +1 -62
- package/src/components/UiSelect/UiSelectValue.vue +1 -47
- package/src/components/UiSelect/__tests__/UiSelect.test.ts +47 -98
- package/src/components/UiSelect/__tests__/UiSelectContent.test.ts +36 -3
- package/src/components/UiSelect/__tests__/UiSelectItem.test.ts +1 -1
- package/src/components/UiSelect/__tests__/UiSelectTrigger.test.ts +2 -2
- package/src/components/UiSelect/types.ts +29 -6
- package/dist/system/components/UiSelect/context.d.ts +0 -28
- package/src/components/UiSelect/context.ts +0 -42
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
|
3
2
|
import { SelectItem as ShadcnSelectItem } from '@/components/core/select';
|
|
4
|
-
import {
|
|
5
|
-
ListboxItem as ShadcnListboxItem,
|
|
6
|
-
ListboxItemIndicator as ShadcnListboxItemIndicator,
|
|
7
|
-
} from '@/components/core/listbox';
|
|
8
|
-
import { UiIcon } from '@/components/UiIcon';
|
|
9
|
-
import { useUiSelectContext } from './context';
|
|
10
3
|
import type { UiSelectItemProps } from './types';
|
|
11
4
|
|
|
12
5
|
defineOptions({
|
|
@@ -17,62 +10,10 @@ const props = withDefaults(defineProps<UiSelectItemProps>(), {
|
|
|
17
10
|
disabled: false,
|
|
18
11
|
textValue: undefined,
|
|
19
12
|
});
|
|
20
|
-
|
|
21
|
-
const ctx = useUiSelectContext();
|
|
22
|
-
|
|
23
|
-
// ----- Multi-select label registration -----
|
|
24
|
-
// We expose the rendered slot's text to the trigger via the shared
|
|
25
|
-
// `itemLabels` registry so `UiSelectValue` can render comma-separated
|
|
26
|
-
// labels for the selected values without consumers having to provide a
|
|
27
|
-
// separate label map.
|
|
28
|
-
const labelEl = ref<HTMLElement | null>(null);
|
|
29
|
-
|
|
30
|
-
function readLabel(): string {
|
|
31
|
-
return labelEl.value?.textContent?.trim() || props.textValue || props.value;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function syncLabel() {
|
|
35
|
-
if (ctx.mode !== 'multiple' || !ctx.multiple) return;
|
|
36
|
-
ctx.multiple.itemLabels.value.set(props.value, readLabel());
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
onMounted(syncLabel);
|
|
40
|
-
|
|
41
|
-
// When `props.value` changes, the entry registered under the OLD key
|
|
42
|
-
// becomes orphaned — `syncLabel()` only writes to the NEW key, so
|
|
43
|
-
// without an explicit delete the registry would accumulate stale
|
|
44
|
-
// mappings. That manifests two ways for consumers:
|
|
45
|
-
// 1. The trigger can render a stale label for a value that's no
|
|
46
|
-
// longer a real option (because `UiSelectValue` happily reads
|
|
47
|
-
// whatever the registry still has under that key).
|
|
48
|
-
// 2. For dynamic option lists (e.g. `<UiSelectItem v-for>` driven
|
|
49
|
-
// by remote data), the map grows unbounded.
|
|
50
|
-
// Use the watcher's `(next, prev)` signature to drop the previous
|
|
51
|
-
// key before re-registering under the new one.
|
|
52
|
-
watch(
|
|
53
|
-
() => props.value,
|
|
54
|
-
(next, prev) => {
|
|
55
|
-
if (ctx.mode !== 'multiple' || !ctx.multiple) return;
|
|
56
|
-
if (prev !== undefined && prev !== next) {
|
|
57
|
-
ctx.multiple.itemLabels.value.delete(prev);
|
|
58
|
-
}
|
|
59
|
-
ctx.multiple.itemLabels.value.set(next, readLabel());
|
|
60
|
-
},
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
// `textValue` only affects the label string under the same key,
|
|
64
|
-
// so a plain re-sync is sufficient (no stale key to clean up).
|
|
65
|
-
watch(() => props.textValue, syncLabel);
|
|
66
|
-
|
|
67
|
-
onBeforeUnmount(() => {
|
|
68
|
-
if (ctx.mode !== 'multiple' || !ctx.multiple) return;
|
|
69
|
-
ctx.multiple.itemLabels.value.delete(props.value);
|
|
70
|
-
});
|
|
71
13
|
</script>
|
|
72
14
|
|
|
73
15
|
<template>
|
|
74
16
|
<ShadcnSelectItem
|
|
75
|
-
v-if="ctx.mode === 'single'"
|
|
76
17
|
:value="props.value"
|
|
77
18
|
:disabled="props.disabled"
|
|
78
19
|
:text-value="props.textValue"
|
|
@@ -85,27 +26,4 @@ onBeforeUnmount(() => {
|
|
|
85
26
|
</template>
|
|
86
27
|
<slot />
|
|
87
28
|
</ShadcnSelectItem>
|
|
88
|
-
|
|
89
|
-
<ShadcnListboxItem
|
|
90
|
-
v-else
|
|
91
|
-
:value="props.value"
|
|
92
|
-
:disabled="props.disabled"
|
|
93
|
-
:text-value="props.textValue"
|
|
94
|
-
class="hover-layer hover-layer-default focus:text-foreground data-[highlighted]:text-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-12 pl-2 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50"
|
|
95
|
-
>
|
|
96
|
-
<span ref="labelEl" class="flex items-center gap-2">
|
|
97
|
-
<slot />
|
|
98
|
-
</span>
|
|
99
|
-
<span
|
|
100
|
-
class="!absolute right-2 flex items-center justify-center gap-1"
|
|
101
|
-
data-slot="select-item-end"
|
|
102
|
-
>
|
|
103
|
-
<slot name="right-icon" />
|
|
104
|
-
<ShadcnListboxItemIndicator>
|
|
105
|
-
<slot name="indicator-icon">
|
|
106
|
-
<UiIcon name="check" :size="16" />
|
|
107
|
-
</slot>
|
|
108
|
-
</ShadcnListboxItemIndicator>
|
|
109
|
-
</span>
|
|
110
|
-
</ShadcnListboxItem>
|
|
111
29
|
</template>
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { computed } from 'vue';
|
|
3
2
|
import { SelectTrigger as ShadcnSelectTrigger } from '@/components/core/select';
|
|
4
|
-
import { PopoverTrigger as ShadcnPopoverTrigger } from '@/components/core/popover';
|
|
5
|
-
import { UiIcon } from '@/components/UiIcon';
|
|
6
|
-
import { cn } from '@/lib/utils';
|
|
7
|
-
import { useUiSelectContext } from './context';
|
|
8
3
|
import type { UiSelectTriggerProps } from './types';
|
|
9
4
|
|
|
10
5
|
defineOptions({
|
|
@@ -14,76 +9,20 @@ defineOptions({
|
|
|
14
9
|
const props = withDefaults(defineProps<UiSelectTriggerProps>(), {
|
|
15
10
|
ariaLabel: undefined,
|
|
16
11
|
disabled: false,
|
|
17
|
-
size: 'default',
|
|
18
12
|
});
|
|
19
13
|
|
|
20
|
-
const ctx = useUiSelectContext();
|
|
21
|
-
|
|
22
|
-
// Mirror reka-ui SelectTrigger's `data-placeholder` attribute on our
|
|
23
|
-
// popover-backed multi-select trigger. Single-select gets this from
|
|
24
|
-
// SelectTrigger itself (when no value is selected). Without it the
|
|
25
|
-
// trigger keeps `bg-accent` and looks "active"/blue even when empty,
|
|
26
|
-
// because the `data-[placeholder]:bg-background-input-default` rule
|
|
27
|
-
// in `multiTriggerClasses` never matches.
|
|
28
|
-
const isMultiPlaceholder = computed(
|
|
29
|
-
() =>
|
|
30
|
-
ctx.mode === 'multiple' &&
|
|
31
|
-
(ctx.multiple?.selectedValues.value.length ?? 0) === 0,
|
|
32
|
-
);
|
|
33
|
-
const singleAriaLabel = computed(() => props.ariaLabel);
|
|
34
|
-
const multiAriaLabel = computed(
|
|
35
|
-
() =>
|
|
36
|
-
props.ariaLabel ??
|
|
37
|
-
(isMultiPlaceholder.value ? 'Select options' : undefined),
|
|
38
|
-
);
|
|
39
|
-
|
|
40
14
|
// shadcn trigger styles target only SVG icons (`[&_svg]...`) but our icons are spans (`data-slot="icon"`).
|
|
41
15
|
// Add equivalent sizing/behavior + rotate-on-open for the chevron.
|
|
42
16
|
const uiIconTriggerClasses =
|
|
43
17
|
'[&_[data-slot=icon]]:pointer-events-none [&_[data-slot=icon]]:shrink-0 [&_[data-slot=icon]]:transition-transform [&_[data-slot=icon]]:duration-200 [&[data-state=open]_[data-slot=icon]]:rotate-180';
|
|
44
|
-
|
|
45
|
-
// In multi-select mode, we render a Popover instead of reka-ui's Select, so
|
|
46
|
-
// we have to recreate the SelectTrigger button (incl. the styling that
|
|
47
|
-
// SelectTrigger.vue applies under the hood) and append the chevron icon
|
|
48
|
-
// ourselves to keep the visual parity with single-select.
|
|
49
|
-
//
|
|
50
|
-
// Two deliberate differences from single-select:
|
|
51
|
-
// - No `w-fit`: the trigger width must NOT grow with the selected
|
|
52
|
-
// labels. Consumers control the width via `min-w-*` / `w-*` classes
|
|
53
|
-
// (see stories). `max-w-full` keeps it from overflowing its parent.
|
|
54
|
-
// - No `whitespace-nowrap` on the trigger itself — we move single-line
|
|
55
|
-
// + ellipsis behavior down to the UiSelectValue span so it can
|
|
56
|
-
// truncate inside the flex row instead of forcing the button wider.
|
|
57
|
-
const multiTriggerClasses = computed(() =>
|
|
58
|
-
cn(
|
|
59
|
-
"border-input data-[placeholder]:text-muted-foreground data-[placeholder]:bg-background-input-default [&:not([data-placeholder])]:border-border-surface-focus-ring [&_svg:not([class*='text-'])]:text-muted-foreground focus:border-border-surface-focus-ring focus-visible:border-border-surface-focus-ring active:border-border-surface-focus-ring data-[state=open]:border-border-surface-focus-ring focus:ring-ring/50 focus-visible:ring-ring/50 focus:shadow-xs focus-visible:shadow-xs aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive flex max-w-full items-center justify-between gap-2 rounded-md border bg-accent px-3 py-2 text-sm transition-[color,box-shadow] outline-none focus:ring-[3px] focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 *:data-[slot=select-value]:min-w-0 *:data-[slot=select-value]:flex-1 *:data-[slot=select-value]:truncate [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([data-slot=icon]):not([class*='size-'])]:size-4",
|
|
60
|
-
props.size === 'default' ? 'h-9' : 'h-8',
|
|
61
|
-
uiIconTriggerClasses,
|
|
62
|
-
),
|
|
63
|
-
);
|
|
64
18
|
</script>
|
|
65
19
|
|
|
66
20
|
<template>
|
|
67
21
|
<ShadcnSelectTrigger
|
|
68
|
-
v-if="ctx.mode === 'single'"
|
|
69
22
|
:disabled="props.disabled"
|
|
70
|
-
:
|
|
71
|
-
:aria-label="singleAriaLabel"
|
|
23
|
+
:aria-label="props.ariaLabel"
|
|
72
24
|
:class="uiIconTriggerClasses"
|
|
73
25
|
>
|
|
74
26
|
<slot />
|
|
75
27
|
</ShadcnSelectTrigger>
|
|
76
|
-
|
|
77
|
-
<ShadcnPopoverTrigger
|
|
78
|
-
v-else
|
|
79
|
-
data-slot="select-trigger"
|
|
80
|
-
:data-size="props.size"
|
|
81
|
-
:data-placeholder="isMultiPlaceholder ? '' : undefined"
|
|
82
|
-
:disabled="props.disabled"
|
|
83
|
-
:aria-label="multiAriaLabel"
|
|
84
|
-
:class="multiTriggerClasses"
|
|
85
|
-
>
|
|
86
|
-
<slot />
|
|
87
|
-
<UiIcon name="chevron-down" :size="16" class="opacity-50" />
|
|
88
|
-
</ShadcnPopoverTrigger>
|
|
89
28
|
</template>
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { computed } from 'vue';
|
|
3
2
|
import { SelectValue as ShadcnSelectValue } from '@/components/core/select';
|
|
4
|
-
import { useUiSelectContext } from './context';
|
|
5
3
|
import type { UiSelectValueProps } from './types';
|
|
6
4
|
|
|
7
5
|
defineOptions({
|
|
@@ -11,54 +9,10 @@ defineOptions({
|
|
|
11
9
|
const props = withDefaults(defineProps<UiSelectValueProps>(), {
|
|
12
10
|
placeholder: undefined,
|
|
13
11
|
});
|
|
14
|
-
|
|
15
|
-
const ctx = useUiSelectContext();
|
|
16
|
-
|
|
17
|
-
// Multi-select: derive the displayed text from the registry of item
|
|
18
|
-
// labels populated by `UiSelectItem`. We keep the selection order
|
|
19
|
-
// (i.e. the order returned by Listbox) for consistent output.
|
|
20
|
-
const displayText = computed(() => {
|
|
21
|
-
if (ctx.mode !== 'multiple' || !ctx.multiple) return '';
|
|
22
|
-
const labels = ctx.multiple.itemLabels.value;
|
|
23
|
-
return ctx.multiple.selectedValues.value
|
|
24
|
-
.map((value) => labels.get(value) ?? value)
|
|
25
|
-
.join(', ');
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
const hasSelection = computed(
|
|
29
|
-
() =>
|
|
30
|
-
ctx.mode === 'multiple' &&
|
|
31
|
-
(ctx.multiple?.selectedValues.value.length ?? 0) > 0,
|
|
32
|
-
);
|
|
33
12
|
</script>
|
|
34
13
|
|
|
35
14
|
<template>
|
|
36
|
-
<ShadcnSelectValue
|
|
37
|
-
v-if="ctx.mode === 'single'"
|
|
38
|
-
:placeholder="props.placeholder"
|
|
39
|
-
>
|
|
15
|
+
<ShadcnSelectValue :placeholder="props.placeholder">
|
|
40
16
|
<slot />
|
|
41
17
|
</ShadcnSelectValue>
|
|
42
|
-
|
|
43
|
-
<!--
|
|
44
|
-
Multi-select display: render as a block-level truncating span.
|
|
45
|
-
`truncate` (= `overflow:hidden; text-overflow:ellipsis; white-space:nowrap`)
|
|
46
|
-
works only when this element participates in the parent flex row with
|
|
47
|
-
`min-w-0` + `flex-1` (applied via `UiSelectTrigger` via the
|
|
48
|
-
`*:data-[slot=select-value]:*` selectors), which is why we avoid flex
|
|
49
|
-
layout on the span itself here.
|
|
50
|
-
-->
|
|
51
|
-
<span
|
|
52
|
-
v-else
|
|
53
|
-
data-slot="select-value"
|
|
54
|
-
:data-placeholder="hasSelection ? undefined : ''"
|
|
55
|
-
class="block truncate"
|
|
56
|
-
>
|
|
57
|
-
<slot
|
|
58
|
-
v-if="$slots.default"
|
|
59
|
-
:selected="ctx.multiple?.selectedValues.value ?? []"
|
|
60
|
-
/>
|
|
61
|
-
<template v-else-if="hasSelection">{{ displayText }}</template>
|
|
62
|
-
<template v-else>{{ props.placeholder }}</template>
|
|
63
|
-
</span>
|
|
64
18
|
</template>
|
|
@@ -218,6 +218,8 @@ describe('UiSelect', () => {
|
|
|
218
218
|
});
|
|
219
219
|
|
|
220
220
|
describe('multiple', () => {
|
|
221
|
+
const triggerRoleOptions = { hidden: true } as const;
|
|
222
|
+
|
|
221
223
|
function renderMultiSelect(
|
|
222
224
|
options: {
|
|
223
225
|
placeholder?: string;
|
|
@@ -279,16 +281,16 @@ describe('UiSelect', () => {
|
|
|
279
281
|
const { getByRole } = renderMultiSelect({
|
|
280
282
|
placeholder: 'Pick some fruits',
|
|
281
283
|
});
|
|
282
|
-
const trigger = getByRole('
|
|
284
|
+
const trigger = getByRole('combobox', triggerRoleOptions);
|
|
283
285
|
expect(trigger).toBeInTheDocument();
|
|
284
286
|
expect(trigger).toHaveTextContent('Pick some fruits');
|
|
285
287
|
});
|
|
286
288
|
|
|
287
|
-
test('opens
|
|
289
|
+
test('opens dropdown on trigger click', async () => {
|
|
288
290
|
const user = userEvent.setup();
|
|
289
291
|
const { getByRole } = renderMultiSelect();
|
|
290
292
|
|
|
291
|
-
await user.click(getByRole('
|
|
293
|
+
await user.click(getByRole('combobox', triggerRoleOptions));
|
|
292
294
|
|
|
293
295
|
await waitFor(() => {
|
|
294
296
|
expect(getByRole('listbox')).toBeInTheDocument();
|
|
@@ -299,18 +301,22 @@ describe('UiSelect', () => {
|
|
|
299
301
|
const user = userEvent.setup();
|
|
300
302
|
const { getByRole } = renderMultiSelect();
|
|
301
303
|
|
|
302
|
-
await user.click(getByRole('
|
|
304
|
+
await user.click(getByRole('combobox', triggerRoleOptions));
|
|
303
305
|
await waitFor(() => expect(getByRole('listbox')).toBeInTheDocument());
|
|
304
306
|
|
|
305
307
|
await user.click(getByRole('option', { name: /apple/i }));
|
|
306
308
|
await user.click(getByRole('option', { name: /orange/i }));
|
|
307
309
|
|
|
308
|
-
//
|
|
310
|
+
// multi-select stays open across clicks
|
|
309
311
|
expect(getByRole('listbox')).toBeInTheDocument();
|
|
310
312
|
|
|
311
313
|
await waitFor(() => {
|
|
312
|
-
expect(getByRole('
|
|
313
|
-
|
|
314
|
+
expect(getByRole('combobox', triggerRoleOptions)).toHaveTextContent(
|
|
315
|
+
/apple/i,
|
|
316
|
+
);
|
|
317
|
+
expect(getByRole('combobox', triggerRoleOptions)).toHaveTextContent(
|
|
318
|
+
/orange/i,
|
|
319
|
+
);
|
|
314
320
|
});
|
|
315
321
|
});
|
|
316
322
|
|
|
@@ -318,19 +324,25 @@ describe('UiSelect', () => {
|
|
|
318
324
|
const user = userEvent.setup();
|
|
319
325
|
const { getByRole } = renderMultiSelect();
|
|
320
326
|
|
|
321
|
-
await user.click(getByRole('
|
|
327
|
+
await user.click(getByRole('combobox', triggerRoleOptions));
|
|
322
328
|
await waitFor(() => expect(getByRole('listbox')).toBeInTheDocument());
|
|
323
329
|
|
|
324
330
|
await user.click(getByRole('option', { name: /apple/i }));
|
|
325
331
|
await waitFor(() =>
|
|
326
|
-
expect(getByRole('
|
|
332
|
+
expect(getByRole('combobox', triggerRoleOptions)).toHaveTextContent(
|
|
333
|
+
/apple/i,
|
|
334
|
+
),
|
|
327
335
|
);
|
|
328
336
|
|
|
329
337
|
await user.click(getByRole('option', { name: /apple/i }));
|
|
330
338
|
|
|
331
339
|
await waitFor(() => {
|
|
332
|
-
expect(getByRole('
|
|
333
|
-
|
|
340
|
+
expect(getByRole('combobox', triggerRoleOptions)).not.toHaveTextContent(
|
|
341
|
+
/apple/i,
|
|
342
|
+
);
|
|
343
|
+
expect(getByRole('combobox', triggerRoleOptions)).toHaveTextContent(
|
|
344
|
+
/select fruits/i,
|
|
345
|
+
);
|
|
334
346
|
});
|
|
335
347
|
});
|
|
336
348
|
|
|
@@ -362,7 +374,7 @@ describe('UiSelect', () => {
|
|
|
362
374
|
},
|
|
363
375
|
});
|
|
364
376
|
|
|
365
|
-
await user.click(getByRole('
|
|
377
|
+
await user.click(getByRole('combobox', triggerRoleOptions));
|
|
366
378
|
await waitFor(() => expect(getByRole('listbox')).toBeInTheDocument());
|
|
367
379
|
|
|
368
380
|
await user.click(getByRole('option', { name: 'A' }));
|
|
@@ -411,7 +423,7 @@ describe('UiSelect', () => {
|
|
|
411
423
|
|
|
412
424
|
// Selecting a second item adds a second hidden input — same name,
|
|
413
425
|
// additional value (mirrors native `<select multiple>` submission).
|
|
414
|
-
await user.click(getByRole('
|
|
426
|
+
await user.click(getByRole('combobox', triggerRoleOptions));
|
|
415
427
|
await waitFor(() => expect(getByRole('listbox')).toBeInTheDocument());
|
|
416
428
|
await user.click(getByRole('option', { name: /banana/i }));
|
|
417
429
|
|
|
@@ -564,7 +576,7 @@ describe('UiSelect', () => {
|
|
|
564
576
|
});
|
|
565
577
|
|
|
566
578
|
await waitFor(() => {
|
|
567
|
-
const trigger = getByRole('
|
|
579
|
+
const trigger = getByRole('combobox', triggerRoleOptions);
|
|
568
580
|
expect(trigger).toHaveTextContent(/alpha/i);
|
|
569
581
|
expect(trigger).toHaveTextContent(/gamma/i);
|
|
570
582
|
expect(trigger).not.toHaveTextContent(/beta/i);
|
|
@@ -607,10 +619,12 @@ describe('UiSelect', () => {
|
|
|
607
619
|
});
|
|
608
620
|
|
|
609
621
|
await waitFor(() => {
|
|
610
|
-
expect(getByRole('
|
|
622
|
+
expect(getByRole('combobox', triggerRoleOptions)).toHaveTextContent(
|
|
623
|
+
/alpha/i,
|
|
624
|
+
);
|
|
611
625
|
});
|
|
612
626
|
|
|
613
|
-
await user.click(getByRole('
|
|
627
|
+
await user.click(getByRole('combobox', triggerRoleOptions));
|
|
614
628
|
await waitFor(() => expect(getByRole('listbox')).toBeInTheDocument());
|
|
615
629
|
await user.click(getByRole('option', { name: /beta/i }));
|
|
616
630
|
|
|
@@ -618,7 +632,7 @@ describe('UiSelect', () => {
|
|
|
618
632
|
|
|
619
633
|
// Trigger should still reflect ONLY the parent-owned value.
|
|
620
634
|
await waitFor(() => {
|
|
621
|
-
const trigger = getByRole('
|
|
635
|
+
const trigger = getByRole('combobox', triggerRoleOptions);
|
|
622
636
|
expect(trigger).toHaveTextContent(/alpha/i);
|
|
623
637
|
expect(trigger).not.toHaveTextContent(/beta/i);
|
|
624
638
|
});
|
|
@@ -669,7 +683,7 @@ describe('UiSelect', () => {
|
|
|
669
683
|
|
|
670
684
|
// Click another option — parent doesn't update `value`, so
|
|
671
685
|
// hidden inputs must stay frozen on the controlled value.
|
|
672
|
-
await user.click(getByRole('
|
|
686
|
+
await user.click(getByRole('combobox', triggerRoleOptions));
|
|
673
687
|
await waitFor(() => expect(getByRole('listbox')).toBeInTheDocument());
|
|
674
688
|
await user.click(getByRole('option', { name: /banana/i }));
|
|
675
689
|
|
|
@@ -706,87 +720,23 @@ describe('UiSelect', () => {
|
|
|
706
720
|
});
|
|
707
721
|
|
|
708
722
|
await waitFor(() =>
|
|
709
|
-
expect(getByRole('
|
|
723
|
+
expect(getByRole('combobox', triggerRoleOptions)).toHaveTextContent(
|
|
724
|
+
/apple/i,
|
|
725
|
+
),
|
|
710
726
|
);
|
|
711
727
|
|
|
712
|
-
await user.click(getByRole('
|
|
728
|
+
await user.click(getByRole('combobox', triggerRoleOptions));
|
|
713
729
|
await waitFor(() => expect(getByRole('listbox')).toBeInTheDocument());
|
|
714
730
|
await user.click(getByRole('option', { name: /banana/i }));
|
|
715
731
|
|
|
716
732
|
await waitFor(() => {
|
|
717
|
-
const trigger = getByRole('
|
|
733
|
+
const trigger = getByRole('combobox', triggerRoleOptions);
|
|
718
734
|
expect(trigger).toHaveTextContent(/apple/i);
|
|
719
735
|
expect(trigger).toHaveTextContent(/banana/i);
|
|
720
736
|
});
|
|
721
737
|
});
|
|
722
738
|
|
|
723
|
-
test('
|
|
724
|
-
// Regression: when `UiSelectItem`'s `:value` changes, the label
|
|
725
|
-
// registry used to keep the OLD key indefinitely. That meant
|
|
726
|
-
// selecting the old value (e.g. via a controlled `modelValue`)
|
|
727
|
-
// would still resolve to the orphaned label, and the map could
|
|
728
|
-
// grow unbounded for dynamic option lists.
|
|
729
|
-
//
|
|
730
|
-
// After the fix, the previous key is dropped before the new one
|
|
731
|
-
// is registered. We can't read the registry directly (it's
|
|
732
|
-
// internal context) so we observe its effects through the
|
|
733
|
-
// trigger label — when a key is missing, `UiSelectValue` falls
|
|
734
|
-
// back to rendering the raw value.
|
|
735
|
-
const { getByRole, rerender } = render({
|
|
736
|
-
components: {
|
|
737
|
-
UiSelect,
|
|
738
|
-
UiSelectTrigger,
|
|
739
|
-
UiSelectContent,
|
|
740
|
-
UiSelectItem,
|
|
741
|
-
UiSelectValue,
|
|
742
|
-
},
|
|
743
|
-
props: {
|
|
744
|
-
itemValue: { type: String, default: 'apple' },
|
|
745
|
-
parentValue: { type: Array, default: () => ['apple'] },
|
|
746
|
-
},
|
|
747
|
-
template: `
|
|
748
|
-
<UiSelect :multiple="true" :model-value="parentValue">
|
|
749
|
-
<UiSelectTrigger>
|
|
750
|
-
<UiSelectValue placeholder="Pick" />
|
|
751
|
-
</UiSelectTrigger>
|
|
752
|
-
<UiSelectContent>
|
|
753
|
-
<UiSelectItem :value="itemValue">Apple</UiSelectItem>
|
|
754
|
-
</UiSelectContent>
|
|
755
|
-
</UiSelect>
|
|
756
|
-
`,
|
|
757
|
-
});
|
|
758
|
-
|
|
759
|
-
// Initial: 'apple' resolves to the registered label "Apple".
|
|
760
|
-
await waitFor(() => {
|
|
761
|
-
expect(getByRole('button')).toHaveTextContent(/^Apple$/);
|
|
762
|
-
});
|
|
763
|
-
|
|
764
|
-
// Re-key the item from 'apple' -> 'pear'. The registry must
|
|
765
|
-
// drop 'apple' before adding 'pear'.
|
|
766
|
-
await rerender({ itemValue: 'pear', parentValue: ['apple'] });
|
|
767
|
-
|
|
768
|
-
// 'apple' is no longer in the registry, so the trigger renders
|
|
769
|
-
// the raw value string (the displayText fallback). Without the
|
|
770
|
-
// fix this would still render "Apple" because the stale entry
|
|
771
|
-
// survived the value change.
|
|
772
|
-
await waitFor(() => {
|
|
773
|
-
const trigger = getByRole('button');
|
|
774
|
-
expect(trigger).toHaveTextContent(/^apple$/);
|
|
775
|
-
});
|
|
776
|
-
|
|
777
|
-
// And the new key 'pear' resolves to the same rendered label.
|
|
778
|
-
await rerender({ itemValue: 'pear', parentValue: ['pear'] });
|
|
779
|
-
await waitFor(() => {
|
|
780
|
-
expect(getByRole('button')).toHaveTextContent(/^Apple$/);
|
|
781
|
-
});
|
|
782
|
-
});
|
|
783
|
-
|
|
784
|
-
test('reactive mode: toggling :multiple switches the rendered branch', async () => {
|
|
785
|
-
// The provided context exposes `mode` via a getter so descendants
|
|
786
|
-
// re-evaluate which branch to render whenever `props.multiple`
|
|
787
|
-
// changes. Without that, `ctx.mode` would be a stale snapshot
|
|
788
|
-
// captured at setup time and toggling `:multiple` would leave
|
|
789
|
-
// children stuck on the original branch.
|
|
739
|
+
test('reactive mode: toggling :multiple keeps the core select branch', async () => {
|
|
790
740
|
const { getByRole, queryByRole, rerender } = render({
|
|
791
741
|
components: {
|
|
792
742
|
UiSelect,
|
|
@@ -809,24 +759,21 @@ describe('UiSelect', () => {
|
|
|
809
759
|
`,
|
|
810
760
|
});
|
|
811
761
|
|
|
812
|
-
//
|
|
813
|
-
// there is no plain `button` trigger.
|
|
762
|
+
// Both modes now render through the same core Select trigger.
|
|
814
763
|
expect(getByRole('combobox')).toBeInTheDocument();
|
|
815
764
|
expect(queryByRole('button')).not.toBeInTheDocument();
|
|
816
765
|
|
|
817
766
|
await rerender({ multiple: true });
|
|
818
767
|
|
|
819
|
-
// Multi-select
|
|
820
|
-
// and tears down the `combobox` from the single-select branch.
|
|
768
|
+
// Multi-select keeps the same core Select trigger semantics.
|
|
821
769
|
await waitFor(() => {
|
|
822
|
-
expect(getByRole('
|
|
823
|
-
expect(queryByRole('
|
|
770
|
+
expect(getByRole('combobox')).toBeInTheDocument();
|
|
771
|
+
expect(queryByRole('button')).not.toBeInTheDocument();
|
|
824
772
|
});
|
|
825
773
|
|
|
826
774
|
await rerender({ multiple: false });
|
|
827
775
|
|
|
828
|
-
// And back the other way —
|
|
829
|
-
// directions, not just on the first toggle.
|
|
776
|
+
// And back the other way — both modes keep the same trigger role.
|
|
830
777
|
await waitFor(() => {
|
|
831
778
|
expect(getByRole('combobox')).toBeInTheDocument();
|
|
832
779
|
expect(queryByRole('button')).not.toBeInTheDocument();
|
|
@@ -857,13 +804,15 @@ describe('UiSelect', () => {
|
|
|
857
804
|
});
|
|
858
805
|
|
|
859
806
|
await waitFor(() =>
|
|
860
|
-
expect(getByRole('
|
|
807
|
+
expect(getByRole('combobox', triggerRoleOptions)).toHaveTextContent(
|
|
808
|
+
/apple/i,
|
|
809
|
+
),
|
|
861
810
|
);
|
|
862
811
|
|
|
863
812
|
await rerender({ value: ['banana'] });
|
|
864
813
|
|
|
865
814
|
await waitFor(() => {
|
|
866
|
-
const trigger = getByRole('
|
|
815
|
+
const trigger = getByRole('combobox', triggerRoleOptions);
|
|
867
816
|
expect(trigger).toHaveTextContent(/banana/i);
|
|
868
817
|
expect(trigger).not.toHaveTextContent(/apple/i);
|
|
869
818
|
});
|
|
@@ -40,7 +40,7 @@ describe('UiSelectContent', () => {
|
|
|
40
40
|
});
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
test('
|
|
43
|
+
test('does not mount multi-select content while closed or lose selected label', async () => {
|
|
44
44
|
const { container, getByRole } = render({
|
|
45
45
|
components: {
|
|
46
46
|
UiSelect,
|
|
@@ -62,12 +62,45 @@ describe('UiSelectContent', () => {
|
|
|
62
62
|
});
|
|
63
63
|
|
|
64
64
|
await waitFor(() => {
|
|
65
|
-
expect(getByRole('
|
|
65
|
+
expect(getByRole('combobox')).toHaveTextContent('Option A');
|
|
66
66
|
});
|
|
67
67
|
expect(
|
|
68
68
|
container.ownerDocument.body.querySelector(
|
|
69
69
|
'[data-slot="select-content"]',
|
|
70
70
|
),
|
|
71
|
-
).
|
|
71
|
+
).not.toBeInTheDocument();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('ports multi-select content through the select portal', async () => {
|
|
75
|
+
const user = userEvent.setup();
|
|
76
|
+
const { container, getByRole } = render({
|
|
77
|
+
components: {
|
|
78
|
+
UiSelect,
|
|
79
|
+
UiSelectTrigger,
|
|
80
|
+
UiSelectContent,
|
|
81
|
+
UiSelectItem,
|
|
82
|
+
UiSelectValue,
|
|
83
|
+
},
|
|
84
|
+
template: `
|
|
85
|
+
<UiSelect :multiple="true">
|
|
86
|
+
<UiSelectTrigger>
|
|
87
|
+
<UiSelectValue placeholder="Select" />
|
|
88
|
+
</UiSelectTrigger>
|
|
89
|
+
<UiSelectContent class="max-h-[200px]">
|
|
90
|
+
<UiSelectItem value="a">Option A</UiSelectItem>
|
|
91
|
+
</UiSelectContent>
|
|
92
|
+
</UiSelect>
|
|
93
|
+
`,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
await user.click(getByRole('combobox'));
|
|
97
|
+
|
|
98
|
+
await waitFor(() => {
|
|
99
|
+
const content = container.ownerDocument.body.querySelector(
|
|
100
|
+
'[data-slot="select-content"]',
|
|
101
|
+
);
|
|
102
|
+
expect(content).toHaveClass('max-h-[200px]');
|
|
103
|
+
expect(container).not.toContainElement(content as HTMLElement);
|
|
104
|
+
});
|
|
72
105
|
});
|
|
73
106
|
});
|
|
@@ -172,7 +172,7 @@ describe('UiSelectItem', () => {
|
|
|
172
172
|
`,
|
|
173
173
|
});
|
|
174
174
|
|
|
175
|
-
await user.click(getByRole('
|
|
175
|
+
await user.click(getByRole('combobox'));
|
|
176
176
|
|
|
177
177
|
const option = getByRole('option', { name: 'Option A' });
|
|
178
178
|
const end = option.querySelector('[data-slot="select-item-end"]');
|
|
@@ -118,7 +118,7 @@ describe('UiSelectTrigger', () => {
|
|
|
118
118
|
`,
|
|
119
119
|
});
|
|
120
120
|
|
|
121
|
-
const trigger = getByRole('
|
|
121
|
+
const trigger = getByRole('combobox');
|
|
122
122
|
|
|
123
123
|
expect(trigger).toHaveClass('focus:border-border-surface-focus-ring');
|
|
124
124
|
expect(trigger).toHaveClass(
|
|
@@ -185,7 +185,7 @@ describe('UiSelectTrigger', () => {
|
|
|
185
185
|
});
|
|
186
186
|
|
|
187
187
|
await waitFor(() => {
|
|
188
|
-
const trigger = getByRole('
|
|
188
|
+
const trigger = getByRole('combobox');
|
|
189
189
|
expect(trigger).not.toHaveAttribute('data-placeholder');
|
|
190
190
|
expect(trigger).toHaveTextContent('Option 1');
|
|
191
191
|
expect(trigger).toHaveClass(
|