@redocly/theme
Version:
Shared UI components lib
23 lines • 889 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.useModalScrollLock = useModalScrollLock;
const react_1 = require("react");
function useModalScrollLock(isOpen) {
(0, react_1.useEffect)(() => {
const originalOverflow = document.body.style.overflow;
const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;
if (isOpen) {
document.body.style.overflow = 'hidden';
document.body.style.marginRight = `${scrollbarWidth}px`;
}
else {
document.body.style.overflow = originalOverflow;
document.body.style.marginRight = '';
}
return () => {
document.body.style.overflow = originalOverflow;
document.body.style.marginRight = '';
};
}, [isOpen]);
}
//# sourceMappingURL=use-modal-scroll-lock.js.map