Skip to content

Commit 12a2f2c

Browse files
author
cristian.jora
committed
#17 Fix repeated tab-change events
1 parent 5cbc696 commit 12a2f2c

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

dev/App.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<template>
22
<div>
3-
<vue-tabs class="card" @on-error="handleError"
3+
<vue-tabs class="card"
4+
@tab-change="handleTabChange"
5+
@on-error="handleError"
46
v-model="tabName">
57
<v-tab v-for="(tab, index) in tabList"
68
:key="tab.name"
@@ -28,6 +30,9 @@
2830
handleError(error){
2931
this.error = error
3032
},
33+
handleTabChange(tabIndex, newTab, oldTab){
34+
console.log(tabIndex, newTab.title, oldTab.title)
35+
},
3136
goToSecondTab(){
3237
this.tabName='name2'
3338
}

src/components/VueTabs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ export default{
100100
},
101101
findTabAndActivate (tabNameOrIndex) {
102102
let indexToActivate = this.tabs.findIndex((tab, index) => tab.title === tabNameOrIndex || index === tabNameOrIndex)
103-
if (indexToActivate != -1) {
103+
if (indexToActivate === this.activeTabIndex) return
104+
if (indexToActivate !== -1) {
104105
this.changeTab(this.activeTabIndex, indexToActivate)
105106
} else {
106107
this.changeTab(this.activeTabIndex, 0)
@@ -139,7 +140,6 @@ export default{
139140
this.renderTabTitle(index, this.textPosition)
140141
}
141142
<a href="javascript:void(0)"
142-
onClick={() => this.navigateToTab(index)}
143143
style={active ? this.activeTabStyle : {}}
144144
class={{'active_tab': active}}
145145
aria-selected={active}

0 commit comments

Comments
 (0)