-
-
Notifications
You must be signed in to change notification settings - Fork 658
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Ignored Deployment
|
@@ -69,7 +70,8 @@ export const Search = ({ | |||
containerStyles, | |||
debounceTime = 200, | |||
}: ISearchProps) => { | |||
const ref = useRef<HTMLInputElement>(); | |||
const searchInputRef = useRef<HTMLInputElement>(null); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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], () => |
There was a problem hiding this comment.
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)} |
There was a problem hiding this comment.
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
About the changes
We want search suggestions to be selectable
To achieve that we hide suggestions on click outside search input and suggestions.
Important files
Discussion points