Skip to content

Commit 8ed8133

Browse files
committed
fix(Submenu): add popupVisible to TdSubMenuInterface and update provide logic
1 parent b546c09 commit 8ed8133

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

packages/components/menu/submenu.tsx

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import {
99
watch,
1010
Slots,
1111
toRefs,
12-
reactive,
1312
nextTick,
1413
Transition,
14+
toRef,
1515
} from 'vue';
1616
import props from './submenu-props';
1717
import { TdMenuInterface, TdSubMenuInterface, TdMenuItem } from './types';
@@ -36,7 +36,7 @@ export default defineComponent({
3636
const { theme, activeValues, expandValues, isHead, open } = menu;
3737

3838
const submenu = inject<TdSubMenuInterface>('TdSubmenu', {});
39-
const { setSubPopup, closeParentPopup } = submenu;
39+
const { setSubPopup, closeParentPopup, popupVisible: parentPopupVisible } = submenu;
4040

4141
const mode = computed(() => attrs.expandType || menu.mode.value);
4242

@@ -100,26 +100,26 @@ export default defineComponent({
100100
},
101101
]);
102102

103-
provide<TdSubMenuInterface>(
104-
'TdSubmenu',
105-
reactive({
106-
value,
107-
addMenuItem: (item: TdMenuItem) => {
108-
menuItems.value.push(item);
109-
if (submenu) {
110-
submenu.addMenuItem(item);
111-
}
112-
},
113-
setSubPopup: (ref: HTMLElement) => {
114-
subPopupRef.value = ref;
115-
},
116-
closeParentPopup: (e: MouseEvent) => {
117-
const related = e.relatedTarget as HTMLElement;
118-
if (loopInPopup(related)) return;
119-
handleMouseLeavePopup(e);
120-
},
121-
}),
122-
);
103+
const submenuInterface = {
104+
value: value.value,
105+
addMenuItem: (item: TdMenuItem) => {
106+
menuItems.value.push(item);
107+
if (submenu) {
108+
submenu.addMenuItem(item);
109+
}
110+
},
111+
setSubPopup: (ref: HTMLElement) => {
112+
subPopupRef.value = ref;
113+
},
114+
closeParentPopup: (e: MouseEvent) => {
115+
const related = e.relatedTarget as HTMLElement;
116+
if (loopInPopup(related)) return;
117+
handleMouseLeavePopup(e);
118+
},
119+
popupVisible: toRef(popupVisible),
120+
};
121+
122+
provide<TdSubMenuInterface>('TdSubmenu', submenuInterface);
123123

124124
const passSubPopupRefToParent = (val: HTMLElement) => {
125125
if (isFunction(setSubPopup)) {
@@ -131,6 +131,7 @@ export default defineComponent({
131131
const handleMouseEnter = () => {
132132
if (props.disabled) return;
133133
setTimeout(() => {
134+
if (parentPopupVisible?.value === false) return;
134135
if (!popupVisible.value) {
135136
open(props.value);
136137

@@ -178,6 +179,9 @@ export default defineComponent({
178179
closeParentPopup?.(e);
179180
};
180181
const handleEnterPopup = () => {
182+
// 如果父 popup 存在且不可见,不触发保持可见功能
183+
if (parentPopupVisible?.value === false) return;
184+
181185
isCursorInPopup.value = true;
182186
};
183187

packages/components/menu/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ export interface TdSubMenuInterface {
2828
addMenuItem?: (item: TdMenuItem) => void;
2929
setSubPopup?: (popupRef: HTMLElement) => void;
3030
closeParentPopup?: (e: MouseEvent) => void;
31+
popupVisible?: Ref<boolean>;
3132
}

0 commit comments

Comments
 (0)