Skip to content

Commit 3fae6b0

Browse files
fix(MdPortal): always check if targetEl exists after apply it
1 parent d438d72 commit 3fae6b0

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/components/MdPortal/MdPortal.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ test('should re render after target change', async () => {
6868
portalWrapper.setProps({
6969
mdTargetEl: targetEl
7070
})
71+
portalWrapper.vm.$nextTick()
7172
expect(document.body.childNodes).not.toContain(portalEl)
7273
expect(targetEl.contains(portalEl)).toBe(true)
7374
})

src/components/MdPortal/MdPortal.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@
5454
},
5555
watch: {
5656
mdTargetEl (newTarget, oldTarget) {
57+
this.changeParentEl()
58+
newTarget.appendChild(this.$el)
59+
5760
if (oldTarget) {
58-
this.changeParentEl()
59-
newTarget.appendChild(this.$el)
6061
this.$forceUpdate()
6162
}
6263
}
@@ -70,11 +71,12 @@
7071
})
7172
},
7273
changeParentEl () {
73-
this.$options._parentElm = this.mdTargetEl || document.body
74+
this.targetEl = this.mdTargetEl || document.body
75+
this.$options._parentElm = this.targetEl
7476
},
7577
killGhostElement () {
76-
if (this.mdTargetEl.contains(this.$el)) {
77-
this.mdTargetEl.removeChild(this.$el)
78+
if (this.targetEl.contains(this.$el)) {
79+
this.targetEl.removeChild(this.$el)
7880
}
7981
},
8082
destroyElement () {

0 commit comments

Comments
 (0)