Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Add toggle body class and update body padding if there is only one modal open.
if (numberOfModalsOpen === 1) {
// Toggle open class.
toggleClass(body, 'tg-modal-open', state);
const { bodyScrollLock } = this.props;
if (state) {
if (bodyScrollLock && this.node.current) {
disableBodyScroll(this.node.current, {
reserveScrollBarGap: true,
});
}
} else if (bodyScrollLock && this.node.current) {
clearAllBodyScrollLocks();
}
}
// Decrement modal count when closing.
if (!state) {
numberOfModalsOpen = Math.max(numberOfModalsOpen - 1, 0);
}
}
}
componentWillUnmount() {
// restauration function can be undefined if there was
// an error during mounting/rendering
clearAllBodyScrollLocks()
if (this.props.onEscape) {
document.removeEventListener('keydown', this.handleKeydown)
}
}
function clearScrollLocks() {
clearAllBodyScrollLocks();
}
componentDidUpdate(prevProps: Props, prevState: State) {
if (
prevProps.isShown !== this.props.isShown ||
prevState.isShown !== this.state.isShown
) {
const isShown = getIsShown(this.props, this.state);
if (isShown === false) {
clearAllBodyScrollLocks();
} else {
disableBodyScroll();
}
}
}
componentWillUnmount() {
this.el.parentNode.removeChild(this.el);
clearAllBodyScrollLocks();
}
componentDidUpdate(prevProps: PanelProps) {
if (prevProps.isShown !== this.props.isShown) {
if (this.props.isShown === false) {
clearAllBodyScrollLocks();
} else if (this.scrollEl) {
disableBodyScroll(this.scrollEl);
}
}
}