From fc3595f6cc208da7ee1e2b649c0e6331789d20b5 Mon Sep 17 00:00:00 2001 From: Kim Chiyoung Date: Tue, 10 Jun 2025 17:38:31 +0900 Subject: [PATCH] =?UTF-8?q?hotfix:=20showModal=EC=97=90=20onModalClose=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=EB=A5=BC=20=EC=A0=84=EB=8B=AC=ED=95=A0=20?= =?UTF-8?q?=EC=88=98=20=EC=9E=88=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/contexts/ModalProvider.jsx | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/contexts/ModalProvider.jsx b/src/contexts/ModalProvider.jsx index 74792a0..c7705cc 100644 --- a/src/contexts/ModalProvider.jsx +++ b/src/contexts/ModalProvider.jsx @@ -13,6 +13,8 @@ export const ModalProvider = ({ children }) => { const [isOpen, setIsOpen] = useState(false); const [isClosing, setIsClosing] = useState(false); + const onModalCloseEventRef = useRef(null); + const modalWrapperRef = useRef(null); const isMouseDownInsideModal = useRef(false); @@ -27,17 +29,20 @@ export const ModalProvider = ({ children }) => { const pendingForClosingAnimation = () => { closeTimeoutRef.current = setTimeout(() => { - setIsOpen(false); - setIsClosing(false); - closeTimeoutRef.current = null; + if (isClosing) { + setIsOpen(false); + setIsClosing(false); + closeTimeoutRef.current = null; + } }, MODAL_CLOSE_DELAY); }; - const showModal = (ModalComponent) => { + const showModal = (ModalComponent, { onModalClose } = {}) => { resetTimer(); setModal(ModalComponent); setIsOpen(true); setIsClosing(false); + onModalCloseEventRef.current = onModalClose; }; const closeModal = () => { @@ -64,7 +69,12 @@ export const ModalProvider = ({ children }) => { !modalWrapperRef.current?.contains(e.target) && isMouseDownInsideModal.current === false ) { - closeModal(); + if (typeof onModalCloseEventRef.current === 'function') { + onModalCloseEventRef.current(); + closeModal(); + } else { + closeModal(); + } } };