Skip to content

Commit 8e20700

Browse files
committed
fix: menu hide animate lose
1 parent fcd6add commit 8e20700

File tree

4 files changed

+18
-19
lines changed

4 files changed

+18
-19
lines changed

components/menu/src/PopupTrigger.tsx

+12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { placements, placementsRtl } from './placements';
77
import type { RafFrame } from '../../_util/raf';
88
import raf from '../../_util/raf';
99
import classNames from '../../_util/classNames';
10+
import { getTransitionProps } from '../../_util/transition';
1011

1112
const popupPlacementMap = {
1213
horizontal: 'bottomLeft',
@@ -40,6 +41,9 @@ export default defineComponent({
4041
triggerSubMenuAction,
4142
isRootMenu,
4243
forceSubMenuRender,
44+
motion,
45+
defaultMotions,
46+
mode,
4347
} = useInjectMenu();
4448
const forceRender = useInjectForceRender();
4549
const placement = computed(() =>
@@ -68,6 +72,13 @@ export default defineComponent({
6872
const onVisibleChange = (visible: boolean) => {
6973
emit('visibleChange', visible);
7074
};
75+
const style = ref({});
76+
const className = ref('');
77+
const mergedMotion = computed(() => {
78+
const m = motion.value || defaultMotions.value?.[mode.value] || defaultMotions.value?.other;
79+
const res = typeof m === 'function' ? m(style, className) : m;
80+
return res ? getTransitionProps(res.name, { css: true }) : undefined;
81+
});
7182
return () => {
7283
const { prefixCls, popupClassName, mode, popupOffset, disabled } = props;
7384
return (
@@ -93,6 +104,7 @@ export default defineComponent({
93104
mouseLeaveDelay={subMenuCloseDelay.value}
94105
onPopupVisibleChange={onVisibleChange}
95106
forceRender={forceRender || forceSubMenuRender.value}
107+
popupAnimation={mergedMotion.value}
96108
v-slots={{
97109
popup: () => {
98110
return slots.popup?.({ visible: innerVisible.value });

components/menu/src/SubMenu.tsx

+4-17
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import useDirectionStyle from './hooks/useDirectionStyle';
1515
import PopupTrigger from './PopupTrigger';
1616
import SubMenuList from './SubMenuList';
1717
import InlineSubMenuList from './InlineSubMenuList';
18-
import Transition, { getTransitionProps } from '../../_util/transition';
1918
import { cloneElement } from '../../_util/vnode';
2019
import Overflow from '../../vc-overflow';
2120
import devWarning from '../../vc-util/devWarning';
@@ -93,8 +92,6 @@ export default defineComponent({
9392
registerMenuInfo,
9493
unRegisterMenuInfo,
9594
selectedSubMenuKeys,
96-
motion,
97-
defaultMotions,
9895
expandIcon: menuExpandIcon,
9996
} = useInjectMenu();
10097

@@ -230,14 +227,6 @@ export default defineComponent({
230227

231228
const renderMode = computed(() => (mode.value === 'horizontal' ? 'vertical' : mode.value));
232229

233-
const style = ref({});
234-
const className = ref('');
235-
const mergedMotion = computed(() => {
236-
const m = motion.value || defaultMotions.value?.[mode.value] || defaultMotions.value?.other;
237-
const res = typeof m === 'function' ? m(style, className) : m;
238-
return res ? getTransitionProps(res.name) : undefined;
239-
});
240-
241230
const subMenuTriggerModeRef = computed(() =>
242231
triggerModeRef.value === 'horizontal' ? 'vertical' : triggerModeRef.value,
243232
);
@@ -291,13 +280,11 @@ export default defineComponent({
291280
disabled={mergedDisabled.value}
292281
onVisibleChange={onPopupVisibleChange}
293282
v-slots={{
294-
popup: ({ visible }) => (
283+
popup: () => (
295284
<MenuContextProvider mode={subMenuTriggerModeRef.value} isRootMenu={false}>
296-
<Transition {...mergedMotion.value}>
297-
<SubMenuList v-show={visible} id={popupId} ref={popupRef}>
298-
{slots.default?.()}
299-
</SubMenuList>
300-
</Transition>
285+
<SubMenuList id={popupId} ref={popupRef}>
286+
{slots.default?.()}
287+
</SubMenuList>
301288
</MenuContextProvider>
302289
),
303290
}}

components/vc-trigger/Popup/PopupInner.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export default defineComponent({
8383

8484
// ======================== Motion ========================
8585
const motion = computed(() => {
86-
const m = getMotion(props);
86+
const m = typeof props.animation === 'object' ? props.animation : getMotion(props as any);
8787
['onAfterEnter', 'onAfterLeave'].forEach(eventName => {
8888
m[eventName] = () => {
8989
goNextStatus();

components/vc-trigger/Popup/interface.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const innerProps = {
1111
forceRender: Boolean,
1212

1313
// Legacy Motion
14-
animation: String,
14+
animation: [String, Object],
1515
transitionName: String,
1616

1717
// Measure

0 commit comments

Comments
 (0)