[Improvement] Popup: get-container support selector (#1699)

This commit is contained in:
neverland
2018-08-27 17:10:50 +08:00
committed by GitHub
parent ab00a16b6a
commit 9e22eb4c1f
11 changed files with 43 additions and 13 deletions
+14 -4
View File
@@ -21,7 +21,7 @@ export default {
// z-index
zIndex: [String, Number],
// return the mount node for popup
getContainer: Function,
getContainer: [String, Function],
// prevent body scroll
lockScroll: {
type: Boolean,
@@ -139,10 +139,20 @@ export default {
},
move() {
if (this.getContainer) {
this.getContainer().appendChild(this.$el);
let container;
const { getContainer } = this;
if (getContainer) {
container =
typeof getContainer === 'string'
? document.querySelector(getContainer)
: getContainer();
} else if (this.$parent) {
this.$parent.$el.appendChild(this.$el);
container = this.$parent.$el;
}
if (container) {
container.appendChild(this.$el);
}
},