11import Vue from '../../utils/vue'
22import { PortalTarget , Wormhole } from 'portal-vue'
33import warn from '../../utils/warn'
4- import { getById } from '../../utils/dom'
4+ import { getById , removeClass , requestAF } from '../../utils/dom'
55
66/* istanbul ignore file: for now until ready for testing */
77
@@ -37,9 +37,35 @@ export const props = {
3737
3838// @vue /component
3939export const DefaultTransition = Vue . extend ( {
40- functional : true ,
41- render ( h , { children } ) {
42- return h ( 'transition-group' , { props : { tag : 'div' , name : 'b-toaster' } } , children )
40+ // functional: true,
41+ // render(h, { children }) {
42+ // return h('transition-group', { props: { tag: 'div', name: 'b-toaster' } }, children)
43+ data ( ) {
44+ return {
45+ // Transition classes base name
46+ name : 'b-toaster'
47+ }
48+ } ,
49+ methods : {
50+ onAfterEnter ( el ) {
51+ // Handle bug where enter-to class is not removed.
52+ // Bug is related to portal-vue and transition-groups.
53+ requestAF ( ( ) => {
54+ removeClass ( el , `${ this . name } -enter-to` )
55+ // The *-move class is also stuck on elements that moved,
56+ // but there are no javascript hooks to handle after move.
57+ } )
58+ }
59+ } ,
60+ render ( h ) {
61+ return h (
62+ 'transition-group' ,
63+ {
64+ props : { tag : 'div' , name : this . name } ,
65+ on : { afterEnter : this . onAfterEnter }
66+ } ,
67+ this . $slots . default
68+ )
4369 }
4470} )
4571
@@ -50,15 +76,22 @@ export default Vue.extend({
5076 data ( ) {
5177 return {
5278 // We don't render on SSR or if a an existing target found
53- doRender : false
79+ doRender : false ,
80+ dead : false
5481 }
5582 } ,
5683 beforeMount ( ) {
5784 /* istanbul ignore if */
58- if ( getById ( this . name ) || Wormhole . targets [ this . name ] ) {
59- warn ( `b-toaster: A <portal-target> name '${ this . name } ' already exists in the document.` )
85+ if ( getById ( this . name ) || Wormhole . hasTarget ( this . name ) ) {
86+ warn ( `b-toaster: A <portal-target> with name '${ this . name } ' already exists in the document.` )
87+ this . dead = true
6088 } else {
6189 this . doRender = true
90+ this . $once ( 'hook:beforeDestroy' , ( ) => {
91+ // Let toasts made with `this.$bvToast.toast()` know that this toaster
92+ // is being destroyed and should should also destroy/hide themselves
93+ this . $root . $emit ( 'bv::toaster::destroyed' , this . name )
94+ } )
6295 }
6396 } ,
6497 destroyed ( ) {
@@ -68,7 +101,7 @@ export default Vue.extend({
68101 }
69102 } ,
70103 render ( h ) {
71- let $target = h ( 'div' , { class : 'd-none' } )
104+ let $target = h ( 'div' , { class : [ 'd-none' , { 'b-dead-toaster' : this . dead } ] } )
72105 if ( this . doRender ) {
73106 $target = h ( PortalTarget , {
74107 staticClass : 'b-toaster' ,
0 commit comments