1
1
import Vue from '../../utils/vue'
2
2
import KeyCodes from '../../utils/key-codes'
3
+ import observeDom from '../../utils/observe-dom'
3
4
import stableSort from '../../utils/stable-sort'
4
5
import { requestAF , selectAll } from '../../utils/dom'
5
6
import { arrayIncludes , concat } from '../../utils/array'
@@ -302,11 +303,14 @@ export const BTabs = /*#__PURE__*/ Vue.extend({
302
303
this . updateTabs ( )
303
304
} )
304
305
}
306
+ // Enable or disable the observer
307
+ this . setObserver ( newVal )
305
308
}
306
309
} ,
307
310
created ( ) {
308
311
let tabIdx = parseInt ( this . value , 10 )
309
312
this . currentTab = isNaN ( tabIdx ) ? - 1 : tabIdx
313
+ this . _bvObserver = null
310
314
// For SSR and to make sure only a single tab is shown on mount
311
315
// We wrap this in a `$nextTick()` to ensure the child tabs have been created
312
316
this . $nextTick ( ( ) => {
@@ -335,6 +339,9 @@ export const BTabs = /*#__PURE__*/ Vue.extend({
335
339
this . isMounted = true
336
340
} )
337
341
} ,
342
+ beforeDestroy ( ) {
343
+ this . isMounted = false
344
+ } ,
338
345
destroyed ( ) {
339
346
// Ensure no references to child instances exist
340
347
this . tabs = [ ]
@@ -351,6 +358,24 @@ export const BTabs = /*#__PURE__*/ Vue.extend({
351
358
unregisterTab ( tab ) {
352
359
this . registeredTabs = this . registeredTabs . slice ( ) . filter ( t => t !== tab )
353
360
} ,
361
+ setObserver ( on ) {
362
+ // DOM observer is needed to detect changes in order of tabs
363
+ if ( on ) {
364
+ // Make sure no existing observer running
365
+ this . setObserver ( false )
366
+ // Watch for changes to <b-tab> sub components
367
+ this . _bvObserver = observeDom ( this . $refs . tabsContainer , this . updateTabs . bind ( this ) , {
368
+ childList : true ,
369
+ subtree : false ,
370
+ attributes : false
371
+ } )
372
+ } else {
373
+ if ( this . _bvObserver && this . _bvObserver . disconnect ) {
374
+ this . _bvObserver . disconnect ( )
375
+ }
376
+ this . _bvObserver = null
377
+ }
378
+ } ,
354
379
getTabs ( ) {
355
380
// We use registeredTabs as the shouce of truth for child tab components. And we
356
381
// filter out any BTab components that are extended BTab with a root child BTab.
0 commit comments