Skip to content

Commit c8ff3ad

Browse files
Menu: add popper-append-to-body for SubMenu (ElemeFE#10515)
1 parent 3ee0c59 commit c8ff3ad

File tree

6 files changed

+38
-5
lines changed

6 files changed

+38
-5
lines changed

examples/docs/en-US/menu.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ Vertical NavMenu could be collapsed.
336336
| show-timeout | timeout before showing a sub-menu | number || 300 |
337337
| hide-timeout | timeout before hiding a sub-menu | number || 300 |
338338
| disabled | whether the sub-menu is disabled | boolean || false |
339+
| popper-append-to-body | whether to append the popup menu to body. If the positioning of the menu is wrong, you can try setting this prop | boolean | - | level one Submenu: true / other Submenus: false |
339340

340341
### Menu-Item Attribute
341342
| Attribute | Description | Type | Accepted Values | Default |

examples/docs/es/menu.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ NavMenu vertical puede ser colapsado.
338338
| show-timeout | tiempo de espera antes de mostrar un submenú | number || 300 |
339339
| hide-timeout | tiempo de espera antes de ocultar un submenú | number || 300 |
340340
| disabled | si esta `disabled` el sub-menu | boolean || false |
341+
| popper-append-to-body | whether to append the popup menu to body. If the positioning of the menu is wrong, you can try setting this prop | boolean | - | level one Submenu: true / other Submenus: false |
341342

342343
### Atributos Menu-Item
343344
| Atributo | Descripción | Tipo | Valores aceptados | Por defecto |

examples/docs/zh-CN/menu.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@
332332
| show-timeout | 展开 sub-menu 的延时 | number || 300 |
333333
| hide-timeout | 收起 sub-menu 的延时 | number || 300 |
334334
| disabled | 是否禁用 | boolean || false |
335+
| popper-append-to-body | 是否将弹出菜单插入至 body 元素。在菜单的定位出现问题时,可尝试修改该属性 | boolean || 一级子菜单:true / 非一级子菜单:false |
335336

336337
### Menu-Item Attribute
337338
| 参数 | 说明 | 类型 | 可选值 | 默认值 |

packages/menu/src/submenu.vue

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,20 @@
4343
default: 300
4444
},
4545
popperClass: String,
46-
disabled: Boolean
46+
disabled: Boolean,
47+
popperAppendToBody: {
48+
type: Boolean,
49+
default: undefined
50+
}
4751
},
4852
4953
data() {
5054
return {
5155
popperJS: null,
5256
timeout: null,
5357
items: {},
54-
submenus: {}
58+
submenus: {},
59+
mouseInChild: false
5560
};
5661
},
5762
watch: {
@@ -66,7 +71,9 @@
6671
computed: {
6772
// popper option
6873
appendToBody() {
69-
return this.isFirstLevel;
74+
return this.popperAppendToBody === undefined
75+
? this.isFirstLevel
76+
: this.popperAppendToBody;
7077
},
7178
menuTransitionName() {
7279
return this.rootMenu.collapse ? 'el-zoom-in-left' : 'el-zoom-in-top';
@@ -180,6 +187,7 @@
180187
) {
181188
return;
182189
}
190+
this.dispatch('ElSubmenu', 'mouse-enter-child');
183191
clearTimeout(this.timeout);
184192
this.timeout = setTimeout(() => {
185193
this.rootMenu.openMenu(this.index, this.indexPath);
@@ -193,9 +201,10 @@
193201
) {
194202
return;
195203
}
204+
this.dispatch('ElSubmenu', 'mouse-leave-child');
196205
clearTimeout(this.timeout);
197206
this.timeout = setTimeout(() => {
198-
this.rootMenu.closeMenu(this.index);
207+
!this.mouseInChild && this.rootMenu.closeMenu(this.index);
199208
}, this.hideTimeout);
200209
},
201210
handleTitleMouseenter() {
@@ -223,6 +232,14 @@
223232
this.parentMenu.addSubmenu(this);
224233
this.rootMenu.addSubmenu(this);
225234
this.$on('toggle-collapse', this.handleCollapseToggle);
235+
this.$on('mouse-enter-child', () => {
236+
this.mouseInChild = true;
237+
clearTimeout(this.timeout);
238+
});
239+
this.$on('mouse-leave-child', () => {
240+
this.mouseInChild = false;
241+
clearTimeout(this.timeout);
242+
});
226243
},
227244
mounted() {
228245
this.initPopper();

packages/theme-chalk/src/menu.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@
190190
}
191191
&-right-start {
192192
margin-left: 5px;
193+
margin-right: 5px;
193194
}
194195
}
195196
}

types/submenu.d.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ export declare class ElSubmenu extends ElementUIComponent {
88
/** Delay time before show a sub-menu */
99
showTimeout: number
1010

11-
/** Delay time before hide a sub-menu */
11+
/** Delay time before showing a sub-menu */
12+
showTimeout: number
13+
14+
/** Delay time before hiding a sub-menu */
1215
hideTimeout: number
16+
17+
/** Custom class name for the popup menu */
18+
popperClass: string
19+
20+
/** Whether the sub-menu is disabled */
21+
disabled: boolean
22+
23+
/** Whether to append the popper menu to body */
24+
popperAppendToBody: boolean
1325
}

0 commit comments

Comments
 (0)