Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search suggestion selectable #4610

Merged
merged 7 commits into from
Sep 5, 2023
Merged

Search suggestion selectable #4610

merged 7 commits into from
Sep 5, 2023

Conversation

kwasniew
Copy link
Contributor

@kwasniew kwasniew commented Sep 5, 2023

About the changes

We want search suggestions to be selectable
Screenshot 2023-09-05 at 11 30 01

To achieve that we hide suggestions on click outside search input and suggestions.

Important files

Discussion points

@vercel
Copy link

vercel bot commented Sep 5, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
unleash-monorepo-frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 5, 2023 0:51am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
unleash-docs ⬜️ Ignored (Inspect) Visit Preview Sep 5, 2023 0:51am

@@ -69,7 +70,8 @@ export const Search = ({
containerStyles,
debounceTime = 200,
}: ISearchProps) => {
const ref = useRef<HTMLInputElement>();
const searchInputRef = useRef<HTMLInputElement>(null);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renaming to meaningful distinction as we have 2 refs now in this component

ref.current?.blur();
if (document.activeElement === searchInputRef.current) {
searchInputRef.current?.blur();
setShowSuggestions(false);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previously there was onBlur action, now we need to explicitly hide suggestions

}
});
const placeholder = `${customPlaceholder ?? 'Search'} (${hotkey})`;

useOnClickOutside([searchInputRef, suggestionsRef], () =>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clicking outside the search input or search suggestions will hide suggestions

@@ -116,7 +123,6 @@ export const Search = ({
value={value}
onChange={e => onSearchChange(e.target.value)}
onFocus={() => setShowSuggestions(true)}
onBlur={() => setShowSuggestions(false)}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was preventing us from selecting text in the search suggestions

@kwasniew kwasniew changed the title Search suggestion exit Search suggestion selectable Sep 5, 2023
@kwasniew kwasniew merged commit 41858a4 into main Sep 5, 2023
12 of 15 checks passed
@kwasniew kwasniew deleted the search-suggestion-exit branch September 5, 2023 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants