Skip to content

Commit d2f1f41

Browse files
author
cristian.jora
committed
#18 Support disabled tabs
1 parent 63133cf commit d2f1f41

File tree

4 files changed

+38
-712
lines changed

4 files changed

+38
-712
lines changed

src/components/VTab.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default{
2020
route: {
2121
type: [String, Object]
2222
},
23+
disabled: Boolean,
2324
transitionName: String,
2425
transitionMode: String
2526
},

src/components/VueTabs.js

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
export default{
1+
export default {
22
name: 'vue-tabs',
33
props: {
44
activeTabColor: String,
55
activeTextColor: String,
6+
disabledColor: String,
7+
disabledTextColor: String,
68
/**
79
* Tab title position: center | bottom | top
810
*/
@@ -67,10 +69,11 @@ export default{
6769
this.$emit('input', tab.title)
6870
},
6971
changeTab (oldIndex, newIndex, route) {
70-
this.activeTabIndex = newIndex
7172
let oldTab = this.tabs[oldIndex]
7273
let newTab = this.tabs[newIndex]
73-
oldTab.active =false
74+
if (newTab.disabled) return;
75+
this.activeTabIndex = newIndex
76+
oldTab.active = false
7477
newTab.active = true
7578
this.$emit('input', this.tabs[newIndex].title)
7679
this.$emit('tab-change', newIndex, newTab, oldTab)
@@ -81,11 +84,11 @@ export default{
8184
this.$router.push(route)
8285
}
8386
},
84-
addTab(item) {
87+
addTab (item) {
8588
const index = this.$slots.default.indexOf(item.$vnode);
8689
this.tabs.splice(index, 0, item);
8790
},
88-
removeTab(item) {
91+
removeTab (item) {
8992
const tabs = this.tabs;
9093
const index = tabs.indexOf(item);
9194
if (index > -1) {
@@ -127,27 +130,37 @@ export default{
127130
let simpleIcon = <i class={icon}>&nbsp;</i>
128131
if (!tab.$slots.title && icon) return simpleIcon
129132
},
133+
tabStyles (tab) {
134+
if (tab.disabled) {
135+
return {
136+
backgroundColor: this.disabledColor,
137+
color: this.disabledTextColor
138+
}
139+
}
140+
return {}
141+
},
130142
renderTabs () {
131143
return this.tabs.map((tab, index) => {
132144
if (!tab) return
133145
let {route, id, title, icon} = tab
134146
let active = this.activeTabIndex === index
135147
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}]}
137150
key={title}
138151
role="presentation">
139152
{this.textPosition === 'top' &&
140153
this.renderTabTitle(index, this.textPosition)
141154
}
142155
<a href="javascript:void(0)"
143-
style={active ? this.activeTabStyle : {}}
156+
style={active ? this.activeTabStyle : this.tabStyles(tab)}
144157
class={{'active_tab': active}}
145158
aria-selected={active}
146159
aria-controls={`#${id}`}
147160
role="tab">
148-
{this.textPosition !=='center' && !tab.$slots.title && this.renderIcon(index)}
161+
{this.textPosition !== 'center' && !tab.$slots.title && this.renderIcon(index)}
149162
{this.textPosition === 'center' &&
150-
this.renderTabTitle(index, this.textPosition)
163+
this.renderTabTitle(index, this.textPosition)
151164
}
152165
</a>
153166
{this.textPosition === 'bottom' &&
@@ -161,15 +174,15 @@ export default{
161174
render () {
162175
const tabList = this.renderTabs()
163176
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}]}>
166179
<div class={['nav-tabs-wrapper', this.stackedClass]}>
167180
<ul class={this.classList} role="tablist">
168181
{tabList}
169182
</ul>
170183
</div>
171184
</div>
172-
<div class={['tab-content',{'right-text-tabs': this.isStacked } ]}>
185+
<div class={['tab-content', {'right-text-tabs': this.isStacked}]}>
173186
{this.$slots.default}
174187
</div>
175188
</div>)

themes/default/_bs_nav_tabs.scss

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,19 @@ $title-color: #f3f2ee;
3838
}
3939

4040
// Disabled state sets text to gray and nukes hover/tab effects
41-
&.disabled > a {
42-
color: $nav-disabled-link-color;
43-
44-
&:hover,
45-
&:focus {
46-
color: $nav-disabled-link-hover-color;
47-
text-decoration: none;
48-
background-color: transparent;
49-
cursor: $cursor-disabled;
41+
&.disabled {
42+
> a{
43+
color: $nav-disabled-link-color;
44+
&:hover,
45+
&:focus {
46+
color: $nav-disabled-link-hover-color;
47+
text-decoration: none;
48+
cursor: $cursor-disabled;
49+
background-color: transparent;
50+
border-color: transparent;
51+
}
5052
}
53+
5154
}
5255
}
5356

0 commit comments

Comments
 (0)