Skip to content

Commit e169a3c

Browse files
author
路振凯
committed
test: set CSSMotion key
1 parent 0955502 commit e169a3c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/Dialog/Content/index.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,20 @@ const Content = React.forwardRef<ContentRef, ContentProps>((props, ref) => {
3333
} = props;
3434

3535
const dialogRef = useRef<{ nativeElement: HTMLElement } & CSSMotionStateRef>(null);
36-
3736
const panelRef = useRef<PanelRef>(null);
3837

38+
// Force remount CSSMotion when visible changes from false to false
39+
// This handles React.Activity scenarios where component state is preserved
40+
const [motionKey, setMotionKey] = React.useState(0);
41+
const prevVisibleRef = useRef(visible);
42+
43+
React.useEffect(() => {
44+
if (!visible && !prevVisibleRef.current) {
45+
setMotionKey(k => k + 1);
46+
}
47+
prevVisibleRef.current = visible;
48+
}, [visible]);
49+
3950
// ============================== Refs ==============================
4051
React.useImperativeHandle(ref, () => ({
4152
...panelRef.current,
@@ -64,6 +75,7 @@ const Content = React.forwardRef<ContentRef, ContentProps>((props, ref) => {
6475
// ============================= Render =============================
6576
return (
6677
<CSSMotion
78+
key={motionKey}
6779
visible={visible}
6880
onVisibleChanged={onVisibleChanged}
6981
onAppearPrepare={onPrepare}

0 commit comments

Comments
 (0)