@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.
Files changed (26) hide show
  1. package/dist/system/components/UiAutocomplete/UiAutocomplete.vue.d.ts +0 -1
  2. package/dist/system/components/UiAutocomplete/types.d.ts +0 -2
  3. package/dist/system/components/UiSelect/UiSelect.vue.d.ts +4 -5
  4. package/dist/system/components/UiSelect/UiSelectContent.vue.d.ts +0 -1
  5. package/dist/system/components/UiSelect/UiSelectItem.vue.d.ts +2 -9
  6. package/dist/system/components/UiSelect/UiSelectTrigger.vue.d.ts +0 -2
  7. package/dist/system/components/UiSelect/UiSelectValue.vue.d.ts +0 -3
  8. package/dist/system/components/UiSelect/types.d.ts +26 -6
  9. package/dist/system/lib.js +18370 -18530
  10. package/package.json +1 -1
  11. package/src/components/UiAutocomplete/UiAutocomplete.vue +9 -9
  12. package/src/components/UiAutocomplete/__tests__/UiAutocomplete.test.ts +76 -5
  13. package/src/components/UiAutocomplete/types.ts +0 -2
  14. package/src/components/UiSelect/UiSelect.stories.ts +4 -90
  15. package/src/components/UiSelect/UiSelect.vue +66 -144
  16. package/src/components/UiSelect/UiSelectContent.vue +10 -21
  17. package/src/components/UiSelect/UiSelectItem.vue +0 -82
  18. package/src/components/UiSelect/UiSelectTrigger.vue +1 -62
  19. package/src/components/UiSelect/UiSelectValue.vue +1 -47
  20. package/src/components/UiSelect/__tests__/UiSelect.test.ts +47 -98
  21. package/src/components/UiSelect/__tests__/UiSelectContent.test.ts +36 -3
  22. package/src/components/UiSelect/__tests__/UiSelectItem.test.ts +1 -1
  23. package/src/components/UiSelect/__tests__/UiSelectTrigger.test.ts +2 -2
  24. package/src/components/UiSelect/types.ts +29 -6
  25. package/dist/system/components/UiSelect/context.d.ts +0 -28
  26. package/src/components/UiSelect/context.ts +0 -42
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aleph-alpha/ui-library",
3
- "version": "2.10.0",
3
+ "version": "2.11.0",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "dist/system/lib.js",
@@ -30,7 +30,6 @@ const props = withDefaults(defineProps<UiAutocompleteProps>(), {
30
30
  required: false,
31
31
  name: undefined,
32
32
  dir: 'ltr',
33
- size: 'default',
34
33
  emptyText: 'No results found.',
35
34
  startIcon: undefined,
36
35
  showIndicator: true,
@@ -97,8 +96,10 @@ const displayText = computed(() =>
97
96
  selectedOptions.value.map((option) => option.label).join(', '),
98
97
  );
99
98
 
99
+ const hasSelection = computed(() => selectedValues.value.length > 0);
100
+
100
101
  const showSelectionDisplay = computed(
101
- () => inputText.value.length === 0 && selectedValues.value.length > 0,
102
+ () => inputText.value.length === 0 && hasSelection.value,
102
103
  );
103
104
 
104
105
  const filteredOptions = computed(() => {
@@ -142,8 +143,7 @@ const inputSlotProps = computed(() => ({
142
143
 
143
144
  const shellClasses = computed(() =>
144
145
  cn(
145
- 'border-input focus-within:border-border-surface-focus-ring focus-within:ring-ring/50 focus-within:shadow-xs aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive flex w-full min-w-0 items-center gap-2 rounded-md border bg-background-input-default px-3 text-sm shadow-xs transition-[color,box-shadow] outline-none focus-within:ring-[3px]',
146
- props.size === 'default' ? 'h-9 py-2' : 'h-8 py-1.5',
146
+ 'border-input data-[placeholder]:bg-background-input-default [&:not([data-placeholder])]:border-border-surface-focus-ring focus-within:border-border-surface-focus-ring focus-within:ring-ring/50 focus-within:shadow-xs aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive flex h-9 w-full min-w-0 items-center gap-2 rounded-md border bg-accent px-3 py-2 text-sm transition-[color,box-shadow] outline-none focus-within:ring-[3px]',
147
147
  props.disabled && 'pointer-events-none cursor-not-allowed opacity-50',
148
148
  ),
149
149
  );
@@ -282,10 +282,6 @@ function syncHighlightToSelection() {
282
282
 
283
283
  function setHighlightedIndex(index: number) {
284
284
  highlightedIndex.value = index;
285
- const value = keyboardValues.value[index];
286
- if (!props.multiple && value) {
287
- applySelectionValue(value, false);
288
- }
289
285
  }
290
286
 
291
287
  function applySelectionValue(
@@ -317,7 +313,11 @@ provideUiAutocompleteContext({
317
313
  <div class="flex flex-col" :dir="props.dir">
318
314
  <ShadcnPopover v-model:open="openState">
319
315
  <ShadcnPopoverAnchor as-child>
320
- <div data-slot="autocomplete-trigger" :class="shellClasses">
316
+ <div
317
+ data-slot="autocomplete-trigger"
318
+ :data-placeholder="hasSelection ? undefined : ''"
319
+ :class="shellClasses"
320
+ >
321
321
  <UiIcon
322
322
  v-if="props.startIcon"
323
323
  :name="props.startIcon"
@@ -1,5 +1,5 @@
1
1
  import '@testing-library/jest-dom/vitest';
2
- import { render, waitFor } from '@testing-library/vue';
2
+ import { fireEvent, render, waitFor } from '@testing-library/vue';
3
3
  import userEvent from '@testing-library/user-event';
4
4
  import { describe, expect, test, vi } from 'vitest';
5
5
  import { ref } from 'vue';
@@ -25,6 +25,42 @@ describe('UiAutocomplete', () => {
25
25
  expect(input).toHaveAttribute('placeholder', 'Search fruit');
26
26
  });
27
27
 
28
+ test('uses the input surface when no value is selected', () => {
29
+ const { container } = render(UiAutocomplete, {
30
+ props: {
31
+ options,
32
+ placeholder: 'Search fruit',
33
+ },
34
+ });
35
+
36
+ const trigger = container.querySelector(
37
+ '[data-slot="autocomplete-trigger"]',
38
+ );
39
+ expect(trigger).toHaveAttribute('data-placeholder');
40
+ expect(trigger).toHaveClass(
41
+ 'data-[placeholder]:bg-background-input-default',
42
+ );
43
+ });
44
+
45
+ test('uses the filled select surface when a value is selected', () => {
46
+ const { container } = render(UiAutocomplete, {
47
+ props: {
48
+ options,
49
+ defaultValue: 'apple',
50
+ placeholder: 'Search fruit',
51
+ },
52
+ });
53
+
54
+ const trigger = container.querySelector(
55
+ '[data-slot="autocomplete-trigger"]',
56
+ );
57
+ expect(trigger).not.toHaveAttribute('data-placeholder');
58
+ expect(trigger).toHaveClass('bg-accent');
59
+ expect(trigger).toHaveClass(
60
+ '[&:not([data-placeholder])]:border-border-surface-focus-ring',
61
+ );
62
+ });
63
+
28
64
  test('opens suggestions and filters by input text', async () => {
29
65
  const user = userEvent.setup();
30
66
  const { getByRole, queryByRole } = render(UiAutocomplete, {
@@ -95,7 +131,7 @@ describe('UiAutocomplete', () => {
95
131
  );
96
132
  expect(
97
133
  document.querySelector('[data-slot="autocomplete-value"]'),
98
- ).toHaveTextContent('Apple');
134
+ ).not.toBeInTheDocument();
99
135
  });
100
136
 
101
137
  await user.keyboard('{ArrowDown}');
@@ -107,7 +143,7 @@ describe('UiAutocomplete', () => {
107
143
  );
108
144
  expect(
109
145
  document.querySelector('[data-slot="autocomplete-value"]'),
110
- ).toHaveTextContent('Banana');
146
+ ).not.toBeInTheDocument();
111
147
  });
112
148
 
113
149
  await user.keyboard('{Enter}');
@@ -140,6 +176,9 @@ describe('UiAutocomplete', () => {
140
176
  'data-highlighted',
141
177
  '',
142
178
  );
179
+ expect(
180
+ document.querySelector('[data-slot="autocomplete-value"]'),
181
+ ).toHaveTextContent('Banana');
143
182
  });
144
183
 
145
184
  await user.keyboard('{Enter}');
@@ -177,7 +216,7 @@ describe('UiAutocomplete', () => {
177
216
  );
178
217
  expect(
179
218
  document.querySelector('[data-slot="autocomplete-value"]'),
180
- ).toHaveTextContent('Apple');
219
+ ).not.toBeInTheDocument();
181
220
  });
182
221
 
183
222
  await user.keyboard('{ArrowDown}');
@@ -189,7 +228,7 @@ describe('UiAutocomplete', () => {
189
228
  );
190
229
  expect(
191
230
  document.querySelector('[data-slot="autocomplete-value"]'),
192
- ).toHaveTextContent('Banana');
231
+ ).not.toBeInTheDocument();
193
232
  });
194
233
 
195
234
  await user.keyboard('{Enter}');
@@ -226,6 +265,9 @@ describe('UiAutocomplete', () => {
226
265
  'data-highlighted',
227
266
  '',
228
267
  );
268
+ expect(
269
+ document.querySelector('[data-slot="autocomplete-value"]'),
270
+ ).toHaveTextContent('Banana');
229
271
  });
230
272
 
231
273
  await user.keyboard('{Enter}');
@@ -237,6 +279,35 @@ describe('UiAutocomplete', () => {
237
279
  });
238
280
  });
239
281
 
282
+ test('hovering an option highlights it without changing the selected value', async () => {
283
+ const user = userEvent.setup();
284
+ const { getByRole } = render({
285
+ components: { UiAutocomplete },
286
+ template: `
287
+ <UiAutocomplete v-model="value" :options="options" placeholder="Search fruit" />
288
+ `,
289
+ setup() {
290
+ const value = ref('apple');
291
+ return { value, options };
292
+ },
293
+ });
294
+
295
+ await user.click(getByRole('textbox'));
296
+ await waitFor(() => expect(getByRole('listbox')).toBeInTheDocument());
297
+
298
+ await fireEvent.pointerMove(getByRole('option', { name: 'Banana' }));
299
+
300
+ await waitFor(() => {
301
+ expect(getByRole('option', { name: 'Banana' })).toHaveAttribute(
302
+ 'data-highlighted',
303
+ '',
304
+ );
305
+ expect(
306
+ document.querySelector('[data-slot="autocomplete-value"]'),
307
+ ).toHaveTextContent('Apple');
308
+ });
309
+ });
310
+
240
311
  test('selects multiple options and keeps selected labels truncated in one value span', async () => {
241
312
  const user = userEvent.setup();
242
313
  const { getByRole } = render({
@@ -53,8 +53,6 @@ export type UiAutocompleteProps = {
53
53
  name?: string;
54
54
  /** Reading direction. */
55
55
  dir?: 'ltr' | 'rtl';
56
- /** Trigger/input size. */
57
- size?: 'default' | 'sm';
58
56
  /** Text shown when filtering returns no options. */
59
57
  emptyText?: string;
60
58
  /** Optional leading icon name. */
@@ -14,7 +14,7 @@ import { UiIcon } from '@/components/UiIcon';
14
14
 
15
15
  /**
16
16
  * UiSelect is a trigger-and-dropdown primitive for choosing one option from a list, with grouped options, separators, and labels.
17
- * Use it for compact form selects; for filterable, multi-select, or always-visible lists, prefer `UiListbox`.
17
+ * Use it for compact form selects; for filterable or always-visible lists, prefer `UiListbox`.
18
18
  */
19
19
  const meta: Meta<typeof UiSelect> = {
20
20
  title: 'Components/UiSelect',
@@ -425,92 +425,6 @@ export const Disabled: Story = {
425
425
  },
426
426
  };
427
427
 
428
- const sizesTemplateSource = `<script setup lang="ts">
429
- import { ref } from 'vue'
430
- import {
431
- UiSelect,
432
- UiSelectTrigger,
433
- UiSelectContent,
434
- UiSelectItem,
435
- UiSelectValue,
436
- } from '@aleph-alpha/ui-library'
437
-
438
- const value = ref('')
439
- const value2 = ref('')
440
- </script>
441
-
442
- <template>
443
- <div class="flex items-center gap-4">
444
- <UiSelect v-model="value">
445
- <UiSelectTrigger ariaLabel="Select option" size="sm">
446
- <UiSelectValue placeholder="Small" />
447
- </UiSelectTrigger>
448
- <UiSelectContent>
449
- <UiSelectItem value="a">Option A</UiSelectItem>
450
- <UiSelectItem value="b">Option B</UiSelectItem>
451
- </UiSelectContent>
452
- </UiSelect>
453
- <UiSelect v-model="value2">
454
- <UiSelectTrigger ariaLabel="Select option" size="default">
455
- <UiSelectValue placeholder="Default" />
456
- </UiSelectTrigger>
457
- <UiSelectContent>
458
- <UiSelectItem value="a">Option A</UiSelectItem>
459
- <UiSelectItem value="b">Option B</UiSelectItem>
460
- </UiSelectContent>
461
- </UiSelect>
462
- </div>
463
- </template>`;
464
-
465
- /**
466
- * Different size variants for the select trigger (sm, default, lg).
467
- */
468
- export const Sizes: Story = {
469
- render: () => ({
470
- components: {
471
- UiSelect,
472
- UiSelectTrigger,
473
- UiSelectContent,
474
- UiSelectItem,
475
- UiSelectValue,
476
- },
477
- setup() {
478
- const value = ref('');
479
- const value2 = ref('');
480
- return { value, value2 };
481
- },
482
- template: `
483
- <div class="flex items-center gap-4">
484
- <UiSelect v-model="value">
485
- <UiSelectTrigger ariaLabel="Select option" size="sm">
486
- <UiSelectValue placeholder="Small" />
487
- </UiSelectTrigger>
488
- <UiSelectContent>
489
- <UiSelectItem value="a">Option A</UiSelectItem>
490
- <UiSelectItem value="b">Option B</UiSelectItem>
491
- </UiSelectContent>
492
- </UiSelect>
493
- <UiSelect v-model="value2">
494
- <UiSelectTrigger ariaLabel="Select option" size="default">
495
- <UiSelectValue placeholder="Default" />
496
- </UiSelectTrigger>
497
- <UiSelectContent>
498
- <UiSelectItem value="a">Option A</UiSelectItem>
499
- <UiSelectItem value="b">Option B</UiSelectItem>
500
- </UiSelectContent>
501
- </UiSelect>
502
- </div>
503
- `,
504
- }),
505
- parameters: {
506
- docs: {
507
- source: {
508
- code: sizesTemplateSource,
509
- },
510
- },
511
- },
512
- };
513
-
514
428
  const withDefaultValueTemplateSource = `<script setup lang="ts">
515
429
  import { ref } from 'vue'
516
430
  import {
@@ -571,8 +485,8 @@ const value = ref<string[]>([])
571
485
  </template>`;
572
486
 
573
487
  /**
574
- * Multi-select mode. Pass `multiple` to switch the trigger into a popover-backed
575
- * listbox. The popover stays open between clicks so users can toggle several
488
+ * Multi-select mode. Pass `multiple` to use the same select primitive with
489
+ * array values. The dropdown stays open between clicks so users can toggle several
576
490
  * items, the selected values are emitted as an array via `update:modelValue`,
577
491
  * and the trigger renders the selected items as a comma-separated list that
578
492
  * truncates with an ellipsis when it exceeds the trigger's width.
@@ -647,7 +561,7 @@ const value = ref<string[]>(['banana', 'mango'])
647
561
 
648
562
  /**
649
563
  * Multi-select with a pre-selected list of values. The trigger renders the
650
- * matching item labels even before the popover is opened.
564
+ * matching item labels even before the dropdown is opened.
651
565
  */
652
566
  export const MultipleWithDefaultValue: Story = {
653
567
  render: () => ({
@@ -2,10 +2,11 @@
2
2
  import type { AcceptableValue } from 'reka-ui';
3
3
  import { computed, ref } from 'vue';
4
4
  import { Select as ShadcnSelect } from '@/components/core/select';
5
- import { Listbox as ShadcnListbox } from '@/components/core/listbox';
6
- import { Popover as ShadcnPopover } from '@/components/core/popover';
7
- import { provideUiSelectContext } from './context';
8
- import type { UiSelectProps, UiSelectEmits } from './types';
5
+ import type {
6
+ UiSelectProps,
7
+ UiSelectEmits,
8
+ UiSelectOptionalValue,
9
+ } from './types';
9
10
 
10
11
  defineOptions({
11
12
  name: 'UiSelect',
@@ -25,52 +26,44 @@ const props = withDefaults(defineProps<UiSelectProps>(), {
25
26
 
26
27
  const emit = defineEmits<UiSelectEmits>();
27
28
 
28
- // -------- Single-select (default) --------
29
+ function toArray(value: UiSelectOptionalValue): string[] {
30
+ if (Array.isArray(value)) return value;
31
+ if (typeof value === 'string' && value.length > 0) return [value];
32
+ return [];
33
+ }
34
+
35
+ function toSelectValue(value: UiSelectOptionalValue): UiSelectOptionalValue {
36
+ if (props.multiple) {
37
+ if (value === undefined) {
38
+ return undefined;
39
+ }
40
+
41
+ return toArray(value);
42
+ }
29
43
 
30
- function handleSingleModelValueUpdate(value: AcceptableValue) {
31
44
  if (typeof value === 'string') {
32
- emit('update:modelValue', value);
45
+ return value;
33
46
  }
34
- }
35
47
 
36
- const singleModelValue = computed(() =>
37
- typeof props.modelValue === 'string' ? props.modelValue : undefined,
38
- );
39
- const singleDefaultValue = computed(() =>
40
- typeof props.defaultValue === 'string' ? props.defaultValue : undefined,
41
- );
48
+ return undefined;
49
+ }
42
50
 
43
- // -------- Multi-select (popover + listbox) --------
51
+ const selectModelValue = computed(() => toSelectValue(props.modelValue));
44
52
 
45
- function toArray(value: string | string[] | undefined): string[] {
46
- if (Array.isArray(value)) return value;
47
- if (typeof value === 'string' && value.length > 0) return [value];
48
- return [];
49
- }
53
+ const selectDefaultValue = computed(() => toSelectValue(props.defaultValue));
50
54
 
51
- // Multi-select is treated as **controlled** when the consumer passes
52
- // `modelValue` (even an empty array); otherwise we manage state
53
- // internally seeded from `defaultValue`. This mirrors how Vue
54
- // components are conventionally controlled and prevents internal
55
- // state from drifting away from the prop when the parent doesn't
56
- // echo `update:modelValue` back.
57
55
  const isMultiControlled = computed(() => props.modelValue !== undefined);
58
-
59
- // Uncontrolled storage. Only mutated when `isMultiControlled` is false.
60
56
  const internalMultiValue = ref<string[]>(toArray(props.defaultValue));
61
-
62
- // Effective selection used by the listbox, the trigger label, the
63
- // hidden form inputs, and the provided context. When controlled it
64
- // tracks the prop directly so the UI never leads the parent state.
65
57
  const multiSelectedValues = computed<string[]>(() =>
66
58
  isMultiControlled.value
67
59
  ? toArray(props.modelValue)
68
60
  : internalMultiValue.value,
69
61
  );
62
+ const formHiddenValues = computed<string[]>(() =>
63
+ props.multiple && props.name ? multiSelectedValues.value : [],
64
+ );
70
65
 
71
- function normalizeMultiValue(
72
- value: AcceptableValue | AcceptableValue[],
73
- ): string[] {
66
+ function toStringArray(value: AcceptableValue | AcceptableValue[]): string[] {
74
67
  if (Array.isArray(value)) {
75
68
  return value.filter((v): v is string => typeof v === 'string');
76
69
  }
@@ -80,129 +73,58 @@ function normalizeMultiValue(
80
73
  return [];
81
74
  }
82
75
 
83
- function handleMultiModelValueUpdate(
84
- value: AcceptableValue | AcceptableValue[],
85
- ) {
86
- const next = normalizeMultiValue(value);
87
- // In controlled mode we **only emit** — the parent owns the value
88
- // and is responsible for echoing it back via `modelValue`. Mutating
89
- // `internalMultiValue` here would cause a brief desync where the
90
- // UI moves but the prop hasn't.
91
- if (!isMultiControlled.value) {
92
- internalMultiValue.value = next;
76
+ function handleModelValueUpdate(value: AcceptableValue | AcceptableValue[]) {
77
+ if (props.multiple) {
78
+ const next = toStringArray(value);
79
+ if (!isMultiControlled.value) {
80
+ internalMultiValue.value = next;
81
+ }
82
+ emit('update:modelValue', next);
83
+ return;
93
84
  }
94
- emit('update:modelValue', next);
95
- }
96
-
97
- // Open state for the multi-select popover. Mirrors the controlled `open`
98
- // prop when provided, otherwise stays uncontrolled internally.
99
- const internalOpen = ref<boolean>(props.defaultOpen ?? false);
100
- const popoverOpen = computed({
101
- get() {
102
- return props.open ?? internalOpen.value;
103
- },
104
- set(value: boolean) {
105
- internalOpen.value = value;
106
- emit('update:open', value);
107
- },
108
- });
109
-
110
- // -------- Form integration (multi-select) --------
111
-
112
- // Hidden `<input type="hidden">` values rendered for FormData
113
- // submission. We only emit hidden inputs when `name` is set; without
114
- // a name they wouldn't contribute to form data anyway.
115
- const formHiddenValues = computed<string[]>(() =>
116
- props.multiple && props.name ? multiSelectedValues.value : [],
117
- );
118
85
 
119
- // -------- Context provided to subcomponents --------
120
-
121
- const itemLabels = ref<Map<string, string>>(new Map());
122
-
123
- // Use getters instead of evaluating `props.multiple` once at setup
124
- // time — descendants choose between the single-select and
125
- // multi-select render paths via `ctx.mode`, and that decision must
126
- // track the current prop value, not a stale snapshot. Without
127
- // getters, toggling `:multiple` after mount would leave children
128
- // rendering the original branch.
129
- provideUiSelectContext({
130
- get mode() {
131
- return props.multiple ? 'multiple' : 'single';
132
- },
133
- get multiple() {
134
- return props.multiple
135
- ? {
136
- selectedValues: multiSelectedValues,
137
- itemLabels,
138
- }
139
- : undefined;
140
- },
141
- });
86
+ if (typeof value === 'string') {
87
+ emit('update:modelValue', value);
88
+ }
89
+ }
142
90
  </script>
143
91
 
144
92
  <template>
145
93
  <ShadcnSelect
146
- v-if="!props.multiple"
147
- :model-value="singleModelValue"
148
- :default-value="singleDefaultValue"
94
+ :model-value="selectModelValue"
95
+ :default-value="selectDefaultValue"
149
96
  :default-open="props.defaultOpen"
150
97
  :open="props.open"
151
98
  :disabled="props.disabled"
152
- :required="props.required"
153
- :name="props.name"
99
+ :required="props.multiple ? false : props.required"
100
+ :name="props.multiple ? undefined : props.name"
154
101
  :dir="props.dir"
155
- @update:model-value="handleSingleModelValueUpdate"
102
+ :multiple="props.multiple"
103
+ @update:model-value="handleModelValueUpdate"
156
104
  @update:open="emit('update:open', $event)"
157
105
  >
158
106
  <slot />
159
107
  </ShadcnSelect>
160
108
 
161
- <ShadcnListbox
162
- v-else
163
- :model-value="multiSelectedValues"
164
- :multiple="true"
109
+ <!--
110
+ Reka Select owns interaction and display in both modes. These inputs only
111
+ preserve native form submission/validation for multi-select arrays.
112
+ -->
113
+ <input
114
+ v-for="value in formHiddenValues"
115
+ :key="value"
116
+ type="hidden"
117
+ :name="props.name"
118
+ :value="value"
119
+ />
120
+ <input
121
+ v-if="props.multiple && props.required"
122
+ type="text"
123
+ :value="multiSelectedValues.length > 0 ? 'has-value' : ''"
124
+ :required="true"
165
125
  :disabled="props.disabled"
166
- :dir="props.dir"
167
- selection-behavior="toggle"
168
- @update:model-value="handleMultiModelValueUpdate"
169
- >
170
- <ShadcnPopover v-model:open="popoverOpen">
171
- <slot />
172
- </ShadcnPopover>
173
-
174
- <!--
175
- Form integration for multi-select.
176
-
177
- Native `<select multiple name="...">` submits one form entry per
178
- selected option (same key, repeated values). We mirror that by
179
- rendering one hidden input per selected value when `name` is set
180
- so multi-select participates in standard FormData / form POSTs.
181
-
182
- For `required`, we render a visually-hidden but focusable text
183
- input that participates in native form validation. We can't use
184
- `display:none`/`visibility:hidden` (browsers skip validating
185
- those), so we use the standard sr-only clip-rect trick. The
186
- input intentionally has no `name` so it doesn't appear in
187
- submitted form data — its only job is to fire constraint
188
- validation on submit when no value is selected.
189
- -->
190
- <input
191
- v-for="value in formHiddenValues"
192
- :key="value"
193
- type="hidden"
194
- :name="props.name"
195
- :value="value"
196
- />
197
- <input
198
- v-if="props.required"
199
- type="text"
200
- :value="multiSelectedValues.length > 0 ? 'has-value' : ''"
201
- :required="true"
202
- :disabled="props.disabled"
203
- tabindex="-1"
204
- aria-hidden="true"
205
- class="pointer-events-none absolute m-[-1px] size-px overflow-hidden border-0 p-0 whitespace-nowrap [clip:rect(0,0,0,0)]"
206
- />
207
- </ShadcnListbox>
126
+ tabindex="-1"
127
+ aria-hidden="true"
128
+ class="pointer-events-none absolute m-[-1px] size-px overflow-hidden border-0 p-0 whitespace-nowrap [clip:rect(0,0,0,0)]"
129
+ />
208
130
  </template>
@@ -1,12 +1,11 @@
1
1
  <script setup lang="ts">
2
+ import { computed, useAttrs } from 'vue';
2
3
  import { SelectContent as ShadcnSelectContent } from '@/components/core/select';
3
- import { PopoverContent as ShadcnPopoverContent } from '@/components/core/popover';
4
- import { ListboxContent as ShadcnListboxContent } from '@/components/core/listbox';
5
- import { useUiSelectContext } from './context';
6
4
  import type { UiSelectContentProps, UiSelectContentEmits } from './types';
7
5
 
8
6
  defineOptions({
9
7
  name: 'UiSelectContent',
8
+ inheritAttrs: false,
10
9
  });
11
10
 
12
11
  const props = withDefaults(defineProps<UiSelectContentProps>(), {
@@ -18,35 +17,25 @@ const props = withDefaults(defineProps<UiSelectContentProps>(), {
18
17
 
19
18
  const emit = defineEmits<UiSelectContentEmits>();
20
19
 
21
- const ctx = useUiSelectContext();
20
+ const attrs = useAttrs();
21
+
22
+ const forwardedAttrs = computed(() => {
23
+ const { class: _class, ...delegatedAttrs } = attrs;
24
+ return delegatedAttrs;
25
+ });
22
26
  </script>
23
27
 
24
28
  <template>
25
29
  <ShadcnSelectContent
26
- v-if="ctx.mode === 'single'"
30
+ v-bind="forwardedAttrs"
27
31
  :side="props.side"
28
32
  :side-offset="props.sideOffset"
29
33
  :align="props.align"
30
34
  :position="props.position"
35
+ :class="props.class"
31
36
  @escape-key-down="emit('escapeKeyDown', $event)"
32
37
  @pointer-down-outside="emit('pointerDownOutside', $event)"
33
38
  >
34
39
  <slot />
35
40
  </ShadcnSelectContent>
36
-
37
- <ShadcnPopoverContent
38
- v-else
39
- data-slot="select-content"
40
- :side="props.side"
41
- :side-offset="props.sideOffset"
42
- :align="props.align"
43
- :force-mount="true"
44
- class="min-w-(--reka-popper-anchor-width) w-(--reka-popper-anchor-width) max-w-(--reka-popper-available-width) p-1 data-[state=closed]:hidden data-[state=closed]:pointer-events-none"
45
- @escape-key-down="emit('escapeKeyDown', $event)"
46
- @pointer-down-outside="emit('pointerDownOutside', $event)"
47
- >
48
- <ShadcnListboxContent>
49
- <slot />
50
- </ShadcnListboxContent>
51
- </ShadcnPopoverContent>
52
41
  </template>