fix: detached content's disappearance in modal or drawer isn't delayed

This commit is contained in:
07akioni 2020-03-20 22:23:38 +08:00
parent aa977a6dc4
commit 0e08fd9d20
2 changed files with 33 additions and 4 deletions

View File

@ -1,3 +1,9 @@
function cleanUp (content, target) {
if (content && target && target.contains(content)) {
target.removeChild(content)
}
}
export default { export default {
name: 'NBasePortal', name: 'NBasePortal',
inject: { inject: {
@ -36,8 +42,17 @@ export default {
}, },
beforeDestroy () { beforeDestroy () {
const target = this.transferTarget() const target = this.transferTarget()
if (target && target.contains(this.$el)) { const content = this.$el
target.removeChild(this.$el) /**
* Since content may be detached in modal, waiting animation done is
* important. A more elegant solution is needed.
*/
if (this.NModal || this.NDrawer) {
setTimeout(() => {
cleanUp(content, target)
}, 300)
} else {
cleanUp(content, target)
} }
}, },
data () { data () {

View File

@ -1,5 +1,11 @@
import withapp from './withapp' import withapp from './withapp'
function cleanUp (content, target) {
if (content && target && target.contains(content)) {
target.removeChild(content)
}
}
/** /**
* Detach $refs.contentContainer to detachTarget * Detach $refs.contentContainer to detachTarget
* *
@ -93,8 +99,16 @@ export default {
if (this.syntheticDetachable) { if (this.syntheticDetachable) {
const content = this.getDetachContent() const content = this.getDetachContent()
const target = this.getDetachTarget() const target = this.getDetachTarget()
if (content && target && target.contains(content)) { /**
this.getDetachTarget().removeChild(content) * Since content may be detached in modal, waiting animation done is
* important. A more elegant solution is needed.
*/
if (this.NModal || this.NDrawer) {
setTimeout(() => {
cleanUp(content, target)
}, 300)
} else {
cleanUp(content, target)
} }
} }
} }