From ea70d662347683f6e6e2c4be572ade3e3055fb99 Mon Sep 17 00:00:00 2001 From: JarvisArt <1120886013@qq.com> Date: Fri, 30 Dec 2022 16:47:15 +0800 Subject: [PATCH 1/3] fix: vertical animation not being affected by inline --- src/SubMenu/PopupTrigger.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/SubMenu/PopupTrigger.tsx b/src/SubMenu/PopupTrigger.tsx index f32ed5bb..21136bb8 100644 --- a/src/SubMenu/PopupTrigger.tsx +++ b/src/SubMenu/PopupTrigger.tsx @@ -62,9 +62,20 @@ export default function PopupTrigger({ const popupPlacement = popupPlacementMap[mode]; const targetMotion = getMotion(mode, motion, defaultMotions); + const [innerMotion, setInnerMotion] = React.useState(targetMotion); + + React.useEffect(() => { + /** + * PopupTrigger is only used for vertical and horizontal types. + * When collapsed is unfolded, the inline animation will destroy the vertical animation. + */ + if (mode !== 'inline') { + setInnerMotion(targetMotion); + } + }, [mode, motion, defaultMotions]); const mergedMotion: CSSMotionProps = { - ...targetMotion, + ...innerMotion, leavedClassName: `${prefixCls}-hidden`, removeOnLeave: false, motionAppear: true, From da328fe6eb23961c14b3b94ad5cec4f77e77e330 Mon Sep 17 00:00:00 2001 From: JarvisArt <1120886013@qq.com> Date: Fri, 30 Dec 2022 22:15:03 +0800 Subject: [PATCH 2/3] test: inline does not affect vertical motion --- tests/Menu.spec.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/Menu.spec.js b/tests/Menu.spec.js index e973b0bb..f9212b83 100644 --- a/tests/Menu.spec.js +++ b/tests/Menu.spec.js @@ -574,6 +574,22 @@ describe('Menu', () => { rerender(genMenu({ mode: 'vertical' })); expect(global.triggerProps.popupMotion.motionName).toEqual('bambooLight'); }); + + it('inline does not affect vertical motion', () => { + const genMenu = props => ( +
+ ); + + const { rerender } = render(genMenu({ mode: 'vertical' })); + rerender(genMenu({ mode: 'inline' })); + expect(global.triggerProps.popupMotion.motionName).toEqual( + 'defaultMotion', + ); + }); }); it('onMouseEnter should work', () => { From 5c5ec4f44e1ac8809d7a7002b6cf9e4f8e2e970e Mon Sep 17 00:00:00 2001 From: JarvisArt <1120886013@qq.com> Date: Tue, 17 Jan 2023 13:21:10 +0800 Subject: [PATCH 3/3] chore: optimize logic --- src/SubMenu/PopupTrigger.tsx | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/SubMenu/PopupTrigger.tsx b/src/SubMenu/PopupTrigger.tsx index 21136bb8..aba6e1d6 100644 --- a/src/SubMenu/PopupTrigger.tsx +++ b/src/SubMenu/PopupTrigger.tsx @@ -62,20 +62,18 @@ export default function PopupTrigger({ const popupPlacement = popupPlacementMap[mode]; const targetMotion = getMotion(mode, motion, defaultMotions); - const [innerMotion, setInnerMotion] = React.useState(targetMotion); + const targetMotionRef = React.useRef(targetMotion); - React.useEffect(() => { + if (mode !== 'inline') { /** * PopupTrigger is only used for vertical and horizontal types. * When collapsed is unfolded, the inline animation will destroy the vertical animation. */ - if (mode !== 'inline') { - setInnerMotion(targetMotion); - } - }, [mode, motion, defaultMotions]); + targetMotionRef.current = targetMotion; + } const mergedMotion: CSSMotionProps = { - ...innerMotion, + ...targetMotionRef.current, leavedClassName: `${prefixCls}-hidden`, removeOnLeave: false, motionAppear: true,