Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/DialogWrap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ const DialogWrap: React.FC<IDialogPropTypes> = (props) => {
closable,
panelRef,
keyboard = true,
scrollLock = true,
onClose,
} = props;
Comment thread
EmilyyyLiu marked this conversation as resolved.
const { scrollLock: _, ...restProps } = props;
const [animatedVisible, setAnimatedVisible] = React.useState<boolean>(visible);

const refContext = React.useMemo(() => ({ panel: panelRef }), [panelRef]);
Expand Down Expand Up @@ -55,10 +57,10 @@ const DialogWrap: React.FC<IDialogPropTypes> = (props) => {
onEsc={onEsc}
autoDestroy={false}
getContainer={getContainer}
autoLock={visible || animatedVisible}
autoLock={scrollLock && (visible || animatedVisible)}
>
<Dialog
{...props}
{...restProps}
destroyOnHidden={destroyOnHidden}
afterClose={() => {
const closableObj = closable && typeof closable === 'object' ? closable : {};
Expand Down
2 changes: 2 additions & 0 deletions src/IDialogPropTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export type IDialogPropTypes = {
// https://github.com/react-component/dialog/issues/95
focusTriggerAfterClose?: boolean;
focusTrap?: boolean;
/** Control whether to lock body scroll when modal opens. Default is true. */
scrollLock?: boolean;

// Refs
panelRef?: React.Ref<HTMLDivElement>;
Expand Down
19 changes: 19 additions & 0 deletions tests/scroll.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,23 @@ describe('Dialog.Scroll', () => {

unmount();
});

it('should not lock body scroll when scrollLock is false', () => {
const { unmount } = render(<Dialog visible scrollLock={false} />);

// 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 } = render(<Dialog visible scrollLock={true} />);
expect(document.body).toHaveStyle({
overflowY: 'hidden',
});
unmount();
});
Comment thread
EmilyyyLiu marked this conversation as resolved.
});
Loading