From 61950e1b4acf928f1be2686a1b066685de721208 Mon Sep 17 00:00:00 2001 From: chrox Date: Wed, 27 Nov 2024 15:04:25 +0100 Subject: [PATCH] Fix searchbar options not visible and autofocus input --- .../src/app/reader/components/sidebar/SearchBar.tsx | 10 ++++++++++ .../src/app/reader/components/sidebar/SideBar.tsx | 1 + apps/readest-app/src/styles/globals.css | 11 ++++++----- 3 files changed, 17 insertions(+), 5 deletions(-) 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 = ({