1
1
<template >
2
2
<NvAutocomplete
3
- :autoScrollIndex =" autoScrollIndex"
4
- :options =" searchResults"
5
- :valueKey =" props.valueKey"
6
- :visible =" isAutocompleteVisible"
7
- :width =" props.autocompleteWidth"
8
- @select =" (item) => !item.children && handleValue(item.value)"
9
- @positioner-change ="
3
+ :autoScrollIndex =" autoScrollIndex"
4
+ :options =" searchResults"
5
+ :valueKey =" props.valueKey"
6
+ :visible =" isAutocompleteVisible"
7
+ :width =" props.autocompleteWidth"
8
+ @select =" (item) => !item.children && handleValue(item.value)"
9
+ @positioner-change ="
10
10
($event) => {
11
11
autocomplete = $event
12
12
}
13
13
"
14
- @pointer-down-outside =" blurInput"
15
- @focus-outside =" blurInput"
16
- @interact-outside =" blurInput"
14
+ @pointer-down-outside =" blurInput"
15
+ @focus-outside =" blurInput"
16
+ @interact-outside =" blurInput"
17
17
>
18
18
<template #reference >
19
19
<StSelect
20
- ref =" select"
21
- :isFocused =" hasFocus"
22
- class =" w-full"
23
- v-bind =" { ...props, isFocused: hasFocus }"
24
- @click =" activate"
20
+ ref =" select"
21
+ :isFocused =" hasFocus"
22
+ class =" w-full"
23
+ v-bind =" { ...props, isFocused: hasFocus }"
24
+ @click =" activate"
25
25
>
26
26
<StSelectWrapper class =" w-full" v-bind =" props" >
27
27
<NvStack :spacing =" 2" class =" w-full" >
28
28
<template v-if =" props .multiple && selectedOptions .length > 0 " >
29
29
<StSelectTagsWrapper >
30
30
<NvGroup :spacing =" 2" class =" w-full" >
31
31
<template
32
- v-for =" option in selectedOptions "
33
- :key =" get (option .value , props .valueKey ) || option .value "
32
+ v-for =" option in selectedOptions "
33
+ :key =" get (option .value , props .valueKey ) || option .value "
34
34
>
35
35
<NvTag
36
- :title =" option.label"
37
- closable
38
- @close =" handleValue(option.value)"
39
- @mousedown =" blurInput()"
40
- @click.stop
36
+ :title =" option.label"
37
+ closable
38
+ @close =" handleValue(option.value)"
39
+ @mousedown =" blurInput()"
40
+ @click.stop
41
41
>
42
42
{{ option.label }}
43
43
</NvTag >
47
47
</template >
48
48
<div ref =" inputWrapper" class =" inline-flex" >
49
49
<StSelectInput
50
- ref =" selectInput"
51
- :isFocused =" hasFocus"
52
- :modelValue =" inputValue"
53
- :placeholder =" $attrs.placeholder"
54
- v-bind =" omit(props, ['modelValue'])"
55
- @focus =" activate"
56
- @update:modelValue =" search = $event"
50
+ ref =" selectInput"
51
+ :isFocused =" hasFocus"
52
+ :modelValue =" inputValue"
53
+ :placeholder =" $attrs.placeholder"
54
+ v-bind =" omit(props, ['modelValue'])"
55
+ @focus =" activate"
56
+ @update:modelValue =" search = $event"
57
57
/>
58
58
</div >
59
59
</NvStack >
60
60
</StSelectWrapper >
61
61
<StSelectIcon v-bind =" props" >
62
- <NvIcon :size =" iconSize" name =" direction" />
62
+ <NvIcon :size =" iconSize" name =" direction" />
63
63
</StSelectIcon >
64
64
</StSelect >
65
65
</template >
66
66
<template #default =" { active , item } " >
67
67
<NvOption
68
- v-if =" item"
69
- :active =" active"
70
- :disabled =" item.disabled"
71
- :readonly =" item.children"
72
- :selected ="
68
+ v-if =" item"
69
+ :active =" active"
70
+ :disabled =" item.disabled"
71
+ :readonly =" item.children"
72
+ :selected ="
73
73
selectedValues.find(
74
74
(v) =>
75
75
(get(item.value, props.valueKey) || item.value) ===
76
76
(get(v, props.valueKey) || v),
77
77
)
78
78
"
79
- :title =" item.label"
80
- v-bind =" item.attrs || {}"
81
- @mousedown =" !item.children && handleValue(item.value)"
79
+ :title =" item.label"
80
+ v-bind =" item.attrs || {}"
81
+ @mousedown =" !item.children && handleValue(item.value)"
82
82
>
83
83
<div class =" w-full text-ellipsis overflow-hidden" >
84
84
{{ item.label }}
85
85
</div >
86
86
<template #after =" props " >
87
- <slot :option =" item" name =" optionAfter" v-bind =" props" />
87
+ <slot :option =" item" name =" optionAfter" v-bind =" props" />
88
88
</template >
89
89
</NvOption >
90
90
</template >
91
91
<template #fallback >
92
92
<StSelectOption
93
- v-if =" searchResults.length === 0"
94
- class =" justify-center pointer-events-none"
93
+ v-if =" searchResults.length === 0"
94
+ class =" justify-center pointer-events-none"
95
95
>
96
96
No Data
97
97
</StSelectOption >
@@ -141,44 +141,44 @@ const iconSize = computed(() => {
141
141
})
142
142
143
143
const selectedValues = computed (() =>
144
- props .multiple ? (props .modelValue as Value []) : [props .modelValue ],
144
+ props .multiple ? (props .modelValue as Value []) : [props .modelValue ],
145
145
)
146
146
147
147
const options = computed (() =>
148
- flatten (
149
- props .options .map ((option ) => {
150
- if (option .children ) {
151
- const mappedChildren = option .children .map ((o ) => ({
152
- id: get (o .value , props .valueKey ) || o .value || uuid (),
153
- ... o ,
154
- }))
155
- return [
156
- {
157
- id: get (option .value , props .valueKey ) || option .value || uuid (),
158
- ... option ,
159
- children: mappedChildren ,
160
- },
161
- ... mappedChildren ,
162
- ]
163
- }
164
- return {
148
+ flatten (
149
+ props .options .map ((option ) => {
150
+ if (option .children ) {
151
+ const mappedChildren = option .children .map ((o ) => ({
152
+ id: get (o .value , props .valueKey ) || o .value || uuid (),
153
+ ... o ,
154
+ }))
155
+ return [
156
+ {
165
157
id: get (option .value , props .valueKey ) || option .value || uuid (),
166
158
... option ,
167
- }
168
- }),
169
- ),
159
+ children: mappedChildren ,
160
+ },
161
+ ... mappedChildren ,
162
+ ]
163
+ }
164
+ return {
165
+ id: get (option .value , props .valueKey ) || option .value || uuid (),
166
+ ... option ,
167
+ }
168
+ }),
169
+ ),
170
170
)
171
171
172
172
const selectedOptions = computed (() =>
173
- selectedValues .value
174
- .map ((value ) =>
175
- options .value .find (
176
- (option ) =>
177
- get (option .value , props .valueKey , option .value ) ===
178
- get (value , props .valueKey , value ),
179
- ),
180
- )
181
- .filter ((option ) => option !== undefined ),
173
+ selectedValues .value
174
+ .map ((value ) =>
175
+ options .value .find (
176
+ (option ) =>
177
+ get (option .value , props .valueKey , option .value ) ===
178
+ get (value , props .valueKey , value ),
179
+ ),
180
+ )
181
+ .filter ((option ) => option !== undefined ),
182
182
)
183
183
184
184
const search = ref (' ' )
@@ -199,22 +199,22 @@ const { hasFocus, activate, deactivate } = useFocusTrap(inputWrapper, {
199
199
const isAutocompleteVisible = ref (false )
200
200
201
201
watch (
202
- () => hasFocus .value ,
203
- (value ) => {
204
- if (value ) {
205
- isAutocompleteVisible .value = true
206
- }
207
- },
202
+ () => hasFocus .value ,
203
+ (value ) => {
204
+ if (value ) {
205
+ isAutocompleteVisible .value = true
206
+ }
207
+ },
208
208
)
209
209
210
210
const fuseOptions = computed <UseFuseOptions <(typeof options .value )[number ]>>(
211
- () => ({
212
- fuseOptions: {
213
- keys: [' label' , ' category' , ' searchValue' ],
214
- threshold: 0.3 ,
215
- shouldSort: false ,
216
- },
217
- }),
211
+ () => ({
212
+ fuseOptions: {
213
+ keys: [' label' , ' category' , ' searchValue' ],
214
+ threshold: 0.3 ,
215
+ shouldSort: false ,
216
+ },
217
+ }),
218
218
)
219
219
const { results } = useFuse (search , options , fuseOptions )
220
220
const searchResults = computed (() => {
@@ -223,7 +223,7 @@ const searchResults = computed(() => {
223
223
return options .value .filter ((option ) => {
224
224
if (' children' in option ) {
225
225
return filteredOptions .some ((o ) =>
226
- (option .children as Option []).find ((c ) => c .id === o .id ),
226
+ (option .children as Option []).find ((c ) => c .id === o .id ),
227
227
)
228
228
}
229
229
return filteredOptions .some ((o ) => o .id === option .id )
@@ -232,34 +232,34 @@ const searchResults = computed(() => {
232
232
return options .value || []
233
233
})
234
234
const inputValue = computed (
235
- () =>
236
- (! hasFocus .value && ! props .multiple && selectedOptions .value [0 ]?.label ) ||
237
- search .value ,
235
+ () =>
236
+ (! hasFocus .value && ! props .multiple && selectedOptions .value [0 ]?.label ) ||
237
+ search .value ,
238
238
)
239
239
240
240
const autoScrollIndex = computed (() => {
241
241
return (
242
- selectedValues .value .length > 0 &&
243
- Math .min (
244
- ... selectedValues .value
245
- .map ((v ) =>
246
- options .value .findIndex (
247
- (o ) =>
248
- get (o .value , props .valueKey , o .value ) ===
249
- get (v , props .valueKey , v ),
250
- ),
251
- )
252
- .filter ((i ) => i !== undefined ),
253
- )
242
+ selectedValues .value .length > 0 &&
243
+ Math .min (
244
+ ... selectedValues .value
245
+ .map ((v ) =>
246
+ options .value .findIndex (
247
+ (o ) =>
248
+ get (o .value , props .valueKey , o .value ) ===
249
+ get (v , props .valueKey , v ),
250
+ ),
251
+ )
252
+ .filter ((i ) => i !== undefined ),
253
+ )
254
254
)
255
255
})
256
256
257
257
const handleValue = (value : Value ) => {
258
258
if (props .multiple ) {
259
259
const newValue = [... selectedValues .value ]
260
260
const index = newValue .findIndex (
261
- (item ) =>
262
- get (item , props .valueKey , item ) === get (value , props .valueKey , value ),
261
+ (item ) =>
262
+ get (item , props .valueKey , item ) === get (value , props .valueKey , value ),
263
263
)
264
264
if (index > - 1 ) {
265
265
newValue .splice (index , 1 )
0 commit comments