Skip to content

Commit

Permalink
refactor: modal 오픈시에 scroll 방지
Browse files Browse the repository at this point in the history
  • Loading branch information
hozzijeong committed Sep 21, 2023
1 parent aedd7f7 commit 49a3ad4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion frontend/src/components/@common/Modal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PropsWithChildren, forwardRef } from 'react';
import { PropsWithChildren, forwardRef, useEffect } from 'react';
import { createPortal } from 'react-dom';
import { CloseButton, ModalBox, ModalContent } from './Modal.style';

Expand All @@ -13,6 +13,14 @@ const Modal = forwardRef<HTMLDialogElement, ModalProps>(function Modal(
) {
const root = document.getElementById('modal-root') ?? document.body;

useEffect(() => {
if (!isOpen) {
document.body.style.position = 'relative';
return;
}
document.body.style.position = 'fixed';
}, [isOpen]);

return createPortal(
isOpen && (
<ModalBox aria-modal="true" ref={ref}>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/style/Global.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const GlobalStyle = createGlobalStyle`
html,
body {
scrollbar-width: none;
width: 100%;
font-size: 62.5%;
}
Expand Down

0 comments on commit 49a3ad4

Please sign in to comment.