From b02a6989471a018f41d2a5a4059d9fc23238e74f Mon Sep 17 00:00:00 2001 From: Emma Indal Date: Wed, 17 Nov 2021 17:16:40 +0100 Subject: [PATCH] use material-uis autoFocus prop as an option, not default Signed-off-by: Emma Indal --- .../SearchBar/SearchBar.stories.tsx | 4 +++- .../src/components/SearchBar/SearchBar.tsx | 23 ++++++++----------- .../components/SearchModal/SearchModal.tsx | 1 - 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/plugins/search/src/components/SearchBar/SearchBar.stories.tsx b/plugins/search/src/components/SearchBar/SearchBar.stories.tsx index 27a739006a..72b8429026 100644 --- a/plugins/search/src/components/SearchBar/SearchBar.stories.tsx +++ b/plugins/search/src/components/SearchBar/SearchBar.stories.tsx @@ -71,7 +71,9 @@ export const Focused = () => { - + {/* decision up to adopter, read https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-autofocus.md#no-autofocus */} + {/* eslint-disable-next-line jsx-a11y/no-autofocus */} + diff --git a/plugins/search/src/components/SearchBar/SearchBar.tsx b/plugins/search/src/components/SearchBar/SearchBar.tsx index 5d503c5c44..c1730bfcff 100644 --- a/plugins/search/src/components/SearchBar/SearchBar.tsx +++ b/plugins/search/src/components/SearchBar/SearchBar.tsx @@ -30,11 +30,11 @@ type PresenterProps = { onSubmit?: () => void; className?: string; placeholder?: string; - focused?: boolean; + autoFocus?: boolean; }; export const SearchBarBase = ({ - focused, + autoFocus, value, onChange, onSubmit, @@ -42,13 +42,6 @@ export const SearchBarBase = ({ placeholder: overridePlaceholder, }: PresenterProps) => { const configApi = useApi(configApiRef); - const inputRef = useRef(); - - useEffect(() => { - if (focused) { - inputRef?.current?.focus(); - } - }, [focused]); const onKeyDown = React.useCallback( (e: KeyboardEvent) => { @@ -69,7 +62,9 @@ export const SearchBarBase = ({ return ( {