Skip to content

Commit c95b799

Browse files
authored
feat(Modal): disable scroll outside of modal when it is open (#2433)
1 parent 2e0a86d commit c95b799

File tree

4 files changed

+41
-24
lines changed

4 files changed

+41
-24
lines changed

packages/core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
"react-inlinesvg": "^3.0.1",
115115
"react-is": "^16.9.0",
116116
"react-popper": "^2.3.0",
117+
"react-remove-scroll": "^2.6.0",
117118
"react-select": "^3.2.0",
118119
"react-transition-group": "^4.4.5",
119120
"react-virtualized-auto-sizer": "^1.0.7",

packages/core/src/components/ModalNew/Modal/Modal.tsx

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { forwardRef, useCallback, useMemo, useState } from "react";
22
import cx from "classnames";
3+
import { RemoveScroll } from "react-remove-scroll";
34
import { getTestId } from "../../../tests/test-ids-utils";
45
import { ComponentDefaultTestId } from "../../../tests/constants";
56
import styles from "./Modal.module.scss";
@@ -71,30 +72,32 @@ const Modal = forwardRef(
7172

7273
return (
7374
<ModalProvider value={contextValue}>
74-
<div
75-
data-testid={getTestId(ComponentDefaultTestId.MODAL_NEXT_OVERLAY, id)}
76-
className={styles.overlay}
77-
onClick={onBackdropClick}
78-
aria-hidden
79-
/>
80-
<div
81-
ref={ref}
82-
className={cx(styles.modal, getStyle(styles, camelCase("size-" + size)), className)}
83-
id={id}
84-
data-testid={dataTestId || getTestId(ComponentDefaultTestId.MODAL_NEXT, id)}
85-
role="dialog"
86-
aria-modal
87-
aria-labelledby={titleId}
88-
aria-describedby={descriptionId}
89-
>
90-
<ModalTopActions
91-
renderAction={renderHeaderAction}
92-
color={closeButtonTheme}
93-
closeButtonAriaLabel={closeButtonAriaLabel}
94-
onClose={onClose}
75+
<RemoveScroll>
76+
<div
77+
data-testid={getTestId(ComponentDefaultTestId.MODAL_NEXT_OVERLAY, id)}
78+
className={styles.overlay}
79+
onClick={onBackdropClick}
80+
aria-hidden
9581
/>
96-
{children}
97-
</div>
82+
<div
83+
ref={ref}
84+
className={cx(styles.modal, getStyle(styles, camelCase("size-" + size)), className)}
85+
id={id}
86+
data-testid={dataTestId || getTestId(ComponentDefaultTestId.MODAL_NEXT, id)}
87+
role="dialog"
88+
aria-modal
89+
aria-labelledby={titleId}
90+
aria-describedby={descriptionId}
91+
>
92+
<ModalTopActions
93+
renderAction={renderHeaderAction}
94+
color={closeButtonTheme}
95+
closeButtonAriaLabel={closeButtonAriaLabel}
96+
onClose={onClose}
97+
/>
98+
{children}
99+
</div>
100+
</RemoveScroll>
98101
</ModalProvider>
99102
);
100103
}

packages/core/src/tests/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ export enum ComponentDefaultTestId {
105105
MODAL_FOOTER_BUTTONS = "modal-footer-buttons",
106106
MODAL_NEXT = "modal",
107107
MODAL_NEXT_OVERLAY = "modal-overlay",
108+
MODAL_NEXT_HEADER = "modal-header",
109+
MODAL_NEXT_CONTENT = "modal-content",
108110
FORMATTED_NUMBER = "formatted-number",
109111
HIDDEN_TEXT = "hidden-text",
110112
DIALOG_CONTENT_CONTAINER = "dialog-content-container",

yarn.lock

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16888,7 +16888,7 @@ react-refresh@^0.14.0:
1688816888
resolved "https://registry.npmjs.org/react-refresh/-/react-refresh-0.14.0.tgz#4e02825378a5f227079554d4284889354e5f553e"
1688916889
integrity sha512-wViHqhAd8OHeLS/IRMJjTSDHF3U9eWi62F/MledQGPdJGDhodXJ9PBLNGr6WWL7qlH12Mt3TyTpbS+hGXMjCzQ==
1689016890

16891-
react-remove-scroll-bar@^2.3.3:
16891+
react-remove-scroll-bar@^2.3.3, react-remove-scroll-bar@^2.3.6:
1689216892
version "2.3.6"
1689316893
resolved "https://registry.npmjs.org/react-remove-scroll-bar/-/react-remove-scroll-bar-2.3.6.tgz#3e585e9d163be84a010180b18721e851ac81a29c"
1689416894
integrity sha512-DtSYaao4mBmX+HDo5YWYdBWQwYIQQshUV/dVxFxK+KM26Wjwp1gZ6rv6OC3oujI6Bfu6Xyg3TwK533AQutsn/g==
@@ -16907,6 +16907,17 @@ [email protected]:
1690716907
use-callback-ref "^1.3.0"
1690816908
use-sidecar "^1.1.2"
1690916909

16910+
react-remove-scroll@^2.6.0:
16911+
version "2.6.0"
16912+
resolved "https://registry.npmjs.org/react-remove-scroll/-/react-remove-scroll-2.6.0.tgz#fb03a0845d7768a4f1519a99fdb84983b793dc07"
16913+
integrity sha512-I2U4JVEsQenxDAKaVa3VZ/JeJZe0/2DxPWL8Tj8yLKctQJQiZM52pn/GWFpSp8dftjM3pSAHVJZscAnC/y+ySQ==
16914+
dependencies:
16915+
react-remove-scroll-bar "^2.3.6"
16916+
react-style-singleton "^2.2.1"
16917+
tslib "^2.1.0"
16918+
use-callback-ref "^1.3.0"
16919+
use-sidecar "^1.1.2"
16920+
1691016921
react-resizable@^3.0.4:
1691116922
version "3.0.5"
1691216923
resolved "https://registry.npmjs.org/react-resizable/-/react-resizable-3.0.5.tgz#362721f2efbd094976f1780ae13f1ad7739786c1"

0 commit comments

Comments
 (0)