Skip to content

Commit 8aeb9e9

Browse files
authored
fix(b-tabs): cleanup rendering logic (#6154)
* fix(b-tabs): tabs detection for SSR * Update tab.js * Update tabs.js * testing * Update safe-types.js * Update dom.js * Update tabs.js * Update tabs.js * Update tabs.js * Update tabs.js * Update tabs.js * fix(b-tabs): improve rendering logic * Update tabs.js * Update tabs.js * Update tab.js * Update tabs.js * Update tabs.js
1 parent 5cb8e0c commit 8aeb9e9

File tree

7 files changed

+196
-288
lines changed

7 files changed

+196
-288
lines changed

src/components/tabs/tab.js

+12-15
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,14 @@ export const BTab = /*#__PURE__*/ Vue.extend({
5454
props,
5555
data() {
5656
return {
57-
localActive: this[MODEL_PROP_NAME_ACTIVE] && !this.disabled,
58-
show: false
57+
localActive: this[MODEL_PROP_NAME_ACTIVE] && !this.disabled
5958
}
6059
},
6160
computed: {
61+
// For parent sniffing of child
62+
_isTab() {
63+
return true
64+
},
6265
tabClasses() {
6366
const { localActive: active, disabled } = this
6467

@@ -80,17 +83,9 @@ export const BTab = /*#__PURE__*/ Vue.extend({
8083
},
8184
computedLazy() {
8285
return this.bvTabs.lazy || this.lazy
83-
},
84-
// For parent sniffing of child
85-
_isTab() {
86-
return true
8786
}
8887
},
8988
watch: {
90-
localActive(newValue) {
91-
// Make `active` prop work with `.sync` modifier
92-
this.$emit(MODEL_EVENT_NAME_ACTIVE, newValue)
93-
},
9489
[MODEL_PROP_NAME_ACTIVE](newValue, oldValue) {
9590
if (newValue !== oldValue) {
9691
if (newValue) {
@@ -114,13 +109,15 @@ export const BTab = /*#__PURE__*/ Vue.extend({
114109
firstTab()
115110
}
116111
}
112+
},
113+
localActive(newValue) {
114+
// Make `active` prop work with `.sync` modifier
115+
this.$emit(MODEL_EVENT_NAME_ACTIVE, newValue)
117116
}
118117
},
119118
mounted() {
120-
// Inform b-tabs of our presence
119+
// Inform `<b-tabs>` of our presence
121120
this.registerTab()
122-
// Initially show on mount if active and not disabled
123-
this.show = this.localActive
124121
},
125122
updated() {
126123
// Force the tab button content to update (since slots are not reactive)
@@ -130,8 +127,8 @@ export const BTab = /*#__PURE__*/ Vue.extend({
130127
updateButton(this)
131128
}
132129
},
133-
destroyed() {
134-
// inform b-tabs of our departure
130+
beforeDestroy() {
131+
// Inform `<b-tabs>` of our departure
135132
this.unregisterTab()
136133
},
137134
methods: {

src/components/tabs/tab.spec.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { mount } from '@vue/test-utils'
2-
import { waitNT, waitRAF } from '../../../tests/utils'
2+
import { waitNT } from '../../../tests/utils'
33
import { BTab } from './tab'
44

55
describe('tab', () => {
@@ -31,7 +31,6 @@ describe('tab', () => {
3131

3232
expect(wrapper.vm._isTab).toBe(true)
3333
expect(wrapper.vm.localActive).toBe(false)
34-
expect(wrapper.vm.show).toBe(false)
3534

3635
wrapper.destroy()
3736
})
@@ -86,15 +85,13 @@ describe('tab', () => {
8685

8786
await wrapper.setData({ localActive: true })
8887
await waitNT(wrapper.vm)
89-
await waitRAF()
9088

9189
expect(wrapper.classes()).toContain('active')
9290
expect(wrapper.classes()).not.toContain('disabled')
9391
expect(wrapper.classes()).not.toContain('card-body')
9492

9593
await wrapper.setData({ localActive: false })
9694
await waitNT(wrapper.vm)
97-
await waitRAF()
9895

9996
expect(wrapper.classes()).not.toContain('active')
10097
expect(wrapper.classes()).not.toContain('disabled')

0 commit comments

Comments
 (0)