Skip to content

Commit 2ced24b

Browse files
committed
fix: CTabs - unable posibility of undefined active tab
1 parent 04930e0 commit 2ced24b

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

src/components/tabs/CTab.vue

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,13 @@ const props = Object.assign(propsFactory(), {
3131
3232
export default {
3333
name: 'CTab',
34-
inject: ['distributed', 'tabs'],
34+
inject: ['distributed', 'tabs', 'initialTab'],
3535
components: {
3636
CLink
3737
},
3838
beforeMount () {
3939
this.index = Array.from(this.$parent.$children).indexOf(this)
40-
if (
41-
this.active && this.distributed.header
42-
&& typeof this.tabs.activeTab !== 'number'
43-
) {
40+
if (this.active && this.distributed.header && this.initialTab === undefined) {
4441
this.distributed.changeTabTo(this.index)
4542
}
4643
},

src/components/tabs/CTabs.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default {
3737
Object.defineProperty(tabs, 'fade', {
3838
get: () => this.fade
3939
})
40-
return { tabs }
40+
return { tabs, initialTab: this.activeTab }
4141
},
4242
props: {
4343
fill: Boolean,
@@ -61,12 +61,12 @@ export default {
6161
},
6262
data () {
6363
return {
64-
activeTabIndex: this.activeTab
64+
activeTabIndex: this.activeTab || 0
6565
}
6666
},
6767
watch: {
6868
activeTab (val) {
69-
this.activeTabIndex = val
69+
this.activeTabIndex = val || 0
7070
}
7171
},
7272
computed: {

src/components/tabs/tests/CTabs.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ describe(ComponentName, () => {
8787
activeTab: 1
8888
})
8989
expect(defaultWrapper.vm.activeTabIndex).toBe(1)
90+
defaultWrapper.setProps({
91+
activeTab: null
92+
})
93+
expect(defaultWrapper.vm.activeTabIndex).toBe(0)
9094
})
9195
it('properly changes vertical classes', () => {
9296
defaultWrapper.setProps({ vertical: true })

0 commit comments

Comments
 (0)