1
1
import BButtonClose from '../button/button-close'
2
2
import { getComponentConfig } from '../../utils/config'
3
+ import { requestAF } from '../../utils/dom'
3
4
4
5
const NAME = 'BAlert'
5
6
@@ -36,7 +37,8 @@ export default {
36
37
data ( ) {
37
38
return {
38
39
countDownTimerId : null ,
39
- dismissed : false
40
+ dismissed : false ,
41
+ showClass : this . fade && this . show
40
42
}
41
43
} ,
42
44
computed : {
@@ -47,6 +49,11 @@ export default {
47
49
watch : {
48
50
show ( ) {
49
51
this . showChanged ( )
52
+ } ,
53
+ dismissed ( newVal ) {
54
+ if ( newVal ) {
55
+ this . $emit ( 'dismissed' )
56
+ }
50
57
}
51
58
} ,
52
59
mounted ( ) {
@@ -58,15 +65,13 @@ export default {
58
65
methods : {
59
66
dismiss ( ) {
60
67
this . clearCounter ( )
61
- this . dismissed = true
62
- this . $emit ( 'dismissed' )
63
- this . $emit ( 'input' , false )
64
68
if ( typeof this . show === 'number' ) {
65
69
this . $emit ( 'dismiss-count-down' , 0 )
66
70
this . $emit ( 'input' , 0 )
67
71
} else {
68
72
this . $emit ( 'input' , false )
69
73
}
74
+ this . dismissed = true
70
75
} ,
71
76
clearCounter ( ) {
72
77
if ( this . countDownTimerId ) {
@@ -101,27 +106,57 @@ export default {
101
106
// If not showing, render placeholder
102
107
return h ( false )
103
108
}
104
- let dismissBtn = h ( false )
109
+ let $ dismissBtn = h ( false )
105
110
if ( this . dismissible ) {
106
111
// Add dismiss button
107
- dismissBtn = h (
112
+ $ dismissBtn = h (
108
113
'b-button-close' ,
109
114
{ attrs : { 'aria-label' : this . dismissLabel } , on : { click : this . dismiss } } ,
110
115
[ this . $slots . dismiss ]
111
116
)
112
117
}
113
- const alert = h (
118
+ const $ alert = h (
114
119
'div' ,
115
120
{
116
121
staticClass : 'alert' ,
117
122
class : {
123
+ fade : this . fade ,
124
+ show : this . showClass ,
118
125
'alert-dismissible' : this . dismissible ,
119
126
[ `alert-${ this . variant } ` ] : this . variant
120
127
} ,
121
128
attrs : { role : 'alert' , 'aria-live' : 'polite' , 'aria-atomic' : true }
122
129
} ,
123
- [ dismissBtn , this . $slots . default ]
130
+ [ $ dismissBtn, this . $slots . default ]
124
131
)
125
- return ! this . fade ? alert : h ( 'transition' , { props : { name : 'fade' , appear : true } } , [ alert ] )
132
+ if ( this . fade ) {
133
+ return h (
134
+ 'transition' ,
135
+ {
136
+ props : {
137
+ // Disable use of built-in transition classes
138
+ 'enter-class' : '' ,
139
+ 'enter-active-class' : '' ,
140
+ 'enter-to-class' : '' ,
141
+ 'leave-class' : '' ,
142
+ 'leave-active-class' : '' ,
143
+ 'leave-to-class' : ''
144
+ } ,
145
+ on : {
146
+ beforeEnter ( ) {
147
+ requestAF ( ( ) => {
148
+ this . showClass = true
149
+ } )
150
+ } ,
151
+ beforeLeave ( ) {
152
+ this . showClass = false
153
+ }
154
+ }
155
+ } ,
156
+ [ $alert ]
157
+ )
158
+ } else {
159
+ return $alert
160
+ }
126
161
}
127
162
}
0 commit comments