Popup: prevent click event bubbles, fixed #1677 (#1754)

pull/1807/head
cinwell.li 2016-12-15 12:50:08 +08:00 committed by baiyaaaaa
parent 5e692418ff
commit 6d2f68b24c
1 changed files with 7 additions and 3 deletions

View File

@ -1,6 +1,8 @@
import PopperJS from './popper'; import PopperJS from './popper';
import { PopupManager } from 'vue-popup'; import { PopupManager } from 'vue-popup';
const stop = e => e.stopPropagation();
/** /**
* @param {HTMLElement} [reference=$refs.reference] - The reference element used to position the popper. * @param {HTMLElement} [reference=$refs.reference] - The reference element used to position the popper.
* @param {HTMLElement} [popper=$refs.popper] - The HTML element used as popper, or a configuration used to generate the popper. * @param {HTMLElement} [popper=$refs.popper] - The HTML element used as popper, or a configuration used to generate the popper.
@ -93,6 +95,7 @@ export default {
this.$nextTick(this.updatePopper); this.$nextTick(this.updatePopper);
}); });
this.popperJS._popper.style.zIndex = PopupManager.nextZIndex(); this.popperJS._popper.style.zIndex = PopupManager.nextZIndex();
this.popperElm.addEventListener('click', stop);
}, },
updatePopper() { updatePopper() {
@ -149,9 +152,10 @@ export default {
beforeDestroy() { beforeDestroy() {
this.doDestroy(); this.doDestroy();
this.popperElm && if (this.popperElm && this.popperElm.parentNode === document.body) {
this.popperElm.parentNode === document.body && this.popperElm.removeEventListener('click', stop);
document.body.removeChild(this.popperElm); document.body.removeChild(this.popperElm);
}
}, },
// call destroy in keep-alive mode // call destroy in keep-alive mode