restore page scroll after modal is closed

This commit is contained in:
Pramod Mahajan 2025-05-19 11:50:50 +05:30
parent 353238fd60
commit c43c668fb8

View File

@ -15,7 +15,7 @@ const GlobalModel = ({
useEffect(() => {
const modalElement = modalRef.current;
const modalInstance = new window.bootstrap.Modal(modalElement, {
backdrop: false // Disable backdrop
backdrop: false,
});
if (isOpen) {
@ -26,16 +26,27 @@ useEffect(() => {
const handleHideModal = () => {
closeModal();
// FIX: Remove any lingering body classes/styles
document.body.classList.remove('modal-open');
document.body.style.overflow = '';
document.body.style.paddingRight = '';
};
modalElement.addEventListener('hidden.bs.modal', handleHideModal);
return () => {
modalElement.removeEventListener('hidden.bs.modal', handleHideModal);
// Also clean up just in case component unmounts
document.body.classList.remove('modal-open');
document.body.style.overflow = '';
document.body.style.paddingRight = '';
};
}, [isOpen, closeModal]);
// Dynamically set the modal size classes (modal-sm, modal-lg, modal-xl)
const modalSizeClass = size ? `modal-${size}` : ''; // Default is empty if no size is specified