From 7e736674458f321fd7f4b8c81ebb1174a6990be6 Mon Sep 17 00:00:00 2001 From: Yunsup Sim Date: Thu, 28 Dec 2023 17:43:39 +0900 Subject: [PATCH] fix: Fix that onOpen and onClose is not dispatched. --- src/asModal/index.tsx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/asModal/index.tsx b/src/asModal/index.tsx index fa6162c..e102435 100755 --- a/src/asModal/index.tsx +++ b/src/asModal/index.tsx @@ -43,6 +43,8 @@ const asModal =

( // trapFocus: true, // returnFocus: true, classPrefix: classPrefixFromProps, + onOpen, + onClose, onEnter, onEntering, onEntered, @@ -58,6 +60,7 @@ const asModal =

( const classPrefixToUse = classPrefixFromProps || classPrefixFromContext; const slug = slugFromArg || slugFromProp; + const isInitialized = useRef(openOnInit); const isOpen = modalState[slug] && modalState[slug].isOpen; useEffect(() => { @@ -137,6 +140,22 @@ const asModal =

( transTime, ]); + useEffect(() => { + if (isOpen) { + onOpen?.(); + } else if (isInitialized.current) { + onClose?.(); + } + + if (!isInitialized.current) { + isInitialized.current = true; + } + }, [ + isOpen, + onOpen, + onClose + ]); + useEffect(() => { if (openOnInit) { openModal(slug);