@@ -3,15 +3,14 @@ import idMixin from '../../mixins/id'
33import listenOnRootMixin from '../../mixins/listen-on-root'
44import normalizeSlotMixin from '../../mixins/normalize-slot'
55import { isBrowser } from '../../utils/env'
6+ import { BVCollapse } from '../../utils/bv-collapse'
67import {
78 addClass ,
89 hasClass ,
910 removeClass ,
1011 closest ,
1112 matches ,
12- reflow ,
1313 getCS ,
14- getBCR ,
1514 eventOn ,
1615 eventOff
1716} from '../../utils/dom'
@@ -54,6 +53,11 @@ export const BCollapse = /*#__PURE__*/ Vue.extend({
5453 tag : {
5554 type : String ,
5655 default : 'div'
56+ } ,
57+ appear : {
58+ // If `true` (and `visible` is `true` on mount), animate initially visible
59+ type : Boolean ,
60+ default : false
5761 }
5862 } ,
5963 data ( ) {
@@ -141,36 +145,26 @@ export const BCollapse = /*#__PURE__*/ Vue.extend({
141145 this . show = ! this . show
142146 } ,
143147 onEnter ( el ) {
144- el . style . height = 0
145- reflow ( el )
146- el . style . height = el . scrollHeight + 'px'
147148 this . transitioning = true
148149 // This should be moved out so we can add cancellable events
149150 this . $emit ( 'show' )
150151 } ,
151152 onAfterEnter ( el ) {
152- el . style . height = null
153153 this . transitioning = false
154154 this . $emit ( 'shown' )
155155 } ,
156156 onLeave ( el ) {
157- el . style . height = 'auto'
158- el . style . display = 'block'
159- el . style . height = getBCR ( el ) . height + 'px'
160- reflow ( el )
161157 this . transitioning = true
162- el . style . height = 0
163158 // This should be moved out so we can add cancellable events
164159 this . $emit ( 'hide' )
165160 } ,
166161 onAfterLeave ( el ) {
167- el . style . height = null
168162 this . transitioning = false
169163 this . $emit ( 'hidden' )
170164 } ,
171165 emitState ( ) {
172166 this . $emit ( 'input' , this . show )
173- // Let v-b-toggle know the state of this collapse
167+ // Let ` v-b-toggle` know the state of this collapse
174168 this . $root . $emit ( EVENT_STATE , this . safeId ( ) , this . show )
175169 if ( this . accordion && this . show ) {
176170 // Tell the other collapses in this accordion to close
@@ -184,13 +178,15 @@ export const BCollapse = /*#__PURE__*/ Vue.extend({
184178 this . $root . $emit ( EVENT_STATE_SYNC , this . safeId ( ) , this . show )
185179 } ,
186180 checkDisplayBlock ( ) {
187- // Check to see if the collapse has `display: block !important; ` set.
188- // We can't set `display: none; ` directly on this.$el, as it would
189- // trigger a new transition to start (or cancel a current one).
181+ // Check to see if the collapse has `display: block !important` set
182+ // We can't set `display: none` directly on ` this.$el` , as it would
183+ // trigger a new transition to start (or cancel a current one)
190184 const restore = hasClass ( this . $el , 'show' )
191185 removeClass ( this . $el , 'show' )
192186 const isBlock = getCS ( this . $el ) . display === 'block'
193- restore && addClass ( this . $el , 'show' )
187+ if ( restore ) {
188+ addClass ( this . $el , 'show' )
189+ }
194190 return isBlock
195191 } ,
196192 clickHandler ( evt ) {
@@ -202,7 +198,7 @@ export const BCollapse = /*#__PURE__*/ Vue.extend({
202198 }
203199 if ( matches ( el , '.nav-link,.dropdown-item' ) || closest ( '.nav-link,.dropdown-item' , el ) ) {
204200 if ( ! this . checkDisplayBlock ( ) ) {
205- // Only close the collapse if it is not forced to be ' display: block !important;'
201+ // Only close the collapse if it is not forced to be ` display: block !important`
206202 this . show = false
207203 }
208204 }
@@ -246,16 +242,9 @@ export const BCollapse = /*#__PURE__*/ Vue.extend({
246242 [ this . normalizeSlot ( 'default' ) ]
247243 )
248244 return h (
249- 'transition' ,
245+ BVCollapse ,
250246 {
251- props : {
252- enterClass : '' ,
253- enterActiveClass : 'collapsing' ,
254- enterToClass : '' ,
255- leaveClass : '' ,
256- leaveActiveClass : 'collapsing' ,
257- leaveToClass : ''
258- } ,
247+ props : { appear : this . appear } ,
259248 on : {
260249 enter : this . onEnter ,
261250 afterEnter : this . onAfterEnter ,
0 commit comments