diff --git a/app/scenes/Search/components/SearchInput.tsx b/app/scenes/Search/components/SearchInput.tsx index 2f27779e7..36143a343 100644 --- a/app/scenes/Search/components/SearchInput.tsx +++ b/app/scenes/Search/components/SearchInput.tsx @@ -12,15 +12,22 @@ function SearchInput({ defaultValue, ...rest }: Props) { const theme = useTheme(); const inputRef = React.useRef(null); + const focusInput = React.useCallback(() => { + inputRef.current?.focus(); + }, []); + React.useEffect(() => { // ensure that focus is placed at end of input const len = (defaultValue || "").length; inputRef.current?.setSelectionRange(len, len); - }, [defaultValue]); + const timeoutId = setTimeout(() => { + focusInput(); + }, 100); // arbitrary number - const focusInput = React.useCallback(() => { - inputRef.current?.focus(); - }, []); + return () => { + clearTimeout(timeoutId); + }; + }, [defaultValue, focusInput]); return (