From f457cd7f570e8833d91dd80a14834a3f02ac127c Mon Sep 17 00:00:00 2001 From: Leopoldthecoder Date: Mon, 25 Sep 2017 15:13:06 +0800 Subject: [PATCH] Tooltip: fix disabled tooltip affecting other instances --- examples/components/side-nav.vue | 5 +++++ examples/docs/zh-CN/table.md | 10 +++++----- examples/index.tpl | 1 + packages/tooltip/src/main.js | 31 ++++++++++++++++++++++--------- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/examples/components/side-nav.vue b/examples/components/side-nav.vue index 11a9f4b51..575c6f06b 100644 --- a/examples/components/side-nav.vue +++ b/examples/components/side-nav.vue @@ -91,6 +91,10 @@ line-height: 26px; margin-top: 10px; } + + #code-sponsor-widget { + margin: 50px 0 0 -20px; + } } .nav-dropdown-list { width: 120px; @@ -165,6 +169,7 @@ +
<% } %> diff --git a/packages/tooltip/src/main.js b/packages/tooltip/src/main.js index 2a9fe2c90..2d9b942c1 100644 --- a/packages/tooltip/src/main.js +++ b/packages/tooltip/src/main.js @@ -48,8 +48,7 @@ export default { data() { return { - timeoutPending: null, - handlerAdded: false + timeoutPending: null }; }, @@ -94,11 +93,10 @@ export default { const nativeOn = vnode.data.nativeOn = vnode.data.nativeOn || {}; data.staticClass = this.concatClass(data.staticClass, 'el-tooltip'); - if (this.handlerAdded) return vnode; - on.mouseenter = this.addEventHandle(on.mouseenter, () => { this.setExpectedState(true); this.handleShowPopper(); }); - on.mouseleave = this.addEventHandle(on.mouseleave, () => { this.setExpectedState(false); this.debounceClose(); }); - nativeOn.mouseenter = this.addEventHandle(nativeOn.mouseenter, () => { this.setExpectedState(true); this.handleShowPopper(); }); - nativeOn.mouseleave = this.addEventHandle(nativeOn.mouseleave, () => { this.setExpectedState(false); this.debounceClose(); }); + on.mouseenter = this.addEventHandle(on.mouseenter, this.show); + on.mouseleave = this.addEventHandle(on.mouseleave, this.hide); + nativeOn.mouseenter = this.addEventHandle(nativeOn.mouseenter, this.show); + nativeOn.mouseleave = this.addEventHandle(nativeOn.mouseleave, this.hide); return vnode; }, @@ -108,9 +106,24 @@ export default { }, methods: { + show() { + this.setExpectedState(true); + this.handleShowPopper(); + }, + + hide() { + this.setExpectedState(false); + this.debounceClose(); + }, + addEventHandle(old, fn) { - this.handlerAdded = true; - return old ? Array.isArray(old) ? old.concat(fn) : [old, fn] : fn; + if (!old) { + return fn; + } else if (Array.isArray(old)) { + return old.indexOf(fn) > -1 ? old : old.concat(fn); + } else { + return old === fn ? old : [old, fn]; + } }, concatClass(a, b) {