From 30d296da7d7750ea779fbffe995d6cad845efab0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=AC=A2?= Date: Thu, 4 Jun 2026 17:43:34 +0800 Subject: [PATCH 1/2] feat: add scrollLock prop to control body scroll lock - Add scrollLock prop (default: true) to control whether to lock body scroll when dialog opens - Add test cases for scrollLock functionality - Update README.md with new prop documentation Co-Authored-By: Claude Opus 4.8 --- README.md | 1 + src/DialogWrap.tsx | 3 ++- src/IDialogPropTypes.ts | 2 ++ tests/scroll.spec.tsx | 19 +++++++++++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 93fec0a2..40920efb 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,7 @@ ReactDOM.render( | closeIcon | ReactNode | | specific the close icon. | | | forceRender | Boolean | false | Create dialog dom node before dialog first show | | | focusTriggerAfterClose | Boolean | true | focus trigger element when dialog closed | | +| scrollLock | Boolean | true | Control whether to lock body scroll when dialog opens | | | modalRender | (node: ReactNode) => ReactNode | | Custom modal content render | 8.3.0 | ## Development diff --git a/src/DialogWrap.tsx b/src/DialogWrap.tsx index c9d366ab..63b312e8 100644 --- a/src/DialogWrap.tsx +++ b/src/DialogWrap.tsx @@ -23,6 +23,7 @@ const DialogWrap: React.FC = (props) => { closable, panelRef, keyboard = true, + scrollLock = true, onClose, } = props; const [animatedVisible, setAnimatedVisible] = React.useState(visible); @@ -55,7 +56,7 @@ const DialogWrap: React.FC = (props) => { onEsc={onEsc} autoDestroy={false} getContainer={getContainer} - autoLock={visible || animatedVisible} + autoLock={scrollLock && (visible || animatedVisible)} > ; diff --git a/tests/scroll.spec.tsx b/tests/scroll.spec.tsx index 6f4a3aa0..ed2508d0 100644 --- a/tests/scroll.spec.tsx +++ b/tests/scroll.spec.tsx @@ -78,4 +78,23 @@ describe('Dialog.Scroll', () => { unmount(); }); + + it('should not lock body scroll when scrollLock is false', () => { + const { unmount, rerender } = render(); + + // body should not have overflow:hidden when scrollLock is false + expect(document.body).not.toHaveStyle({ + overflowY: 'hidden', + }); + + unmount(); + }); + + it('should lock body scroll when scrollLock is true (default)', () => { + const { unmount, rerender } = render(); + expect(document.body).toHaveStyle({ + overflowY: 'hidden', + }); + unmount(); + }); }); From cb61b2236ca63fb4c834b0eb81e06be4119d2ab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=AC=A2?= Date: Fri, 5 Jun 2026 11:29:40 +0800 Subject: [PATCH 2/2] fix: remove unnecessary props from Dialog component in tests --- src/DialogWrap.tsx | 3 ++- tests/scroll.spec.tsx | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/DialogWrap.tsx b/src/DialogWrap.tsx index 63b312e8..76563968 100644 --- a/src/DialogWrap.tsx +++ b/src/DialogWrap.tsx @@ -26,6 +26,7 @@ const DialogWrap: React.FC = (props) => { scrollLock = true, onClose, } = props; + const { scrollLock: _, ...restProps } = props; const [animatedVisible, setAnimatedVisible] = React.useState(visible); const refContext = React.useMemo(() => ({ panel: panelRef }), [panelRef]); @@ -59,7 +60,7 @@ const DialogWrap: React.FC = (props) => { autoLock={scrollLock && (visible || animatedVisible)} > { const closableObj = closable && typeof closable === 'object' ? closable : {}; diff --git a/tests/scroll.spec.tsx b/tests/scroll.spec.tsx index ed2508d0..8cbfa19d 100644 --- a/tests/scroll.spec.tsx +++ b/tests/scroll.spec.tsx @@ -80,7 +80,7 @@ describe('Dialog.Scroll', () => { }); it('should not lock body scroll when scrollLock is false', () => { - const { unmount, rerender } = render(); + const { unmount } = render(); // body should not have overflow:hidden when scrollLock is false expect(document.body).not.toHaveStyle({ @@ -91,7 +91,7 @@ describe('Dialog.Scroll', () => { }); it('should lock body scroll when scrollLock is true (default)', () => { - const { unmount, rerender } = render(); + const { unmount } = render(); expect(document.body).toHaveStyle({ overflowY: 'hidden', });