2020 px-1
2121 user-select-none
2222 cursor-pointer
23+ px-2
2324 `,
2425 index=== activeSuggestion && `bg-accent-200 dark:bg-accent-800`
2526 )"
2930 :key =" item"
3031 @mouseover =" activeSuggestion = index"
3132 @mousedown =" activeSuggestion = index; mousedown = true;"
32- @mouseup =" activeSuggestion = index; mousedown = true ;"
33+ @mouseup =" activeSuggestion = index; mousedown = false ;"
3334 @click =" setSelected()"
3435 >
3536 <slot name =" item" :item =" item" :index =" index" >
@@ -191,7 +192,13 @@ const openSuggestions = (): void => {
191192 if (! openable .value ) return
192193 $isOpen .value = true
193194 // see delay close
194- if (activeSuggestion .value === - 1 ) activeSuggestion .value = 0
195+ if (activeSuggestion .value === - 1 ) {
196+ if (exactlyMatchingSuggestion .value ) {
197+ activeSuggestion .value = suggestionsList .value ?.indexOf (exactlyMatchingSuggestion .value ) ?? - 1
198+ } else {
199+ activeSuggestion .value = 0
200+ }
201+ }
195202 // activeSuggestion.value = 0
196203}
197204watch (() => props .canOpen , val => {
@@ -211,21 +218,25 @@ watch(() => $modelValue.value, () => {
211218 $inputValue .value = getStringValue ($modelValue .value )
212219})
213220watch (() => $inputValue .value , () => {
214- if (props .restrictToSuggestions ) {
215- if (exactlyMatchingSuggestion .value !== undefined ) {
216- $modelValue .value = $inputValue .value
217- }
218- } else {
219- $modelValue .value = $inputValue .value
221+ if (props .restrictToSuggestions && ! exactlyMatchingSuggestion .value ) {
222+ return
220223 }
224+ $modelValue .value = $inputValue .value
225+ const i = suggestionsList .value ?.indexOf (exactlyMatchingSuggestion .value ) ?? - 1
226+ if (
227+ i === - 1
228+ && props .restrictToSuggestions
229+ && exactlyMatchingSuggestion .value !== undefined
230+ ) return
231+ activeSuggestion .value = i
221232})
222233watchPostEffect ((): void => {
223234 if (! openable .value ) {
224235 closeSuggestions ()
225236 return
226237 }
227238 if (suggestionAvailable .value ) {
228- if (! exactlyMatchingSuggestion .value || moreThanOneSuggestionAvailable .value ) {
239+ if (! $isOpen . value && ( ! exactlyMatchingSuggestion .value || moreThanOneSuggestionAvailable .value ) ) {
229240 openSuggestions ()
230241 }
231242 } else if (isValidSuggestion .value ) {
@@ -234,7 +245,7 @@ watchPostEffect((): void => {
234245})
235246
236247
237- const setSuggestion = (num : number ): void => {
248+ function setSuggestion(num : number ): void {
238249 if (fullSuggestionsList .value === undefined ) return
239250 const val = suggestionLabel .value (fullSuggestionsList .value [num ])
240251
0 commit comments