From eb8baffcf88d3300d73afffa268e381244a6127d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Mon, 18 Dec 2023 22:03:07 +0100 Subject: [PATCH] Add class search-open to body when search modal is displayed --- src/components/Search/SearchModal.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/components/Search/SearchModal.tsx b/src/components/Search/SearchModal.tsx index 32d7e2f26..255072885 100644 --- a/src/components/Search/SearchModal.tsx +++ b/src/components/Search/SearchModal.tsx @@ -28,6 +28,18 @@ export function SearchModal(props: SearchModalProps) { [], ); + // Add a global class on the body when the search modal is open + const isSearchOpened = state !== null; + React.useEffect(() => { + if (isSearchOpened) { + document.body.classList.add('search-open'); + } + + return () => { + document.body.classList.remove('search-open'); + }; + }, [isSearchOpened]); + if (state === null) { return null; }