Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
Input,
InputProps,
InputRef,
} from "antd";

import CaseSensitiveToggle, {CaseSensitiveToggleProps} from "./CaseSenstiveToggle";
Expand All @@ -9,7 +10,8 @@ import CaseSensitiveToggle, {CaseSensitiveToggleProps} from "./CaseSenstiveToggl
/**
* Antd Input props and case sensitive toggle props with suffix omitted since set by component.
*/
type InputWithCaseSensitiveProps = Omit<InputProps, "suffix"> & CaseSensitiveToggleProps;
type InputWithCaseSensitiveProps =
Omit<InputProps, "suffix"> & CaseSensitiveToggleProps & React.RefAttributes<InputRef>;

/**
* Antd Input with a built-in case sensitivity toggle.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
useState,
} from "react";

import type {InputRef} from "antd";
import {Nullable} from "src/typings/common";

import QueryBox from "../../../../components/QueryBox";
Expand All @@ -28,6 +29,7 @@ const QueryInput = () => {
const searchUiState = useSearchStore((state) => state.searchUiState);
const [pseudoProgress, setPseudoProgress] = useState<Nullable<number>>(null);
const intervalIdRef = useRef<number>(0);
const inputRef = useRef<InputRef>(null);

const handleCaseSensitiveChange = useCallback((newValue: boolean) => {
const {updateQueryIsCaseSensitive} = useSearchStore.getState();
Expand Down Expand Up @@ -67,11 +69,21 @@ const QueryInput = () => {
clearInterval(intervalIdRef.current);
}, []);

useEffect(() => {
if (
searchUiState === SEARCH_UI_STATE.DEFAULT ||
searchUiState === SEARCH_UI_STATE.DONE
) {
inputRef.current?.focus();
}
}, [searchUiState]);

return (
<QueryBox
isCaseSensitive={queryIsCaseSensitive}
placeholder={"Enter your query"}
progress={pseudoProgress}
ref={inputRef}
size={"large"}
value={queryString}
disabled={
Expand Down