Skip to content

Commit 8c1eb07

Browse files
jgrisafeorteth01
authored andcommitted
added enabled prop with default true, can disable component from parent (#9)
* added enabled prop with default true, can disable component from parent * refactored enabled mechanism to remove/add handler * removed logic from cancelScrollEvent method * added check to cdm and build * removed object destructure
1 parent bd2c987 commit 8c1eb07

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

lib/ScrollLock.js

Lines changed: 18 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/ScrollLock.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ScrollLock.jsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@ import React, { Component } from 'react';
22

33
class ScrollLock extends Component {
44
componentDidMount() {
5-
this.scrollingElement.addEventListener('wheel', this.onScrollHandler, false);
5+
if (this.props.enabled) {
6+
this.scrollingElement.addEventListener('wheel', this.onScrollHandler, false)
7+
}
8+
}
9+
10+
componentWillReceiveProps(nextProps) {
11+
if (nextProps.enabled) {
12+
this.scrollingElement.addEventListener('wheel', this.onScrollHandler, false)
13+
} else {
14+
this.scrollingElement.removeEventListener('wheel', this.onScrollHandler, false)
15+
}
616
}
717

818
componentWillUnmount() {
@@ -45,4 +55,8 @@ class ScrollLock extends Component {
4555
}
4656
}
4757

58+
ScrollLock.defaultProps = {
59+
enabled: true
60+
};
61+
4862
export default ScrollLock;

0 commit comments

Comments
 (0)