@@ -27,7 +27,7 @@ export default function AutocompleteInput({
27
27
queryHistoryType,
28
28
} : {
29
29
inputRef : React . RefObject < HTMLInputElement > ;
30
- value : string ;
30
+ value ? : string ;
31
31
onChange : ( value : string ) => void ;
32
32
onSubmit ?: ( ) => void ;
33
33
placeholder ?: string ;
@@ -64,7 +64,7 @@ export default function AutocompleteInput({
64
64
label : q ,
65
65
} ;
66
66
} ) ;
67
- } , [ queryHistory ] ) ;
67
+ } , [ queryHistory , queryHistoryType ] ) ;
68
68
69
69
useEffect ( ( ) => {
70
70
if ( isSearchInputFocused ) {
@@ -74,7 +74,12 @@ export default function AutocompleteInput({
74
74
75
75
useEffect ( ( ) => {
76
76
// only show search history when: 1.no input, 2.has search type, 3.has history list
77
- if ( value . length === 0 && queryHistoryList . length > 0 && queryHistoryType ) {
77
+ if (
78
+ value != null &&
79
+ value . length === 0 &&
80
+ queryHistoryList . length > 0 &&
81
+ queryHistoryType
82
+ ) {
78
83
setShowSearchHistory ( true ) ;
79
84
} else {
80
85
setShowSearchHistory ( false ) ;
@@ -114,8 +119,10 @@ export default function AutocompleteInput({
114
119
setSelectedAutocompleteIndex ( - 1 ) ;
115
120
116
121
const newValue =
117
- value . split ( ' ' ) . slice ( 0 , - 1 ) . join ( ' ' ) +
118
- `${ value . split ( ' ' ) . length > 1 ? ' ' : '' } ${ suggestion } ` ;
122
+ value == null
123
+ ? suggestion
124
+ : value . split ( ' ' ) . slice ( 0 , - 1 ) . join ( ' ' ) +
125
+ `${ value . split ( ' ' ) . length > 1 ? ' ' : '' } ${ suggestion } ` ;
119
126
onChange ( newValue ) ;
120
127
inputRef . current ?. focus ( ) ;
121
128
} ;
@@ -274,7 +281,7 @@ export default function AutocompleteInput({
274
281
suggestedProperties [ selectedAutocompleteIndex ] . value ,
275
282
) ;
276
283
} else {
277
- if ( queryHistoryType ) {
284
+ if ( queryHistoryType && value ) {
278
285
setQueryHistory ( value ) ;
279
286
}
280
287
onSubmit ?.( ) ;
0 commit comments