Skip to content

Commit

Permalink
chore: Prevent dialog scroll (#7710)
Browse files Browse the repository at this point in the history
* chore: Prevent dialog scroll

* chore: preventBodyScroll should not be passed as a part of restProps
  • Loading branch information
burkov authored Sep 12, 2024
1 parent 062f75f commit 380979e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/dialog/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface DialogProps extends Partial<TabTrapProps> {
dense?: boolean | null | undefined
native?: boolean
modal?: boolean
preventBodyScroll?: boolean
}

/**
Expand Down Expand Up @@ -68,7 +69,8 @@ export default class Dialog extends PureComponent<DialogProps> {
trapFocus: PropTypes.bool,
portalTarget: PropTypes.instanceOf(HTMLElement),
autoFocusFirst: PropTypes.bool,
'data-test': PropTypes.string
'data-test': PropTypes.string,
preventBodyScroll: PropTypes.bool
};

static defaultProps: Partial<DialogProps> = {
Expand All @@ -82,7 +84,8 @@ export default class Dialog extends PureComponent<DialogProps> {
shortcutOptions: {modal: false},
trapFocus: false,
autoFocusFirst: true,
modal: true
modal: true,
preventBodyScroll: true
};

state = {
Expand Down Expand Up @@ -128,6 +131,9 @@ export default class Dialog extends PureComponent<DialogProps> {
}

toggleScrollPreventer() {
if (!this.props.preventBodyScroll) {
return;
}
if (this.props.show) {
this.scrollPreventer.prevent();
} else {
Expand Down Expand Up @@ -169,7 +175,7 @@ export default class Dialog extends PureComponent<DialogProps> {
const {show, showCloseButton, onOverlayClick, onCloseAttempt, onEscPress, onCloseClick,
children, className, contentClassName, trapFocus, 'data-test': dataTest, closeButtonInside,
portalTarget, label, closeButtonTitle, dense, shortcutOptions, native, modal,
...restProps} = this.props;
preventBodyScroll, ...restProps} = this.props;
const classes = classNames(styles.container, className);
const shortcutsMap = this.getShortcutsMap();
const content = (
Expand Down

0 comments on commit 380979e

Please sign in to comment.