File tree Expand file tree Collapse file tree 3 files changed +42
-5
lines changed Expand file tree Collapse file tree 3 files changed +42
-5
lines changed Original file line number Diff line number Diff line change 1+ import { useEffect } from 'react' ;
2+
3+ import { getScrollbarWidth } from '@/utils/getScrollbarWidth' ;
4+
15interface ModalOverlayProps {
26 closeOnOutsideClick ?: boolean ;
3- children : React . ReactElement ;
7+ children : React . ReactNode ;
48 onClose ?: ( ) => void ;
59}
610
711const ModalOverlay = ( { closeOnOutsideClick = false , children, onClose } : ModalOverlayProps ) => {
12+ useEffect ( ( ) => {
13+ const scrollbarWidth = getScrollbarWidth ( ) ;
14+ const header = document . querySelector ( 'header' ) ;
15+
16+ document . documentElement . style . setProperty ( '--scrollbar-width' , `${ scrollbarWidth } px` ) ;
17+ document . body . classList . add ( 'modal-open' ) ;
18+ if ( header ) header . classList . add ( 'modal-open' ) ;
19+
20+ return ( ) => {
21+ document . documentElement . style . setProperty ( '--scrollbar-width' , '0px' ) ;
22+ document . body . classList . remove ( 'modal-open' ) ;
23+ } ;
24+ } , [ ] ) ;
25+
826 const handleClickOutside = ( ) => {
927 if ( closeOnOutsideClick && onClose ) {
1028 onClose ( ) ;
Original file line number Diff line number Diff line change 11/* Tailwind에서 기본적으로 제공하지 않는 추가 유틀리티 클래스 정의 */
2- /* import congratThemeFrame from '@/assets/images/congrat-theme-frame.png';
3- import fieldThemeFrame from '@/assets/images/field-theme-frame.png';
4- import skyThemeFrame from '@/assets/images/sky-theme-frame.png';
5- import vintageThemeFrame from '@/assets/images/vintage-theme-frame.png'; */
62
73@layer utilities {
84 /* 편지지 줄 css */
@@ -63,4 +59,9 @@ import vintageThemeFrame from '@/assets/images/vintage-theme-frame.png'; */
6359 right : 8% ; /* 수평 중앙 정렬 */
6460 transform : translateX (-50% );
6561 }
62+
63+ .modal-open {
64+ overflow : hidden;
65+ padding-right : var (--scrollbar-width , 0px );
66+ }
6667}
Original file line number Diff line number Diff line change 1+ let scrollbarWidth : number | undefined ;
2+
3+ export const getScrollbarWidth = ( ) => {
4+ if ( scrollbarWidth !== undefined ) return scrollbarWidth ;
5+
6+ const container = document . createElement ( 'div' ) ;
7+
8+ document . body . appendChild ( container ) ;
9+ container . style . overflow = 'scroll' ;
10+
11+ const inner = document . createElement ( 'div' ) ;
12+ container . appendChild ( inner ) ;
13+
14+ scrollbarWidth = container . offsetWidth - inner . offsetWidth ;
15+ document . body . removeChild ( container ) ;
16+
17+ return scrollbarWidth ;
18+ } ;
You can’t perform that action at this time.
0 commit comments