Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/component/modals/ParentModal.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect } from 'react';
import React, { useState, useEffect, useRef } from 'react';
import ReactModal from 'react-modal';
import './parent-modal.css';

Expand All @@ -9,31 +9,34 @@ const Modal = ({
}) => {
const [curClass, setCurClass] = useState('');
const [isOpen, setIsOpen] = useState(ModelOpen);
const [stid, setStid] = useState(null);
const stid = useRef(null);
useEffect(() => {
if (ModelOpen === true) {
setIsOpen(true);
setCurClass('closing');
clearTimeout(stid);
setStid(setTimeout(() => {
clearTimeout(stid.current);
document.body.style.overflow = 'hidden';
stid.current = setTimeout(() => {
setIsOpen(true);
setCurClass('');
}, 20));
}, 20);
} else {
setCurClass('closing');
clearTimeout(stid);
setStid(setTimeout(() => {
clearTimeout(stid.current);
document.body.style.overflow = '';
stid.current = setTimeout(() => {
setIsOpen(false);
}, 400));
}, 400);
}
return () => clearTimeout(stid.current);
}, [ModelOpen]);

if (!isOpen) return '';
return (
<ReactModal
isOpen={isOpen}
contentLabel="onRequestClose Example"
// onRequestClose={closeModal} // prevent modal from closing when clicked outside
onRequestClose={closeModal}
className="Modal"
overlayClassName={`Overlay ${curClass}`}
>
Expand Down