@weni/unnnic-system 3.36.1-alpha.0 → 3.36.1

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 (42) hide show
  1. package/dist/assets/scss/tailwind.css +1 -1
  2. package/dist/components/MultiSelect/MultiSelectOption.css +1 -1
  3. package/dist/components/MultiSelect/MultiSelectOption.vue.mjs +2 -2
  4. package/dist/components/MultiSelect/MultiSelectOption.vue2.mjs +15 -41
  5. package/dist/components/MultiSelect/index.css +1 -1
  6. package/dist/components/MultiSelect/index.vue.mjs +2 -2
  7. package/dist/components/MultiSelect/index.vue2.mjs +114 -126
  8. package/dist/components/SelectTime/index.css +1 -1
  9. package/dist/components/SelectTime/index.vue.mjs +55 -42
  10. package/dist/composables/useSelectBase.mjs +39 -44
  11. package/dist/composables/useSelectKeyboard.mjs +35 -70
  12. package/dist/locales/en.json.mjs +5 -9
  13. package/dist/style.css +4 -6
  14. package/dist/unnnic.umd.js +19 -19
  15. package/package.json +2 -2
  16. package/src/components/MultiSelect/MultiSelectOption.vue +3 -66
  17. package/src/components/MultiSelect/__tests__/MultiSelect.spec.js +0 -556
  18. package/src/components/MultiSelect/__tests__/MultiSelectOption.spec.js +1 -55
  19. package/src/components/MultiSelect/__tests__/__snapshots__/MultiSelectOption.spec.js.snap +0 -5
  20. package/src/components/MultiSelect/index.vue +50 -57
  21. package/src/components/Select/_select-shared.scss +0 -8
  22. package/src/components/Select/types.ts +0 -1
  23. package/src/components/SelectTime/__tests__/SelectTime.spec.js +88 -0
  24. package/src/components/SelectTime/index.vue +31 -7
  25. package/src/composables/useSelectBase.ts +16 -40
  26. package/src/composables/useSelectKeyboard.ts +18 -92
  27. package/src/locales/en.json +1 -3
  28. package/src/stories/MultiSelect.stories.js +1 -62
  29. package/src/stories/SelectTime.stories.js +5 -1
  30. package/dist/components/MultiSelect/MultiSelectTreeOptions.css +0 -1
  31. package/dist/components/MultiSelect/MultiSelectTreeOptions.vue.mjs +0 -7
  32. package/dist/components/MultiSelect/MultiSelectTreeOptions.vue2.mjs +0 -50
  33. package/dist/composables/useMultiSelectRows.mjs +0 -74
  34. package/dist/composables/useMultiSelectSelection.mjs +0 -44
  35. package/dist/composables/useTreeExpansion.mjs +0 -24
  36. package/dist/lib/tree-selection.mjs +0 -66
  37. package/src/components/MultiSelect/MultiSelectTreeOptions.vue +0 -73
  38. package/src/composables/useMultiSelectRows.ts +0 -121
  39. package/src/composables/useMultiSelectSelection.ts +0 -97
  40. package/src/composables/useTreeExpansion.ts +0 -44
  41. package/src/lib/__tests__/tree-selection.spec.ts +0 -141
  42. package/src/lib/tree-selection.ts +0 -156
@@ -1,15 +1,9 @@
1
1
  import { mount } from '@vue/test-utils';
2
2
  import { beforeEach, describe, expect, test, afterEach } from 'vitest';
3
3
  import MultiSelectOption from '../MultiSelectOption.vue';
4
- import i18n from '@/utils/plugins/i18n';
5
4
 
6
5
  const createWrapper = (props = {}) => {
7
- return mount(MultiSelectOption, {
8
- props,
9
- global: {
10
- plugins: [i18n],
11
- },
12
- });
6
+ return mount(MultiSelectOption, { props });
13
7
  };
14
8
 
15
9
  describe('MultiSelectOption.vue', () => {
@@ -78,54 +72,6 @@ describe('MultiSelectOption.vue', () => {
78
72
  });
79
73
  });
