diff --git a/gui/src/renderer/components/SearchBar.tsx b/gui/src/renderer/components/SearchBar.tsx index 40f4614dd94b..c8c0bfa46be3 100644 --- a/gui/src/renderer/components/SearchBar.tsx +++ b/gui/src/renderer/components/SearchBar.tsx @@ -3,7 +3,7 @@ import styled from 'styled-components'; import { colors } from '../../config.json'; import { messages } from '../../shared/gettext'; -import { useStyledRef } from '../lib/utilityHooks'; +import { useCombinedRefs, useStyledRef } from '../lib/utilityHooks'; import { normalText } from './common-styles'; import ImageView from './ImageView'; @@ -71,12 +71,12 @@ interface ISearchBarProps { onSearch: (searchTerm: string) => void; className?: string; disableAutoFocus?: boolean; - hasLocationTypeChanged?: boolean; - resetLocationTypeChange?: () => void; + searchInputRef?: React.Ref; } export default function SearchBar(props: ISearchBarProps) { const inputRef = useStyledRef(); + const combinedRef = useCombinedRefs(inputRef, props.searchInputRef); const onInput = useCallback( (event: React.FormEvent) => { @@ -95,14 +95,12 @@ export default function SearchBar(props: ISearchBarProps) { if (!props.disableAutoFocus) { inputRef.current?.focus({ preventScroll: true }); } - - return () => props.resetLocationTypeChange?.(); - }, [props.hasLocationTypeChanged]); + }, []); return ( (); const changeLocationType = useCallback( (locationType: LocationType) => { saveScrollPosition(); setLocationType(locationType); - notifyLocationTypeChange(); + + console.log('### changeLocationType | searchInputRef.current', searchInputRef.current); + searchInputRef.current?.focus(); }, [saveScrollPosition], ); @@ -247,8 +248,7 @@ export default function SelectLocation() {