Permalink
Browse files

fix(tabs): Default current tab to null (issue #687) (#701)

* fix(tab): Set localActive to initial active state

* fix(tabs): Default currentTab to null
value defaulted to 0, which prevented tab with `active` state from being shown
  • Loading branch information...
tmorehouse committed Jul 16, 2017
1 parent 26c8a3e commit bc7ca26a71316b17d537b6b69d6dc58542f6d7f9
Showing with 26 additions and 11 deletions.
  1. +1 −1 lib/components/tab.vue
  2. +25 −10 lib/components/tabs.vue
@@ -29,7 +29,7 @@
data() {
return {
fade: false,
localActive: false,
localActive: this.active,
lazy: true,
show: false
};
@@ -84,7 +84,7 @@
},
value: {
type: Number,
default: 0
default: null
},
pills: {
type: Boolean,
@@ -183,16 +183,17 @@
return;
}
// Deactivate any previous active tab(s)
// Activate current tab, and deactivte any old tabs
this.tabs.forEach( t => {
if (t !== tab && t.localActive) {
this.$set(t, 'localActive', false);
if (t === tab) {
// Set new tab as active
this.$set(t, 'localActive', true);
} else {
// Ensure non current tabs are not active
this.$set(tab, 'localActive', false);
}
});
// Set new tab as active
this.$set(tab, 'localActive', true);
// Update currentTab
this.currentTab = index + offset;
},
@@ -218,17 +219,31 @@
let tabIndex = this.currentTab;
if (tabIndex === null || tabIndex === undefined) {
// Find last active tab in current tabs
// Make null for easier testing further on
tabIndex = null;
}
if (tabIndex === null) {
// Find last active non-dsabled tab in current tabs
this.tabs.forEach((tab, index) => {
if (tab.active && !tab.disabled) {
tabIndex = index;
}
});
}
if (tabIndex === null) {
// Find first non-disabled tab in current tabs
this.tabs.forEach((tab, index) => {
if (tab.active) {
if (!tab.disabled && tabIndex === null) {
tabIndex = index;
}
});
}
// Workaround to fix problem when currentTab is removed
let offset = 0;
if (tabIndex > this.tabs.length - 1) {
if (tabIndex >= this.tabs.length) {
offset = -1;
}

0 comments on commit bc7ca26

Please sign in to comment.