Commit 36bed61f authored by badpunman's avatar badpunman Committed by 杨奕

remove popover's document click handler, related to #2561 (#2570)

* popover memory leak fix

* actual fix
parent 1f53559c
...@@ -60,15 +60,7 @@ export default { ...@@ -60,15 +60,7 @@ export default {
} }
if (this.trigger === 'click') { if (this.trigger === 'click') {
on(reference, 'click', () => { this.showPopper = !this.showPopper; }); on(reference, 'click', () => { this.showPopper = !this.showPopper; });
on(document, 'click', (e) => { on(document, 'click', this.handleDocumentClick);
if (!this.$el ||
!reference ||
this.$el.contains(e.target) ||
reference.contains(e.target) ||
!popper ||
popper.contains(e.target)) return;
this.showPopper = false;
});
} else if (this.trigger === 'hover') { } else if (this.trigger === 'hover') {
on(reference, 'mouseenter', this.handleMouseEnter); on(reference, 'mouseenter', this.handleMouseEnter);
on(popper, 'mouseenter', this.handleMouseEnter); on(popper, 'mouseenter', this.handleMouseEnter);
...@@ -111,6 +103,21 @@ export default { ...@@ -111,6 +103,21 @@ export default {
this._timer = setTimeout(() => { this._timer = setTimeout(() => {
this.showPopper = false; this.showPopper = false;
}, 200); }, 200);
},
handleDocumentClick(e) {
let reference = this.reference || this.$refs.reference;
const popper = this.popper || this.$refs.popper;
if (!reference && this.$slots.reference && this.$slots.reference[0]) {
reference = this.referenceElm = this.$slots.reference[0].elm;
}
if (!this.$el ||
!reference ||
this.$el.contains(e.target) ||
reference.contains(e.target) ||
!popper ||
popper.contains(e.target)) return;
this.showPopper = false;
} }
}, },
...@@ -123,6 +130,7 @@ export default { ...@@ -123,6 +130,7 @@ export default {
off(reference, 'blur'); off(reference, 'blur');
off(reference, 'mouseleave'); off(reference, 'mouseleave');
off(reference, 'mouseenter'); off(reference, 'mouseenter');
off(document, 'click', this.handleDocumentClick);
} }
}; };
</script> </script>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment