From 1b55be8038c661389d70377d54c477a6ece5cb97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Quentin=20G=C3=A9r=C3=B4me?= Date: Fri, 7 Oct 2022 18:03:45 +0200 Subject: [PATCH] fix(Search): Close quicksearch on route change --- src/catalog/features/Quicksearch/Quicksearch.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/catalog/features/Quicksearch/Quicksearch.tsx b/src/catalog/features/Quicksearch/Quicksearch.tsx index ce8b8184..7b6d7329 100644 --- a/src/catalog/features/Quicksearch/Quicksearch.tsx +++ b/src/catalog/features/Quicksearch/Quicksearch.tsx @@ -4,6 +4,7 @@ import Dialog from "core/components/Dialog"; import Link from "core/components/Link"; import useDebounce from "core/hooks/useDebounce"; import { useTranslation } from "next-i18next"; +import { useRouter } from "next/router"; import { useEffect, useState } from "react"; import SearchInput from "../SearchInput"; import SearchResult, { SearchResultProps } from "../SearchResult"; @@ -17,12 +18,17 @@ const Quicksearch = (props: QuicksearchProps) => { const { open = false, onClose, renderActions } = props; const [queryString, setQueryString] = useState(""); const { t } = useTranslation(); + const router = useRouter(); const debouncedQueryString = useDebounce(queryString, 120); const { results, loading } = useSearch({ query: debouncedQueryString, perPage: 10, }); + useEffect(() => { + onClose(); + }, [router.pathname, onClose]); + useEffect(() => { if (!open) { setQueryString("");