From 5a482f7c3acdba05fd204204209f8935699f88ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Rialland?= Date: Mon, 4 Jul 2022 18:41:33 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20la=20popover=20de=20recherche=20qui=20se?= =?UTF-8?q?=20ferme=20imm=C3=A9diatement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/search/SearchRulesAndSimulators.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/site/source/components/search/SearchRulesAndSimulators.tsx b/site/source/components/search/SearchRulesAndSimulators.tsx index 9b5d0c2dc..934d1fd7b 100644 --- a/site/source/components/search/SearchRulesAndSimulators.tsx +++ b/site/source/components/search/SearchRulesAndSimulators.tsx @@ -1,6 +1,6 @@ import algoliasearch from 'algoliasearch/lite' import { Spacing } from '@/design-system/layout' -import { useEffect } from 'react' +import { useEffect, useRef } from 'react' import { Configure, Index } from 'react-instantsearch-dom' import { RulesInfiniteHits } from './RulesInfiniteHits' import { SearchBox } from './SearchBox' @@ -20,7 +20,13 @@ interface Props { export default function SearchRulesAndSimulators({ closePopover }: Props) { const location = useLocation() - useEffect(() => closePopover(), [location]) + const prevLocation = useRef(location) + useEffect(() => { + if (prevLocation.current !== location) { + prevLocation.current = location + closePopover() + } + }, [closePopover, location]) return (