diff --git a/apps/readest-app/src/app/reader/components/sidebar/SearchBar.tsx b/apps/readest-app/src/app/reader/components/sidebar/SearchBar.tsx index 711866eb..e58babdb 100644 --- a/apps/readest-app/src/app/reader/components/sidebar/SearchBar.tsx +++ b/apps/readest-app/src/app/reader/components/sidebar/SearchBar.tsx @@ -12,12 +12,14 @@ import SearchOptions from './SearchOptions'; const MINIMUM_SEARCH_TERM_LENGTH = 2; interface SearchBarProps { + isVisible: boolean; bookKey: string; searchTerm: string; onSearchResultChange: (results: BookSearchResult[]) => void; } const SearchBar: React.FC = ({ + isVisible, bookKey, searchTerm: term, onSearchResultChange, @@ -27,6 +29,7 @@ const SearchBar: React.FC = ({ const { getConfig, saveConfig } = useBookDataStore(); const { getView, getProgress } = useReaderStore(); const [searchTerm, setSearchTerm] = useState(term); + const inputRef = useRef(null); const view = getView(bookKey)!; const config = getConfig(bookKey)!; @@ -48,6 +51,12 @@ const SearchBar: React.FC = ({ // eslint-disable-next-line react-hooks/exhaustive-deps }, [term]); + useEffect(() => { + if (isVisible && inputRef.current) { + inputRef.current.focus(); + } + }, [isVisible]); + useEffect(() => { return () => { if (searchTimeout.current) { @@ -128,6 +137,7 @@ const SearchBar: React.FC = ({