Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Prevent dialog scroll #7710

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Changes from 1 commit
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
10 changes: 8 additions & 2 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