Add autoFocus functionality to search.json

This commit is contained in:
Bastian Meissner 2022-03-08 20:53:17 +01:00
parent a743902445
commit cef0826587
5 changed files with 42 additions and 12 deletions

View file

@ -44,6 +44,7 @@ export interface ISearchProviderProps {
export interface ISearchProps {
placeholder: string;
defaultProvider: string;
autoFocus?: boolean;
providers: Array<ISearchProviderProps> | undefined;
}
@ -99,6 +100,10 @@ const SearchBar = ({ search }: ISearchBarProps) => {
e.preventDefault();
};
const autoFocus = () => {
return search.autoFocus !== undefined ? search.autoFocus : false;
};
return (
<Search onSubmit={(e) => handleSearchQuery(e)}>
<SearchInput
@ -106,6 +111,7 @@ const SearchBar = ({ search }: ISearchBarProps) => {
data-testid="search-input"
value={input}
placeholder={search.placeholder}
autoFocus={autoFocus()}
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
setInput(e.target.value)
}