Skip to content

Commit

Permalink
fix(ffe-modals-react): fix overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Hellstrand committed Jun 25, 2024
1 parent 1151fe0 commit dd4f9c0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/ffe-modals-react/src/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const Modal = React.forwardRef<ModalHandle, ModalProps>(
) => {
const [isOpen, setIsOpen] = useState(false);
const modalRef = useRef<HTMLDialogElement>(null);
const htmlOverflowY = useRef(document.documentElement.style.overflowY);

useImperativeHandle(ref, () => ({
open: () => {
Expand All @@ -44,14 +45,15 @@ export const Modal = React.forwardRef<ModalHandle, ModalProps>(
}));

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]);
Expand Down

0 comments on commit dd4f9c0

Please sign in to comment.