Skip to content

Commit dc7e98d

Browse files
authored
alert: remove need for custom transition classes
1 parent c643738 commit dc7e98d

File tree

1 file changed

+44
-9
lines changed

1 file changed

+44
-9
lines changed

src/components/alert/alert.js

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import BButtonClose from '../button/button-close'
22
import { getComponentConfig } from '../../utils/config'
3+
import { requestAF } from '../../utils/dom'
34

45
const NAME = 'BAlert'
56

@@ -36,7 +37,8 @@ export default {
3637
data() {
3738
return {
3839
countDownTimerId: null,
39-
dismissed: false
40+
dismissed: false,
41+
showClass: this.fade && this.show
4042
}
4143
},
4244
computed: {
@@ -47,6 +49,11 @@ export default {
4749
watch: {
4850
show() {
4951
this.showChanged()
52+
},
53+
dismissed(newVal) {
54+
if (newVal) {
55+
this.$emit('dismissed')
56+
}
5057
}
5158
},
5259
mounted() {
@@ -58,15 +65,13 @@ export default {
5865
methods: {
5966
dismiss() {
6067
this.clearCounter()
61-
this.dismissed = true
62-
this.$emit('dismissed')
63-
this.$emit('input', false)
6468
if (typeof this.show === 'number') {
6569
this.$emit('dismiss-count-down', 0)
6670
this.$emit('input', 0)
6771
} else {
6872
this.$emit('input', false)
6973
}
74+
this.dismissed = true
7075
},
7176
clearCounter() {
7277
if (this.countDownTimerId) {
@@ -101,27 +106,57 @@ export default {
101106
// If not showing, render placeholder
102107
return h(false)
103108
}
104-
let dismissBtn = h(false)
109+
let $dismissBtn = h(false)
105110
if (this.dismissible) {
106111
// Add dismiss button
107-
dismissBtn = h(
112+
$dismissBtn = h(
108113
'b-button-close',
109114
{ attrs: { 'aria-label': this.dismissLabel }, on: { click: this.dismiss } },
110115
[this.$slots.dismiss]
111116
)
112117
}
113-
const alert = h(
118+
const $alert = h(
114119
'div',
115120
{
116121
staticClass: 'alert',
117122
class: {
123+
fade: this.fade,
124+
show: this.showClass,
118125
'alert-dismissible': this.dismissible,
119126
[`alert-${this.variant}`]: this.variant
120127
},
121128
attrs: { role: 'alert', 'aria-live': 'polite', 'aria-atomic': true }
122129
},
123-
[dismissBtn, this.$slots.default]
130+
[$dismissBtn, this.$slots.default]
124131
)
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+
}
126161
}
127162
}

0 commit comments

Comments
 (0)