@@ -13,7 +13,6 @@ import {
13
13
defineComponent ,
14
14
h ,
15
15
inject ,
16
- nextTick ,
17
16
onMounted ,
18
17
onUnmounted ,
19
18
ref ,
@@ -73,6 +72,8 @@ export default defineComponent({
73
72
74
73
const inputElement = shallowRef < HTMLInputElement > ( )
75
74
const suggestionsElement = shallowRef < HTMLDivElement > ( )
75
+ const body = shallowRef < HTMLElement > ( )
76
+ const isLocked = useScrollLock ( body . value )
76
77
77
78
const hasSuggestions = computed (
78
79
( ) =>
@@ -99,38 +100,38 @@ export default defineComponent({
99
100
}
100
101
} )
101
102
102
- const updateQueries = useDebounceFn (
103
- ( ) : void => {
104
- void (
105
- searchOptions . value . querySplitter ?.( input . value ) ??
106
- Promise . resolve ( input . value . split ( ' ' ) )
107
- ) . then ( ( result ) => {
108
- queries . value = result
109
- } )
110
- } ,
111
- Math . min ( options . searchDelay , options . suggestDelay ) ,
112
- )
103
+ onClickOutside ( suggestionsElement , ( ) => {
104
+ showSuggestion . value = false
105
+ } )
113
106
114
- watchImmediate ( input , updateQueries )
107
+ watchImmediate (
108
+ input ,
109
+ useDebounceFn (
110
+ ( ) =>
111
+ (
112
+ searchOptions . value . querySplitter ?.( input . value ) ??
113
+ Promise . resolve ( input . value . split ( ' ' ) )
114
+ ) . then ( ( result ) => {
115
+ queries . value = result
116
+ } ) ,
117
+ Math . min ( options . searchDelay , options . suggestDelay ) ,
118
+ ) ,
119
+ )
115
120
116
121
onMounted ( ( ) => {
117
- const isLocked = useScrollLock ( document . body )
118
-
119
- watch ( isActive , async ( value ) => {
120
- isLocked . value = value
121
- if ( value ) {
122
- await nextTick ( )
123
- inputElement . value ?. focus ( )
124
- }
125
- } )
122
+ body . value = document . body
126
123
127
- onClickOutside ( suggestionsElement , ( ) => {
128
- showSuggestion . value = false
129
- } )
124
+ watch (
125
+ isActive ,
126
+ ( value ) => {
127
+ if ( value ) inputElement . value ?. focus ( )
128
+ } ,
129
+ { flush : 'post' } ,
130
+ )
131
+ } )
130
132
131
- onUnmounted ( ( ) => {
132
- isLocked . value = false
133
- } )
133
+ onUnmounted ( ( ) => {
134
+ isLocked . value = false
134
135
} )
135
136
136
137
return ( ) : VNode | null =>
0 commit comments