From 2fee8b4ed5853caa2f167a89053b2e3ca3938c4f Mon Sep 17 00:00:00 2001 From: tate Date: Fri, 26 Aug 2022 16:26:18 +1000 Subject: [PATCH] behaviour tweak --- .../components/molecules/Backdrop/Backdrop.tsx | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/components/src/components/molecules/Backdrop/Backdrop.tsx b/components/src/components/molecules/Backdrop/Backdrop.tsx index 4f2888df..19deb64b 100644 --- a/components/src/components/molecules/Backdrop/Backdrop.tsx +++ b/components/src/components/molecules/Backdrop/Backdrop.tsx @@ -53,7 +53,7 @@ export const Backdrop = ({ } toggle(open || false) - if (typeof window !== 'undefined') { + if (typeof window !== 'undefined' && !noBackground) { if (open) { if (currBackdrops() === 0) { setStyles( @@ -64,23 +64,19 @@ export const Backdrop = ({ } modifyBackdrops(1) return () => { + const top = parseFloat(style.top || '0') * -1 if (currBackdrops() === 1) { setStyles('', '', '') + window.scroll({ + top, + }) } modifyBackdrops(-1) - window.scroll({ top: parseFloat(style.top || '0') * -1 }) } } } // eslint-disable-next-line react-hooks/exhaustive-deps - }, [open]) - - React.useEffect(() => { - return () => { - document.body.style.position = '' - document.body.style.top = '' - } - }, []) + }, [open, noBackground]) return state !== 'unmounted' ? (