Skip to content

Commit bc7ca26

Browse files
authored
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
1 parent 26c8a3e commit bc7ca26

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

lib/components/tab.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
data() {
3030
return {
3131
fade: false,
32-
localActive: false,
32+
localActive: this.active,
3333
lazy: true,
3434
show: false
3535
};

lib/components/tabs.vue

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
},
8585
value: {
8686
type: Number,
87-
default: 0
87+
default: null
8888
},
8989
pills: {
9090
type: Boolean,
@@ -183,16 +183,17 @@
183183
return;
184184
}
185185
186-
// Deactivate any previous active tab(s)
186+
// Activate current tab, and deactivte any old tabs
187187
this.tabs.forEach( t => {
188-
if (t !== tab && t.localActive) {
189-
this.$set(t, 'localActive', false);
188+
if (t === tab) {
189+
// Set new tab as active
190+
this.$set(t, 'localActive', true);
191+
} else {
192+
// Ensure non current tabs are not active
193+
this.$set(tab, 'localActive', false);
190194
}
191195
});
192196
193-
// Set new tab as active
194-
this.$set(tab, 'localActive', true);
195-
196197
// Update currentTab
197198
this.currentTab = index + offset;
198199
},
@@ -218,17 +219,31 @@
218219
let tabIndex = this.currentTab;
219220
220221
if (tabIndex === null || tabIndex === undefined) {
221-
// Find last active tab in current tabs
222+
// Make null for easier testing further on
223+
tabIndex = null;
224+
}
225+
226+
if (tabIndex === null) {
227+
// Find last active non-dsabled tab in current tabs
228+
this.tabs.forEach((tab, index) => {
229+
if (tab.active && !tab.disabled) {
230+
tabIndex = index;
231+
}
232+
});
233+
}
234+
235+
if (tabIndex === null) {
236+
// Find first non-disabled tab in current tabs
222237
this.tabs.forEach((tab, index) => {
223-
if (tab.active) {
238+
if (!tab.disabled && tabIndex === null) {
224239
tabIndex = index;
225240
}
226241
});
227242
}
228243
229244
// Workaround to fix problem when currentTab is removed
230245
let offset = 0;
231-
if (tabIndex > this.tabs.length - 1) {
246+
if (tabIndex >= this.tabs.length) {
232247
offset = -1;
233248
}
234249

0 commit comments

Comments
 (0)