1
- export default {
1
+ export default {
2
2
name : 'vue-tabs' ,
3
3
props : {
4
4
activeTabColor : String ,
5
5
activeTextColor : String ,
6
+ disabledColor : String ,
7
+ disabledTextColor : String ,
6
8
/**
7
9
* Tab title position: center | bottom | top
8
10
*/
@@ -67,10 +69,11 @@ export default{
67
69
this . $emit ( 'input' , tab . title )
68
70
} ,
69
71
changeTab ( oldIndex , newIndex , route ) {
70
- this . activeTabIndex = newIndex
71
72
let oldTab = this . tabs [ oldIndex ]
72
73
let newTab = this . tabs [ newIndex ]
73
- oldTab . active = false
74
+ if ( newTab . disabled ) return ;
75
+ this . activeTabIndex = newIndex
76
+ oldTab . active = false
74
77
newTab . active = true
75
78
this . $emit ( 'input' , this . tabs [ newIndex ] . title )
76
79
this . $emit ( 'tab-change' , newIndex , newTab , oldTab )
@@ -81,11 +84,11 @@ export default{
81
84
this . $router . push ( route )
82
85
}
83
86
} ,
84
- addTab ( item ) {
87
+ addTab ( item ) {
85
88
const index = this . $slots . default . indexOf ( item . $vnode ) ;
86
89
this . tabs . splice ( index , 0 , item ) ;
87
90
} ,
88
- removeTab ( item ) {
91
+ removeTab ( item ) {
89
92
const tabs = this . tabs ;
90
93
const index = tabs . indexOf ( item ) ;
91
94
if ( index > - 1 ) {
@@ -127,27 +130,37 @@ export default{
127
130
let simpleIcon = < i class = { icon } > </ i >
128
131
if ( ! tab . $slots . title && icon ) return simpleIcon
129
132
} ,
133
+ tabStyles ( tab ) {
134
+ if ( tab . disabled ) {
135
+ return {
136
+ backgroundColor : this . disabledColor ,
137
+ color : this . disabledTextColor
138
+ }
139
+ }
140
+ return { }
141
+ } ,
130
142
renderTabs ( ) {
131
143
return this . tabs . map ( ( tab , index ) => {
132
144
if ( ! tab ) return
133
145
let { route, id, title, icon} = tab
134
146
let active = this . activeTabIndex === index
135
147
return (
136
- < li name = "tab" onClick = { ( ) => this . navigateToTab ( index , route ) } class = { [ 'tab' , { active : active } ] }
148
+ < li name = "tab" onClick = { ( ) => ! tab . disabled && this . navigateToTab ( index , route ) }
149
+ class = { [ 'tab' , { active : active } , { disabled : tab . disabled } ] }
137
150
key = { title }
138
151
role = "presentation" >
139
152
{ this . textPosition === 'top' &&
140
153
this . renderTabTitle ( index , this . textPosition )
141
154
}
142
155
< a href = "javascript:void(0)"
143
- style = { active ? this . activeTabStyle : { } }
156
+ style = { active ? this . activeTabStyle : this . tabStyles ( tab ) }
144
157
class = { { 'active_tab' : active } }
145
158
aria-selected = { active }
146
159
aria-controls = { `#${ id } ` }
147
160
role = "tab" >
148
- { this . textPosition !== 'center' && ! tab . $slots . title && this . renderIcon ( index ) }
161
+ { this . textPosition !== 'center' && ! tab . $slots . title && this . renderIcon ( index ) }
149
162
{ this . textPosition === 'center' &&
150
- this . renderTabTitle ( index , this . textPosition )
163
+ this . renderTabTitle ( index , this . textPosition )
151
164
}
152
165
</ a >
153
166
{ this . textPosition === 'bottom' &&
@@ -161,15 +174,15 @@ export default{
161
174
render ( ) {
162
175
const tabList = this . renderTabs ( )
163
176
return (
164
- < div class = { [ 'vue-tabs' , this . stackedClass ] } >
165
- < div class = { [ { 'nav-tabs-navigation' : ! this . isStacked } , { 'left-vertical-tabs' : this . isStacked } ] } >
177
+ < div class = { [ 'vue-tabs' , this . stackedClass ] } >
178
+ < div class = { [ { 'nav-tabs-navigation' : ! this . isStacked } , { 'left-vertical-tabs' : this . isStacked } ] } >
166
179
< div class = { [ 'nav-tabs-wrapper' , this . stackedClass ] } >
167
180
< ul class = { this . classList } role = "tablist" >
168
181
{ tabList }
169
182
</ ul >
170
183
</ div >
171
184
</ div >
172
- < div class = { [ 'tab-content' , { 'right-text-tabs' : this . isStacked } ] } >
185
+ < div class = { [ 'tab-content' , { 'right-text-tabs' : this . isStacked } ] } >
173
186
{ this . $slots . default }
174
187
</ div >
175
188
</ div > )
0 commit comments