-
Notifications
You must be signed in to change notification settings - Fork 322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(Modal): unmount when hidden #2165
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import React, { useCallback, useEffect } from "react"; | ||
import React, { useState, useCallback, useEffect } from "react"; | ||
import useAnimationProps from "./useAnimationProps"; | ||
import useKeyEvent from "../../hooks/useKeyEvent/index"; | ||
import { A11yDialogType } from "./ModalHelper"; | ||
|
@@ -19,6 +19,7 @@ export default function useShowHideModal({ | |
onClose: () => void; | ||
alertDialog: boolean; | ||
}) { | ||
const [isAnimating, setIsAnimating] = useState(false); | ||
const getAnimationProps = useAnimationProps(triggerElement, instance); | ||
|
||
const closeOnEsc = useCallback( | ||
|
@@ -37,22 +38,28 @@ export default function useShowHideModal({ | |
keys: KEYS | ||
}); | ||
|
||
// show/hide and animate the modal | ||
useEffect(() => { | ||
if (!instance) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why did you removed this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The check is unnecessary here, it's already checked inside the conditions. If it exists here, when the modal is not being rendered, it will not render at all |
||
return; | ||
} | ||
const animate = instance?.$el.childNodes[1].animate; | ||
if (show) { | ||
setIsAnimating(true); | ||
instance?.show(); | ||
if (animate) instance?.$el.childNodes[1].animate?.(...getAnimationProps()); | ||
const animate = instance?.$el.childNodes[1].animate; | ||
if (animate) { | ||
instance?.$el.childNodes[1].animate?.(...getAnimationProps()); | ||
} | ||
} else { | ||
const animate = instance?.$el.childNodes[1].animate; | ||
if (animate) { | ||
const animation = instance?.$el.childNodes[1]?.animate(...getAnimationProps(true)); | ||
animation?.finished.then(() => instance?.hide()); | ||
animation?.finished.then(() => { | ||
setIsAnimating(false); | ||
instance?.hide(); | ||
}); | ||
} else { | ||
setIsAnimating(false); | ||
instance?.hide(); | ||
} | ||
} | ||
}, [show, instance, getAnimationProps]); | ||
|
||
return { shouldShow: isAnimating }; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened a ticket to remove it next major