Skip to content

Commit f06decd

Browse files
authored
Merge pull request #312 from prgrms-web-devcourse-final-project/fix/modal-scroll-lock
[fix] 모달시트 열릴 때 배경 스크롤 방지 처리 추가
2 parents d9ddc8a + bc43d31 commit f06decd

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/layouts/ModalSheetLayoutTemp.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import BackLink from '@/components/modalSheet/BackLink';
22
import CardDetailMoreMenu from '@/components/modalSheet/CardDetailMoreMenu';
33
import { motion } from 'framer-motion';
4+
import { useEffect } from 'react';
45

56
interface ModalSheetLayoutProps {
67
children: React.ReactNode;
@@ -15,6 +16,16 @@ function ModalSheetLayoutTemp({ children, isOwnPost }: ModalSheetLayoutProps) {
1516
exit: { opacity: 0, y: -200 },
1617
};
1718

19+
useEffect(() => {
20+
// 모달이 열릴 때
21+
document.documentElement.style.overflow = 'hidden';
22+
23+
return () => {
24+
// 모달이 닫힐 때
25+
document.documentElement.style.overflow = '';
26+
};
27+
}, []);
28+
1829
return (
1930
<motion.div
2031
className="fixed inset-0 z-50 flex items-center justify-center"
@@ -24,7 +35,7 @@ function ModalSheetLayoutTemp({ children, isOwnPost }: ModalSheetLayoutProps) {
2435
variants={modalVariants}
2536
transition={{ duration: 0.3 }}
2637
>
27-
<div className="max-w-[600px] w-full h-screen flex flex-col bg-white rounded-lg card-shadow border border-gray-5 overflow-y-auto scroll">
38+
<div className="max-w-[600px] w-full h-screen flex flex-col bg-white rounded-lg card-shadow border border-gray-5">
2839
{/* 헤더 */}
2940
<div className="sticky top-0 flex h-[60px] items-center px-4 justify-between bg-white">
3041
<BackLink />

src/styles/index.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
@import '@styles/scrollbar.css';
55

66
html {
7-
overflow-y: scroll; /* 항상 스크롤바 공간 확보 (윈도우에서 효과적) */
7+
scrollbar-gutter: stable;
88
}

0 commit comments

Comments
 (0)