80
74
 
81
- describe('indeterminate state', () => {
82
- test('passes less to the checkbox modelValue', async () => {
83
- await wrapper.setProps({ active: 'less' });
84
- const checkbox = wrapper.findComponent({ name: 'UnnnicCheckbox' });
85
- expect(checkbox.props('modelValue')).toBe('less');
86
- });
87
-
88
- test('emits true when the checkbox is clicked while less', async () => {
89
- await wrapper.setProps({ active: 'less' });
90
- const checkbox = wrapper.findComponent({ name: 'UnnnicCheckbox' });
91
-
92
- await checkbox.vm.$emit('update:model-value', false);
93
-
94
- expect(wrapper.emitted('update:modelValue')[0][0]).toBe(true);
95
- });
96
- });
97
-
98
- describe('tree props', () => {
99
- test('renders the expand button and emits update:expanded', async () => {
100
- await wrapper.setProps({ expandable: true, expanded: false });
101
-
102
- const button = wrapper.find('.unnnic-multi-select-option__expand');
103
- expect(button.exists()).toBe(true);
104
- expect(button.attributes('aria-expanded')).toBe('false');
105
-
106
- await button.trigger('click');
107
-
108
- expect(wrapper.emitted('update:expanded')[0][0]).toBe(true);
109
- });
110
-
111
- test('applies the level 2 modifier class', async () => {
112
- await wrapper.setProps({ level: 2 });
113
- expect(wrapper.classes()).toContain(
114
- 'unnnic-multi-select-option--level-2',
115
- );
116
- });
117
-
118
- test('renders a spacer on a root leaf', async () => {
119
- await wrapper.setProps({ level: 1, expandable: false });
120
- expect(
121
- wrapper.find('.unnnic-multi-select-option__expand-spacer').exists(),
122
- ).toBe(true);
123
- expect(wrapper.find('.unnnic-multi-select-option__expand').exists()).toBe(
124
- false,
125
- );
126
- });
127
- });
128
-
129
75
  describe('active state', () => {
130
76
  test('passes active prop to checkbox modelValue when active is true', async () => {
131
77
  await wrapper.setProps({ active: true });
@@ -2,7 +2,6 @@
2
2
 
3
3
  exports[`MultiSelectOption.vue > snapshot testing > matches snapshot with active state 1`] = `
4
4
  "<div data-v-7d79eb5d="" class="unnnic-multi-select-option">
5
- <!--v-if-->
6
5
  <section data-v-18939422="" data-v-7d79eb5d="" class="unnnic-checkbox"><label data-v-18939422="" class="unnnic-checkbox__input-wrapper"><input data-v-18939422="" class="unnnic-checkbox__input" type="checkbox" checked="">
7
6
  <p data-v-18939422="" class="unnnic-checkbox__label" data-testid="checkbox-text-right">Test Option</p>
8
7
  </label>
@@ -13,7 +12,6 @@ exports[`MultiSelectOption.vue > snapshot testing > matches snapshot with active
13
12
 
14
13
  exports[`MultiSelectOption.vue > snapshot testing > matches snapshot with both active and disabled states 1`] = `
15
14
  "<div data-v-7d79eb5d="" class="unnnic-multi-select-option">
16
- <!--v-if-->
17
15
  <section data-v-18939422="" data-v-7d79eb5d="" class="unnnic-checkbox"><label data-v-18939422="" class="unnnic-checkbox__input-wrapper unnnic-checkbox__input-wrapper--disabled"><input data-v-18939422="" class="unnnic-checkbox__input" type="checkbox" disabled="" checked="">
18
16
  <p data-v-18939422="" class="unnnic-checkbox__label unnnic-checkbox__label--disabled" data-testid="checkbox-text-right">Test Option</p>
19
17
  </label>
@@ -24,7 +22,6 @@ exports[`MultiSelectOption.vue > snapshot testing > matches snapshot with both a
24
22
 
25
23
  exports[`MultiSelectOption.vue > snapshot testing > matches snapshot with default props 1`] = `
26
24
  "<div data-v-7d79eb5d="" class="unnnic-multi-select-option">
27
- <!--v-if-->
28
25
  <section data-v-18939422="" data-v-7d79eb5d="" class="unnnic-checkbox"><label data-v-18939422="" class="unnnic-checkbox__input-wrapper"><input data-v-18939422="" class="unnnic-checkbox__input" type="checkbox">
29
26
  <p data-v-18939422="" class="unnnic-checkbox__label" data-testid="checkbox-text-right">Test Option</p>
30
27
  </label>
@@ -35,7 +32,6 @@ exports[`MultiSelectOption.vue > snapshot testing > matches snapshot with defaul
35
32
 
36
33
  exports[`MultiSelectOption.vue > snapshot testing > matches snapshot with disabled state 1`] = `
37
34
  "<div data-v-7d79eb5d="" class="unnnic-multi-select-option">
38
- <!--v-if-->
39
35
  <section data-v-18939422="" data-v-7d79eb5d="" class="unnnic-checkbox"><label data-v-18939422="" class="unnnic-checkbox__input-wrapper unnnic-checkbox__input-wrapper--disabled"><input data-v-18939422="" class="unnnic-checkbox__input" type="checkbox" disabled="">
40
36
  <p data-v-18939422="" class="unnnic-checkbox__label unnnic-checkbox__label--disabled" data-testid="checkbox-text-right">Test Option</p>
41
37
  </label>
@@ -46,7 +42,6 @@ exports[`MultiSelectOption.vue > snapshot testing > matches snapshot with disabl
46
42
 
47
43
  exports[`MultiSelectOption.vue > snapshot testing > matches snapshot with focused state 1`] = `
48
44
  "<div data-v-7d79eb5d="" class="unnnic-multi-select-option">
49
- <!--v-if-->
50
45
  <section data-v-18939422="" data-v-7d79eb5d="" class="unnnic-checkbox"><label data-v-18939422="" class="unnnic-checkbox__input-wrapper"><input data-v-18939422="" class="unnnic-checkbox__input" type="checkbox">
51
46
  <p data-v-18939422="" class="unnnic-checkbox__label" data-testid="checkbox-text-right">Test Option</p>
52
47
  </label>
@@ -48,28 +48,16 @@
48
48
  {{ $t('without_results') }}
49
49
  </p>
50
50
  <template v-else>
51
- <UnnnicMultiSelectTreeOptions
52
- v-if="isTreeMode"
53
- :groups="optionGroups"
54
- :itemLabel="props.itemLabel"
55
- :itemValue="props.itemValue"
56
- :focusedIndex="focusedOptionIndex"
57
- @select="toggleOption"
58
- @expand="toggleExpanded"
59
- />
60
- <div
61
- v-else
62
- class="unnnic-multi-select__options"
63
- >
51
+ <div class="unnnic-multi-select__options">
64
52
  <UnnnicMultiSelectOption
65
- v-for="row in visibleRows"
66
- :key="String(row.option[props.itemValue])"
67
- :data-option-index="row.index"
68
- :label="String(row.option[props.itemLabel] ?? '')"
69
- :active="row.checkState"
70
- :focused="focusedOptionIndex === row.index"
71
- :disabled="row.option.disabled"
72
- @update:model-value="toggleOption(row.option, $event)"
53
+ v-for="(option, index) in filteredOptions"
54
+ :key="String(option[props.itemValue])"
55
+ :data-option-index="index"
56
+ :label="String(option[props.itemLabel] ?? '')"
57
+ :active="getActivatedOptionStatus(option)"
58
+ :focused="focusedOptionIndex === index"
59
+ :disabled="option.disabled"
60
+ @update:model-value="handleSelectOption(option, $event)"
73
61
  />
74
62
  </div>
75
63
  <div
@@ -97,13 +85,9 @@ import { Popover, PopoverTrigger, PopoverContent } from '../ui/popover';
97
85
  import UnnnicInput from '../Input/Input.vue';
98
86
  import UnnnicIconLoading from '../IconLoading/IconLoading.vue';
99
87
  import UnnnicMultiSelectOption from './MultiSelectOption.vue';
100
- import UnnnicMultiSelectTreeOptions from './MultiSelectTreeOptions.vue';
101
88
 
102
89
  import { useSelectBase } from '../../composables/useSelectBase';
103
90
  import { useSelectKeyboard } from '../../composables/useSelectKeyboard';
104
- import { useMultiSelectSelection } from '../../composables/useMultiSelectSelection';
105
- import { useMultiSelectRows } from '../../composables/useMultiSelectRows';
106
- import { filterTreeOptions } from '../../lib/tree-selection';
107
91
  import type { SelectBaseProps, SelectOption } from '../Select/types';
108
92
 
109
93
  defineOptions({
@@ -147,41 +131,26 @@ const emit = defineEmits<{
147
131
  const multiSelectInputRef = useTemplateRef<HTMLElement>('multiSelectInputRef');
148
132
  const contentRef = useTemplateRef<HTMLDivElement>('contentRef');
149
133
 
150
- const base = useSelectBase(props, 'multi', multiSelectInputRef, contentRef, {
151
- filterOptions: filterTreeOptions,
152
- });
134
+ const base = useSelectBase(props, 'multi', multiSelectInputRef, contentRef);
153
135
 
154
136
  const openPopover = base.openPopover;
155
137
  const popoverContentCustomStyles = base.popoverContentCustomStyles;
156
138
  const inputWidthString = base.inputWidthString;
157
139
  const filteredOptions = base.filteredOptions;
158
140
 
159
- const {
160
- isTreeMode,
161
- getCheckState,
162
- toggleOption,
163
- toggle,
164
- displayItems: selectedItems,
165
- } = useMultiSelectSelection(props, emit);
166
-
167
- const {
168
- optionGroups,
169
- visibleRows,
170
- toggleExpanded,
171
- resetExpanded,
172
- handleArrowRight,
173
- handleArrowLeft,
174
- } = useMultiSelectRows(props, {
175
- filteredOptions: base.filteredOptions,
176
- isSearchActive: base.isSearchActive,
177
- matchesSearch: base.matchesSearch,
178
- getCheckState,
179
- });
180
-
181
141
  function setOpenPopover(value: boolean) {
182
142
  base.openPopover.value = value;
183
143
  }
184
144
 
145
+ const selectedItems = computed<SelectOption[]>(() => {
146
+ if (props.returnObject) return props.modelValue as SelectOption[];
147
+
148
+ const valueIds = props.modelValue.slice();
149
+ return props.options.filter((option) =>
150
+ valueIds.includes(option[props.itemValue]),
151
+ );
152
+ });
153
+
185
154
  const inputValue = computed(() =>
186
155
  selectedItems.value.map((item) => item[props.itemLabel]).join(', '),
187
156
  );
@@ -190,16 +159,42 @@ function handleSearch(value: string) {
190
159
  emit('update:search', value);
191
160
  }
192
161
 
162
+ function getActivatedOptionStatus(option: SelectOption) {
163
+ if (props.returnObject) {
164
+ return (props.modelValue as SelectOption[]).some(
165
+ (item) => item[props.itemValue] === option[props.itemValue],
166
+ );
167
+ }
168
+ return props.modelValue.includes(option[props.itemValue]);
169
+ }
170
+
171
+ function handleSelectOption(option: SelectOption, selected: boolean) {
172
+ if (selected) {
173
+ const value = props.returnObject
174
+ ? [...props.modelValue, option]
175
+ : [...props.modelValue, option[props.itemValue]];
176
+ emit('update:modelValue', value);
177
+ } else {
178
+ const value = props.returnObject
179
+ ? (props.modelValue as SelectOption[]).filter(
180
+ (item) => item[props.itemValue] !== option[props.itemValue],
181
+ )
182
+ : props.modelValue.filter((item) => item !== option[props.itemValue]);
183
+ emit('update:modelValue', value);
184
+ }
185
+ }
186
+
193
187
  const keyboard = useSelectKeyboard<SelectOption>(
194
- () => visibleRows.value.map((row) => row.option),
195
- toggle,
188
+ () => base.filteredOptions.value,
189
+ (option) => {
190
+ if (option.disabled) return;
191
+ const active = getActivatedOptionStatus(option);
192
+ handleSelectOption(option, !active);
193
+ },
196
194
  {
197
195
  closeOnSelect: false,
198
196
  closePopover: () => setOpenPopover(false),
199
197
  openPopoverRef: base.openPopover,
200
- toggleOnSpace: isTreeMode,
201
- onArrowRight: handleArrowRight,
202
- onArrowLeft: handleArrowLeft,
203
198
  },
204
199
  );
205
200
 
@@ -246,7 +241,6 @@ watch(base.openPopover, (isOpen) => {
246
241
  if (!isOpen) {
247
242
  handleSearch('');
248
243
  infiniteScrollLoading.value = false;
249
- resetExpanded();
250
244
  return;
251
245
  }
252
246
 
@@ -287,7 +281,6 @@ defineExpose({
287
281
 
288
282
  :deep(.unnnic-multi-select__input) {
289
283
  @include shared.select-input-trigger;
290
- @include shared.select-input-ellipsis;
291
284
  }
292
285
 
293
286
  :deep(.unnnic-multi-select__input-search) {
@@ -8,14 +8,6 @@
8
8
  }
9
9
  }
10
10
 
11
- @mixin select-input-ellipsis {
12
- .input-itself {
13
- overflow: hidden;
14
- text-overflow: ellipsis;
15
- white-space: nowrap;
16
- }
17
- }
18
-
19
11
  @mixin select-input-search {
20
12
  > .icon-left {
21
13
  color: $unnnic-color-fg-base;
@@ -6,7 +6,6 @@ export interface SelectOption {
6
6
  label?: string;
7
7
  value?: string;
8
8
  disabled?: boolean;
9
- children?: SelectOption[];
10
9
  [key: string]: unknown;
11
10
  }
12
11
 
@@ -0,0 +1,88 @@
1
+ import { mount } from '@vue/test-utils';
2
+ import { describe, it, expect } from 'vitest';
3
+ import SelectTime from '../index.vue';
4
+
5
+ function mountSelectTime(props = {}) {
6
+ return mount(SelectTime, {
7
+ props: {
8
+ modelValue: '',
9
+ ...props,
10
+ },
11
+ });
12
+ }
13
+
14
+ describe('SelectTime', () => {
15
+ it('uses a native time input when enable24hTime is off', () => {
16
+ const wrapper = mountSelectTime({ modelValue: '24:00' });
17
+ const input = wrapper.find('input');
18
+
19
+ expect(input.attributes('type')).toBe('time');
20
+ expect(wrapper.text()).not.toContain('24:00');
21
+ });
22
+
23
+ it('clears 24:00 on blur when enable24hTime is off', () => {
24
+ const wrapper = mountSelectTime({ modelValue: '24:00' });
25
+
26
+ wrapper.vm.handleBlur();
27
+
28
+ expect(wrapper.emitted('update:modelValue').at(-1)).toEqual(['']);
29
+ });
30
+
31
+ describe('enable24hTime', () => {
32
+ it('renders 24:00 in a text input and lists it as an option', () => {
33
+ const wrapper = mountSelectTime({
34
+ modelValue: '24:00',
35
+ enable24hTime: true,
36
+ });
37
+ const input = wrapper.find('input');
38
+
39
+ expect(input.attributes('type')).toBe('text');
40
+ expect(input.element.value).toBe('24:00');
41
+ expect(wrapper.text()).toContain('24:00');
42
+ });
43
+
44
+ it('keeps 24:00 on blur', () => {
45
+ const wrapper = mountSelectTime({
46
+ modelValue: '24:00',
47
+ enable24hTime: true,
48
+ });
49
+
50
+ wrapper.vm.handleBlur();
51
+
52
+ expect(wrapper.emitted('update:modelValue').at(-1)).toEqual(['24:00']);
53
+ });
54
+
55
+ it('formats 2400 as 24:00', () => {
56
+ const wrapper = mountSelectTime({
57
+ modelValue: '2400',
58
+ enable24hTime: true,
59
+ });
60
+
61
+ wrapper.vm.handleBlur();
62
+
63
+ expect(wrapper.emitted('update:modelValue').at(-1)).toEqual(['24:00']);
64
+ });
65
+
66
+ it('formats 24 as 24:00', () => {
67
+ const wrapper = mountSelectTime({
68
+ modelValue: '24',
69
+ enable24hTime: true,
70
+ });
71
+
72
+ wrapper.vm.handleBlur();
73
+
74
+ expect(wrapper.emitted('update:modelValue').at(-1)).toEqual(['24:00']);
75
+ });
76
+
77
+ it('clears 24:30 because only 24:00 is valid past 23:59', () => {
78
+ const wrapper = mountSelectTime({
79
+ modelValue: '24:30',
80
+ enable24hTime: true,
81
+ });
82
+
83
+ wrapper.vm.handleBlur();
84
+
85
+ expect(wrapper.emitted('update:modelValue').at(-1)).toEqual(['']);
86
+ });
87
+ });
88
+ });
@@ -13,7 +13,7 @@
13
13
  <TextInput
14
14
  :modelValue="modelValue"
15
15
  :iconRight="active ? 'keyboard_arrow_up' : 'keyboard_arrow_down'"
16
- nativeType="time"
16
+ :nativeType="enable24hTime ? 'text' : 'time'"
17
17
  :placeholder="placeholder"
18
18
  :disabled="disabled"
19
19
  class="unnnic-select-time__input"
@@ -29,7 +29,7 @@
29
29
  class="unnnic-select-time__options"
30
30
  >
31
31
  <section
32
- v-for="hour in options"
32
+ v-for="hour in timeOptions"
33
33
  :ref="`hour-${hour.value}`"
34
34
  :key="hour.value"
35
35
  :class="{
@@ -82,6 +82,10 @@ export default {
82
82
  type: Boolean,
83
83
  default: false,
84
84
  },
85
+ enable24hTime: {
86
+ type: Boolean,
87
+ default: false,
88
+ },
85
89
  },
86
90
  emits: ['update:modelValue'],
87
91
  data() {
@@ -89,10 +93,21 @@ export default {
89
93
  active: false,
90
94
  };
91
95
  },
96
+ computed: {
97
+ timeOptions() {
98
+ const options = this.options.filter((hour) => hour.value !== '24:00');
99
+
100
+ if (!this.enable24hTime) {
101
+ return options;
102
+ }
103
+
104
+ return [...options, { label: '24:00', value: '24:00' }];
105
+ },
106
+ },
92
107
  methods: {
93
108
  handleInput(text) {
94
109
  const { value } =
95
- this.options.find((hour) => hour.value.includes(text)) || {};
110
+ this.timeOptions.find((hour) => hour.value.includes(text)) || {};
96
111
 
97
112
  if (value) {
98
113
  const hourRef = this.$refs[`hour-${value}`][0];
@@ -112,11 +127,15 @@ export default {
112
127
  let formattedTime = '';
113
128
 
114
129
  if (cleanValue.length === 4) {
115
- // Format: 0101 -> 01:01, 1310 -> 13:10
130
+ // Format: 0101 -> 01:01, 1310 -> 13:10, 2400 -> 24:00
116
131
  const hours = cleanValue.substring(0, 2);
117
132
  const minutes = cleanValue.substring(2, 4);
133
+ const hoursNumber = parseInt(hours, 10);
134
+ const minutesNumber = parseInt(minutes, 10);
135
+ const isEndOfDay =
136
+ this.enable24hTime && hoursNumber === 24 && minutesNumber === 0;
118
137
 
119
- if (parseInt(hours) <= 23 && parseInt(minutes) <= 59) {
138
+ if ((hoursNumber <= 23 && minutesNumber <= 59) || isEndOfDay) {
120
139
  formattedTime = `${hours}:${minutes}`;
121
140
  }
122
141
  } else if (cleanValue.length === 3) {
@@ -128,9 +147,14 @@ export default {
128
147
  formattedTime = `${hours}:${minutes}`;
129
148
  }
130
149
  } else if (cleanValue.length === 2) {
131
- // Format: 12 -> 12:00
150
+ // Format: 12 -> 12:00, 24 -> 24:00 when enable24hTime is on
132
151
  const hours = cleanValue;
133
- formattedTime = `${hours}:00`;
152
+ const hoursNumber = parseInt(hours, 10);
153
+ const isEndOfDay = hoursNumber === 24;
154
+
155
+ if (!isEndOfDay || this.enable24hTime) {
156
+ formattedTime = `${hours}:00`;
157
+ }
134
158
  } else if (cleanValue.length === 1) {
135
159
  // Format: 1 -> 01:00
136
160
  const hours = `0${cleanValue}`;
@@ -11,16 +11,6 @@ import type {
11
11
 
12
12
  export type SelectVariant = 'single' | 'multi';
13
13
 
14
- export type SelectOptionMatcher = (option: SelectOption) => boolean;
15
-
16
- export interface UseSelectBaseOptions {
17
- /** Picks the options kept by a search. Defaults to the matching options. */
18
- filterOptions?: (
19
- options: SelectOption[],
20
- matches: SelectOptionMatcher,
21
- ) => SelectOption[];
22
- }
23
-
24
14
  export interface UseSelectBaseProps {
25
15
  options: SelectOption[];
26
16
  itemLabel: string;
@@ -43,40 +33,28 @@ export function useSelectBase(
43
33
  variant: SelectVariant,
44
34
  triggerRef: SelectTriggerRef,
45
35
  contentRef: SelectContentRef,
46
- {
47
- filterOptions = (options, matches) => options.filter(matches),
48
- }: UseSelectBaseOptions = {},
49
36
  ) {
50
37
  const openPopover = ref(false);
51
38
 
52
39
  const { width: inputWidth } = useElementSize(triggerRef);
53
40
  const inputWidthString = computed(() => `${inputWidth.value}px`);
54
41
 
55
- const isSearchActive = computed(
56
- () => props.enableSearch && Boolean(props.search),
57
- );
58
-
59
- /** Every option matches while the search is inactive. */
60
- function matchesSearch(option: SelectOption) {
61
- if (!isSearchActive.value) return true;
62
- const searchLower = props.search.toLowerCase();
63
-
64
- const matchLabel = String(option[props.itemLabel] ?? '')
65
- .toLowerCase()
66
- .includes(searchLower);
67
-
68
- const matchValue = String(option[props.itemValue] ?? '')
69
- .toLowerCase()
70
- .includes(searchLower);
71
-
72
- return matchLabel || matchValue;
73
- }
74
-
75
- const filteredOptions = computed(() =>
76
- isSearchActive.value
77
- ? filterOptions(props.options, matchesSearch)
78
- : props.options,
79
- );
42
+ const filteredOptions = computed(() => {
43
+ const opts = props.options;
44
+ if (!props.enableSearch || !props.search) return opts;
45
+ const searchLower = props.search?.toLowerCase() ?? '';
46
+ return opts.filter((option) => {
47
+ const matchLabel = String(option[props.itemLabel] ?? '')
48
+ .toLowerCase()
49
+ .includes(searchLower);
50
+
51
+ const matchValue = String(option[props.itemValue] ?? '')
52
+ .toLowerCase()
53
+ .includes(searchLower);
54
+
55
+ return matchLabel || matchValue;
56
+ });
57
+ });
80
58
 
81
59
  function calcPopoverHeight(params: SelectPopoverHeightParams): string {
82
60
  const {
@@ -136,8 +114,6 @@ export function useSelectBase(
136
114
  inputWidthString,
137
115
  calculatedPopoverHeight,
138
116
  popoverContentCustomStyles,
139
- isSearchActive,
140
- matchesSearch,
141
117
  filteredOptions,
142
118
  };
143
119
  }