-
-
Notifications
You must be signed in to change notification settings - Fork 205
fix: Resolve DOM residue issue on activate #525
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
Changes from 2 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 | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -58,6 +58,7 @@ const Dialog: React.FC<IDialogPropTypes> = (props) => { | |||||||||||||||||||||||||||||||||||||
| const lastOutSideActiveElementRef = useRef<HTMLElement>(null); | ||||||||||||||||||||||||||||||||||||||
| const wrapperRef = useRef<HTMLDivElement>(null); | ||||||||||||||||||||||||||||||||||||||
| const contentRef = useRef<ContentRef>(null); | ||||||||||||||||||||||||||||||||||||||
| const closeTimerRef = useRef<ReturnType<typeof setTimeout>>(null); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const [animatedVisible, setAnimatedVisible] = React.useState(visible); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
@@ -157,22 +158,36 @@ const Dialog: React.FC<IDialogPropTypes> = (props) => { | |||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // ========================= Effect ========================= | ||||||||||||||||||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||||||||||||||||||
| clearTimeout(closeTimerRef.current); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if (visible) { | ||||||||||||||||||||||||||||||||||||||
| setAnimatedVisible(true); | ||||||||||||||||||||||||||||||||||||||
| saveLastOutSideActiveElementRef(); | ||||||||||||||||||||||||||||||||||||||
| } else if ( | ||||||||||||||||||||||||||||||||||||||
| animatedVisible && | ||||||||||||||||||||||||||||||||||||||
| contentRef.current.enableMotion() && | ||||||||||||||||||||||||||||||||||||||
| !contentRef.current.inMotion() | ||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||
| doClose(); | ||||||||||||||||||||||||||||||||||||||
| } else if (animatedVisible) { | ||||||||||||||||||||||||||||||||||||||
| const hasMotion = contentRef.current?.enableMotion?.(); | ||||||||||||||||||||||||||||||||||||||
| const inMotion = contentRef.current?.inMotion?.(); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if (hasMotion && !inMotion) { | ||||||||||||||||||||||||||||||||||||||
| doClose(); | ||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||
| closeTimerRef.current = setTimeout(() => { | ||||||||||||||||||||||||||||||||||||||
| if (!visible && animatedVisible) { | ||||||||||||||||||||||||||||||||||||||
| doClose(); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| }, 500); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
| if (hasMotion && !inMotion) { | |
| doClose(); | |
| } else { | |
| closeTimerRef.current = setTimeout(() => { | |
| if (!visible && animatedVisible) { | |
| doClose(); | |
| } | |
| }, 500); | |
| } | |
| if (!hasMotion || !inMotion) { | |
| doClose(); | |
| } else { | |
| closeTimerRef.current = setTimeout(() => { | |
| if (!visible && animatedVisible) { | |
| doClose(); | |
| } | |
| }, 500); | |
| } |
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.
The timeout duration
500is a magic number. It's better to define it as a constant with a descriptive name (e.g.,const DIALOG_CLOSE_FALLBACK_TIMEOUT = 500;) at the top of the component. This improves readability and makes the purpose of the timeout clearer and easier to modify in the future.