Skip to content

Fix https://github.com/LinusBorg/vue-simple-portal/issues/42 #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions demo/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<h1>Demo App for VueSimplePortal</h1>
<nav class="nav">
<router-link to="/" exact>Base</router-link>
<router-link to="/condition" exact>
Base With condition component inside portal
</router-link>
<router-link to="/disable">Disable</router-link>
<router-link to="/transition">Transition</router-link>
<router-link to="/multiple">Multiple</router-link>
Expand Down
28 changes: 28 additions & 0 deletions demo/components/Condition.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<template>
<div>
<h1>Component with condition prop</h1>
<button id="toggle-button" @click="active = !active">
Toggle test component
</button>
<portal>
<Test :active="active" />
</portal>
</div>
</template>

<script>
import Test from './TestComponentProp'
export default {
name: 'Base',
data() {
return {
active: false,
}
},
components: {
Test,
},
}
</script>

<style lang="scss" scoped></style>
16 changes: 16 additions & 0 deletions demo/components/TestComponentProp.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<template>
<div v-if="active">
<h3 data-test="test-header">This is just a Test Component</h3>
<p>
Its purpose is to check the behaviour of components inside of the Simple
Portal which shown by prop
</p>
</div>
</template>

<script>
export default {
name: 'TestComponent',
props: ['active'],
}
</script>
2 changes: 1 addition & 1 deletion src/components/TargetContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default Vue.extend({
: h(this.tag || 'DIV', nodes)
},
destroyed() {
const { $el: el } = this
const el = this.$el.parentNode ? this.$el : this.updatedNodes()[0].elm
el.parentNode.removeChild(el)
},
})
13 changes: 13 additions & 0 deletions tests/e2e/specs/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ describe('My First Test', () => {
expect(this.el).to.not.have.descendants('[data-test="test-header"]')
})
})
it('correct destroy component inside portal with condition prop', function() {
cy.visit('/condition')
cy.portalTarget()
.as('el')
.then(el => {
expect(el).to.not.be.undefined

cy.get('#toggle-button').click()
return cy.wait(500)
})
cy.visit('/')
expect(this.el).to.not.have.descendants('[data-test="test-header"]')
})
it('works with multiple portals sending content', function() {
cy.visit('/multiple')
cy.portalTarget()
Expand Down