Skip to content

Commit 78494e5

Browse files
authored
fix(SidebarMobile): move body event listeners to lifecycle methods (#8155)
1 parent 45efec9 commit 78494e5

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/components/SidebarMobile/SidebarMobile.jsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,24 @@ export default class SidebarMobile extends Component {
1818
sections: PropTypes.array,
1919
};
2020

21+
componentDidMount() {
22+
if (this.props.isOpen) {
23+
this._toggleBodyListener(true);
24+
}
25+
}
26+
27+
componentDidUpdate(prevProps) {
28+
if (prevProps.isOpen !== this.props.isOpen) {
29+
this._toggleBodyListener(this.props.isOpen);
30+
}
31+
}
32+
33+
componentWillUnmount() {
34+
this._toggleBodyListener(false);
35+
}
36+
2137
render() {
2238
const { isOpen, toggle } = this.props;
23-
this._toggleBodyListener(isOpen);
2439

2540
return (
2641
<nav

0 commit comments

Comments
 (0)