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);