Skip to content

Commit

Permalink
fix: handleMenuClick trigger multiple times
Browse files Browse the repository at this point in the history
1. handleMenuClick listerner not removed on menu hide
  • Loading branch information
Volankey authored and Moyee committed Aug 12, 2020
1 parent 55ab1fe commit c3b16cc
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/plugins/menu/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ export default class Menu extends Base {

const handleMenuClick = this.get('handleMenuClick')
if (handleMenuClick) {
menuDom.addEventListener('click', handleMenuClick);
const handleMenuClickWrapper = (evt) => {
handleMenuClick(evt.target, e.item)
}
this.set('handleMenuClickWrapper', handleMenuClickWrapper)
menuDom.addEventListener('click', handleMenuClickWrapper);
}

const graph: Graph = this.get('graph');
Expand Down Expand Up @@ -166,19 +170,19 @@ export default class Menu extends Base {
// 隐藏菜单后需要移除事件监听
document.body.removeEventListener('click', this.get('handler'));

const handleMenuClick = this.get('handleMenuClick')
if (handleMenuClick) {
menuDom.removeEventListener('click', handleMenuClick)
const handleMenuClickWrapper = this.get('handleMenuClickWrapper');
if (handleMenuClickWrapper) {
menuDom.removeEventListener('click', handleMenuClickWrapper);
}
}

public destroy() {
const menu = this.get('menu')
const handler = this.get('handler');

const handleMenuClick = this.get('handleMenuClick')
if (handleMenuClick) {
menu.removeEventListener('click', handleMenuClick)
const handleMenuClickWrapper = this.get('handleMenuClickWrapper');
if (handleMenuClickWrapper) {
menu.removeEventListener('click', handleMenuClickWrapper);
}

if (menu) {
Expand Down

0 comments on commit c3b16cc

Please sign in to comment.