From cc44229542453e9d4ee5cfd9b919448dea357d63 Mon Sep 17 00:00:00 2001 From: Isha Kakkad Date: Thu, 23 Jan 2025 00:18:17 +0530 Subject: [PATCH 1/6] Removing one value from Search filter clears the search --- src/components/Search/SearchPageHeaderInput.tsx | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/components/Search/SearchPageHeaderInput.tsx b/src/components/Search/SearchPageHeaderInput.tsx index 21452d358e62..5c4b24fbe89a 100644 --- a/src/components/Search/SearchPageHeaderInput.tsx +++ b/src/components/Search/SearchPageHeaderInput.tsx @@ -126,8 +126,6 @@ function SearchPageHeaderInput({queryJSON, children}: SearchPageHeaderInputProps if (updatedUserQuery || textInputValue.length > 0) { listRef.current?.updateAndScrollToFocusedIndex(0); - } else { - listRef.current?.updateAndScrollToFocusedIndex(-1); } }, [autocompleteSubstitutions, setTextInputValue, textInputValue], @@ -148,6 +146,9 @@ function SearchPageHeaderInput({queryJSON, children}: SearchPageHeaderInputProps setTextInputValue(''); setAutocompleteQueryValue(''); setIsAutocompleteListVisible(false); + } else { + setTextInputValue(queryText); + setAutocompleteQueryValue(queryText); } }, [autocompleteSubstitutions, originalInputQuery, queryJSON.policyID], @@ -257,10 +258,18 @@ function SearchPageHeaderInput({queryJSON, children}: SearchPageHeaderInputProps { + onSearchQueryChange(userQuery); + if (!userQuery) { + listRef.current?.updateAndScrollToFocusedIndex(-1); + } + }} isFullWidth onSubmit={() => { - submitSearch(textInputValue); + const focusedOption = listRef.current?.getFocusedOption(); + if (!focusedOption) { + submitSearch(textInputValue); + } }} autoFocus={false} onFocus={showAutocompleteList} From 488c11d1e62e9f3ea40f01ec121c252a8639d7d7 Mon Sep 17 00:00:00 2001 From: Isha Kakkad Date: Thu, 23 Jan 2025 12:37:07 +0530 Subject: [PATCH 2/6] Fix issue when selecting autocomplete suggestion. --- src/components/Search/SearchPageHeaderInput.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/Search/SearchPageHeaderInput.tsx b/src/components/Search/SearchPageHeaderInput.tsx index 5c4b24fbe89a..4719d1bfed83 100644 --- a/src/components/Search/SearchPageHeaderInput.tsx +++ b/src/components/Search/SearchPageHeaderInput.tsx @@ -266,8 +266,7 @@ function SearchPageHeaderInput({queryJSON, children}: SearchPageHeaderInputProps }} isFullWidth onSubmit={() => { - const focusedOption = listRef.current?.getFocusedOption(); - if (!focusedOption) { + if (isAutocompleteListVisible) { submitSearch(textInputValue); } }} From 885ee948e268cdbf29fa42dfd14be7abcab27414 Mon Sep 17 00:00:00 2001 From: Isha Kakkad Date: Thu, 23 Jan 2025 12:44:08 +0530 Subject: [PATCH 3/6] Fix useCallback missing dependancy --- src/components/Search/SearchPageHeaderInput.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Search/SearchPageHeaderInput.tsx b/src/components/Search/SearchPageHeaderInput.tsx index 4719d1bfed83..63b4f46b4dc8 100644 --- a/src/components/Search/SearchPageHeaderInput.tsx +++ b/src/components/Search/SearchPageHeaderInput.tsx @@ -151,7 +151,7 @@ function SearchPageHeaderInput({queryJSON, children}: SearchPageHeaderInputProps setAutocompleteQueryValue(queryText); } }, - [autocompleteSubstitutions, originalInputQuery, queryJSON.policyID], + [autocompleteSubstitutions, originalInputQuery, queryJSON.policyID, queryText], ); const onListItemPress = useCallback( From 45e48888a048864757126da1efbcb2069f5ecd33 Mon Sep 17 00:00:00 2001 From: Isha Kakkad Date: Thu, 23 Jan 2025 15:41:30 +0530 Subject: [PATCH 4/6] Fix eslint issues --- src/components/Search/SearchPageHeaderInput.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/components/Search/SearchPageHeaderInput.tsx b/src/components/Search/SearchPageHeaderInput.tsx index 63b4f46b4dc8..c7a51d6d2e35 100644 --- a/src/components/Search/SearchPageHeaderInput.tsx +++ b/src/components/Search/SearchPageHeaderInput.tsx @@ -260,15 +260,17 @@ function SearchPageHeaderInput({queryJSON, children}: SearchPageHeaderInputProps value={textInputValue} onSearchQueryChange={(userQuery) => { onSearchQueryChange(userQuery); - if (!userQuery) { - listRef.current?.updateAndScrollToFocusedIndex(-1); + if (userQuery) { + return; } + listRef.current?.updateAndScrollToFocusedIndex(-1); }} isFullWidth onSubmit={() => { - if (isAutocompleteListVisible) { - submitSearch(textInputValue); + if (!isAutocompleteListVisible) { + return; } + submitSearch(textInputValue); }} autoFocus={false} onFocus={showAutocompleteList} From 2820b29e7acff2cb553d994b78c184d639dd8c98 Mon Sep 17 00:00:00 2001 From: Isha Kakkad Date: Thu, 23 Jan 2025 22:04:35 +0530 Subject: [PATCH 5/6] Fix review comments --- src/components/Search/SearchPageHeaderInput.tsx | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/components/Search/SearchPageHeaderInput.tsx b/src/components/Search/SearchPageHeaderInput.tsx index c7a51d6d2e35..edbecca59db2 100644 --- a/src/components/Search/SearchPageHeaderInput.tsx +++ b/src/components/Search/SearchPageHeaderInput.tsx @@ -124,8 +124,10 @@ 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); } }, [autocompleteSubstitutions, setTextInputValue, textInputValue], @@ -258,16 +260,11 @@ function SearchPageHeaderInput({queryJSON, children}: SearchPageHeaderInputProps { - onSearchQueryChange(userQuery); - if (userQuery) { - return; - } - listRef.current?.updateAndScrollToFocusedIndex(-1); - }} + onSearchQueryChange={onSearchQueryChange} isFullWidth onSubmit={() => { - if (!isAutocompleteListVisible) { + const focusedOption = listRef.current?.getFocusedOption(); + if (focusedOption) { return; } submitSearch(textInputValue); From 82c553273b49476df631fb2d0a2726e80788a4bd Mon Sep 17 00:00:00 2001 From: Isha Kakkad Date: Thu, 23 Jan 2025 22:10:08 +0530 Subject: [PATCH 6/6] Fix prettier issues --- src/components/Search/SearchPageHeaderInput.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Search/SearchPageHeaderInput.tsx b/src/components/Search/SearchPageHeaderInput.tsx index edbecca59db2..7e1021012bbe 100644 --- a/src/components/Search/SearchPageHeaderInput.tsx +++ b/src/components/Search/SearchPageHeaderInput.tsx @@ -263,8 +263,8 @@ function SearchPageHeaderInput({queryJSON, children}: SearchPageHeaderInputProps onSearchQueryChange={onSearchQueryChange} isFullWidth onSubmit={() => { - const focusedOption = listRef.current?.getFocusedOption(); - if (focusedOption) { + const focusedOption = listRef.current?.getFocusedOption(); + if (focusedOption) { return; } submitSearch(textInputValue);