Fix searchbar options not visible and autofocus input

This commit is contained in:
chrox
2024-11-27 15:04:25 +01:00
parent a511db3b3a
commit 61950e1b4a
3 changed files with 17 additions and 5 deletions
@@ -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<SearchBarProps> = ({
isVisible,
bookKey,
searchTerm: term,
onSearchResultChange,
@@ -27,6 +29,7 @@ const SearchBar: React.FC<SearchBarProps> = ({
const { getConfig, saveConfig } = useBookDataStore();
const { getView, getProgress } = useReaderStore();
const [searchTerm, setSearchTerm] = useState(term);
const inputRef = useRef<HTMLInputElement>(null);
const view = getView(bookKey)!;
const config = getConfig(bookKey)!;
@@ -48,6 +51,12 @@ const SearchBar: React.FC<SearchBarProps> = ({
// 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<SearchBarProps> = ({
</div>
<input
ref={inputRef}
type='text'
value={searchTerm}
spellCheck={false}
@@ -124,6 +124,7 @@ const SideBar: React.FC<{
})}
>
<SearchBar
isVisible={isSearchBarVisible}
bookKey={sideBarBookKey!}
searchTerm={searchTerm}
onSearchResultChange={setSearchResults}
+6 -5
View File
@@ -15,22 +15,23 @@
}
}
html[data-page="default"] {
html[data-page='default'] {
background: #ffffff;
}
html[data-page="library"] {
html[data-page='library'] {
background: theme('colors.base-200');
}
html[data-page="reader"] {
html[data-page='reader'] {
background: theme('colors.base-100');
}
body {
color: var(--foreground);
background: var(--background);
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
sans-serif;
border-radius: 10px;
background-color: transparent;
}
@@ -175,7 +176,7 @@ foliate-view {
.search-bar {
max-height: 0;
visibility: hidden;
overflow: hidden;
overflow: visible;
transition: max-height 0.3s ease-out;
}