diff --git a/src/components/Search/SearchPageHeaderInput.tsx b/src/components/Search/SearchPageHeaderInput.tsx index 21452d358e625..7e1021012bbe1 100644 --- a/src/components/Search/SearchPageHeaderInput.tsx +++ b/src/components/Search/SearchPageHeaderInput.tsx @@ -124,7 +124,7 @@ function SearchPageHeaderInput({queryJSON, children}: SearchPageHeaderInputProps const updatedSubstitutionsMap = getUpdatedSubstitutionsMap(userQuery, autocompleteSubstitutions); setAutocompleteSubstitutions(updatedSubstitutionsMap); - if (updatedUserQuery || textInputValue.length > 0) { + if (updatedUserQuery) { listRef.current?.updateAndScrollToFocusedIndex(0); } else { listRef.current?.updateAndScrollToFocusedIndex(-1); @@ -148,9 +148,12 @@ function SearchPageHeaderInput({queryJSON, children}: SearchPageHeaderInputProps setTextInputValue(''); setAutocompleteQueryValue(''); setIsAutocompleteListVisible(false); + } else { + setTextInputValue(queryText); + setAutocompleteQueryValue(queryText); } }, - [autocompleteSubstitutions, originalInputQuery, queryJSON.policyID], + [autocompleteSubstitutions, originalInputQuery, queryJSON.policyID, queryText], ); const onListItemPress = useCallback( @@ -260,6 +263,10 @@ function SearchPageHeaderInput({queryJSON, children}: SearchPageHeaderInputProps onSearchQueryChange={onSearchQueryChange} isFullWidth onSubmit={() => { + const focusedOption = listRef.current?.getFocusedOption(); + if (focusedOption) { + return; + } submitSearch(textInputValue); }} autoFocus={false}