From dd4f9c0bf00e1fe5fb6bf01776113d5452464ec8 Mon Sep 17 00:00:00 2001 From: Peter Hellstrand Date: Tue, 25 Jun 2024 11:31:12 +0200 Subject: [PATCH] fix(ffe-modals-react): fix overflow --- packages/ffe-modals-react/src/Modal.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/ffe-modals-react/src/Modal.tsx b/packages/ffe-modals-react/src/Modal.tsx index 628d420220..62b541ba33 100644 --- a/packages/ffe-modals-react/src/Modal.tsx +++ b/packages/ffe-modals-react/src/Modal.tsx @@ -32,6 +32,7 @@ export const Modal = React.forwardRef( ) => { const [isOpen, setIsOpen] = useState(false); const modalRef = useRef(null); + const htmlOverflowY = useRef(document.documentElement.style.overflowY); useImperativeHandle(ref, () => ({ open: () => { @@ -44,14 +45,15 @@ export const Modal = React.forwardRef( })); useEffect(() => { + const html = document.documentElement; const inShadow = modalRef.current?.getRootNode() instanceof ShadowRoot; if (inShadow) { - const html = document.documentElement; if (isOpen) { - html.classList.add('ffe-modal__root'); - } else { - html.classList.remove('ffe-modal__root'); + htmlOverflowY.current = html.style.overflowY; + html.style.overflowY = 'hidden'; + } else if (!isOpen) { + html.style.overflowY = htmlOverflowY.current; } } }, [isOpen]);