Skip to content

Commit

Permalink
Fix header search field persisting after search is done (#697)
Browse files Browse the repository at this point in the history
  • Loading branch information
InfiniteStash authored Jul 20, 2023
1 parent fc3dc9a commit 2b08781
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion frontend/src/components/searchField/SearchField.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { FC, KeyboardEvent, useRef, useState } from "react";
import { useApolloClient } from "@apollo/client";
import { OnChangeValue, components } from "react-select";
import {
OnChangeValue,
components,
SelectInstance,
GroupBase,
} from "react-select";
import Async from "react-select/async";
import debounce from "p-debounce";
import { useNavigate } from "react-router-dom";
Expand Down Expand Up @@ -171,6 +176,8 @@ const SearchField: FC<SearchFieldProps> = ({
const navigate = useNavigate();
const [selectedValue, setSelected] = useState(null);
const searchTerm = useRef("");
const selectRef =
useRef<SelectInstance<SearchResult, false, GroupBase<SearchResult>>>(null);

const handleSearch = async (term: string) => {
if (term) {
Expand Down Expand Up @@ -212,6 +219,7 @@ const SearchField: FC<SearchFieldProps> = ({
const handleKeyDown = (e: KeyboardEvent<HTMLElement>) => {
if (e.key === "Enter" && searchTerm.current && showAllLink) {
navigate(createHref(ROUTE_SEARCH, { term: searchTerm.current }));
selectRef?.current?.blur();
}
};

Expand All @@ -224,6 +232,7 @@ const SearchField: FC<SearchFieldProps> = ({
loadOptions={handleLoad}
onChange={handleChange}
onKeyDown={handleKeyDown}
ref={selectRef}
placeholder={
placeholder ??
(searchType === SearchType.Performer
Expand Down

0 comments on commit 2b08781

Please sign in to comment.