diff --git a/src/packages/overlay/overlay.tsx b/src/packages/overlay/overlay.tsx index 3db024f6a7..e11c9e34dd 100644 --- a/src/packages/overlay/overlay.tsx +++ b/src/packages/overlay/overlay.tsx @@ -1,10 +1,10 @@ import React, { - useState, - useEffect, FunctionComponent, MouseEvent, MouseEventHandler, + useEffect, useRef, + useState, } from 'react' import { CSSTransition } from 'react-transition-group' import { EnterHandler, ExitHandler } from 'react-transition-group/Transition' @@ -17,7 +17,7 @@ export interface OverlayProps extends BasicComponent { duration: number closeOnOverlayClick: boolean visible: boolean - lockScroll: boolean + lockScroll: boolean | 'strict' onClick: (event: MouseEvent) => void afterShow: () => void afterClose: () => void @@ -66,7 +66,9 @@ export const Overlay: FunctionComponent< } }, [visible]) - useLockScroll(nodeRef, !!lockScroll && innerVisible) + const shouldLockScroll = !innerVisible ? false : lockScroll + + useLockScroll(nodeRef, shouldLockScroll) const classes = classNames(classPrefix, className) diff --git a/src/packages/popup/popup.tsx b/src/packages/popup/popup.tsx index 6987e39c9b..ca1abc71f4 100644 --- a/src/packages/popup/popup.tsx +++ b/src/packages/popup/popup.tsx @@ -1,19 +1,19 @@ import React, { FunctionComponent, - useState, - useEffect, - MouseEventHandler, MouseEvent, + MouseEventHandler, ReactElement, - ReactPortal, ReactNode, + ReactPortal, + useEffect, + useState, } from 'react' import { createPortal } from 'react-dom' import { CSSTransition } from 'react-transition-group' import classNames from 'classnames' import { Close } from '@nutui/icons-react' import { EnterHandler, ExitHandler } from 'react-transition-group/Transition' -import { OverlayProps, defaultOverlayProps } from '@/packages/overlay/overlay' +import { defaultOverlayProps, OverlayProps } from '@/packages/overlay/overlay' import Overlay from '@/packages/overlay' import { ComponentDefaults } from '@/utils/typings' import { useLockScroll } from '@/utils/use-lock-scroll' @@ -104,7 +104,10 @@ export const Popup: FunctionComponent< const [innerVisible, setInnerVisible] = useState(visible) const [showChildren, setShowChildren] = useState(true) const [transitionName, setTransitionName] = useState('') - useLockScroll(nodeRef, innerVisible && lockScroll) + + const shouldLockScroll = !innerVisible ? false : lockScroll + useLockScroll(nodeRef, shouldLockScroll) + const classPrefix = 'nut-popup' const baseStyle = { zIndex: index,