Skip to content
This repository was archived by the owner on Jun 20, 2022. It is now read-only.

Commit 23f35dd

Browse files
theKasheygregberge
authored andcommitted
feat: add scroll-lock to modals, fixes #25 (#103)
1 parent f26186c commit 23f35dd

File tree

5 files changed

+51
-24
lines changed

5 files changed

+51
-24
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"bundlesize": [
1818
{
1919
"path": "./packages/core-em/dist/smooth-ui-core-em.min.js",
20-
"maxSize": "20 kB"
20+
"maxSize": "21 kB"
2121
},
2222
{
2323
"path": "./packages/core-sc/dist/smooth-ui-core-sc.min.js",

packages/core-em/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"polished": "^2.3.3",
3131
"prop-types": "^15.6.2",
3232
"react-focus-lock": "^1.17.6",
33+
"react-remove-scroll": "^1.0.1",
3334
"react-transition-group": "^2.5.3"
3435
},
3536
"peerDependencies": {

packages/core-sc/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"polished": "^2.3.3",
3131
"prop-types": "^15.6.2",
3232
"react-focus-lock": "^1.17.6",
33+
"react-remove-scroll": "^1.0.1",
3334
"react-transition-group": "^2.5.3"
3435
},
3536
"peerDependencies": {

packages/shared/core/Modal.js

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import React from 'react'
33
import PropTypes from 'prop-types'
44
import FocusLock from 'react-focus-lock'
5+
import { RemoveScroll } from 'react-remove-scroll';
56
import { css, withTheme } from './styled-engine'
67
import { th, mixin } from './utils/system'
78
import Transition from './Transition'
@@ -90,31 +91,33 @@ class ModalComponent extends React.Component {
9091
return (
9192
<Portal>
9293
<FocusLock returnFocus onActivation={this.onFocusLockActivation}>
93-
<div
94-
className={cx(
95-
'sui-modal',
96-
`sui-modal-transition-${status}`,
97-
className,
98-
)}
99-
ref={this.handleDialogRef}
100-
onClick={wrapEvent(onClick, event => {
101-
event.stopPropagation()
102-
onClose()
103-
})}
104-
onKeyDown={wrapEvent(onKeyDown, event => {
105-
if (event.key === 'Escape') {
94+
<RemoveScroll forwardProps>
95+
<div
96+
className={cx(
97+
'sui-modal',
98+
`sui-modal-transition-${status}`,
99+
className,
100+
)}
101+
ref={this.handleDialogRef}
102+
onClick={wrapEvent(onClick, event => {
106103
event.stopPropagation()
107104
onClose()
108-
}
109-
})}
110-
{...props}
111-
>
112-
<ModalContext.Provider
113-
value={{ contentRef: this.contentRef, onClose }}
105+
})}
106+
onKeyDown={wrapEvent(onKeyDown, event => {
107+
if (event.key === 'Escape') {
108+
event.stopPropagation()
109+
onClose()
110+
}
111+
})}
112+
{...props}
114113
>
115-
{children}
116-
</ModalContext.Provider>
117-
</div>
114+
<ModalContext.Provider
115+
value={{ contentRef: this.contentRef, onClose }}
116+
>
117+
{children}
118+
</ModalContext.Provider>
119+
</div>
120+
</RemoveScroll>
118121
</FocusLock>
119122
</Portal>
120123
)

yarn.lock

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11450,6 +11450,20 @@ react-powerplug@^1.0.0:
1145011450
dependencies:
1145111451
"@babel/runtime" "^7.0.0"
1145211452

11453+
react-remove-scroll-bar@^1.1.3:
11454+
version "1.1.3"
11455+
resolved "https://registry.yarnpkg.com/react-remove-scroll-bar/-/react-remove-scroll-bar-1.1.3.tgz#21eb49a0cc9628746d2b624880fb272a3541866a"
11456+
integrity sha512-mEPbImnGIxv+PyVTpeuGhWVl2aAQgSpB2yX4lL6ttsjT/XVVZwyPiz4gnCxBPoWYniQBLTL1IjZ/rrQLT9ZIJg==
11457+
dependencies:
11458+
react-style-singleton "^1.1.0"
11459+
11460+
react-remove-scroll@^1.0.1:
11461+
version "1.0.1"
11462+
resolved "https://registry.yarnpkg.com/react-remove-scroll/-/react-remove-scroll-1.0.1.tgz#b2033e87edfe19b7c8160b7d7b58e5bdf76f1caa"
11463+
integrity sha512-gSKT049UTFMvT1DhBlRCVqpPpcyqUs2b9Ncp81Dc0USh2c+la5yl70+BYK0jFWOMisMDcxaiOMpdIqpeKUO2Jw==
11464+
dependencies:
11465+
react-remove-scroll-bar "^1.1.3"
11466+
1145311467
react-router-dom@^4.3.1:
1145411468
version "4.3.1"
1145511469
resolved "https://registry.yarnpkg.com/react-router-dom/-/react-router-dom-4.3.1.tgz#4c2619fc24c4fa87c9fd18f4fb4a43fe63fbd5c6"
@@ -11490,6 +11504,14 @@ react-sizes@^1.0.4:
1149011504
lodash.throttle "^4.1.1"
1149111505
prop-types "^15.6.0"
1149211506

11507+
react-style-singleton@^1.1.0:
11508+
version "1.1.1"
11509+
resolved "https://registry.yarnpkg.com/react-style-singleton/-/react-style-singleton-1.1.1.tgz#b2b698765519da812b80f55ab3c5fc5d849a2e63"
11510+
integrity sha512-0JD+XC5veR3oxf7GzIXipr89sM8R3rWnOR/gpzIV0DnoRBrcTvvkqyMu9icDYqM/6CWJhYcH5Jdy6Nim7PmoTQ==
11511+
dependencies:
11512+
invariant "^2.2.4"
11513+
tslib "^1.0.0"
11514+
1149311515
react-test-renderer@^16.0.0-0:
1149411516
version "16.5.2"
1149511517
resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-16.5.2.tgz#92e9d2c6f763b9821b2e0b22f994ee675068b5ae"
@@ -13562,7 +13584,7 @@ tryer@^1.0.0:
1356213584
resolved "https://registry.yarnpkg.com/tryer/-/tryer-1.0.1.tgz#f2c85406800b9b0f74c9f7465b81eaad241252f8"
1356313585
integrity sha512-c3zayb8/kWWpycWYg87P71E1S1ZL6b6IJxfb5fvsUgsf0S2MVGaDhDXXjDMpdCpfWXqptc+4mXwmiy1ypXqRAA==
1356413586

13565-
tslib@^1.9.0:
13587+
tslib@^1.0.0, tslib@^1.9.0:
1356613588
version "1.9.3"
1356713589
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286"
1356813590
integrity sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==

0 commit comments

Comments
 (0)