Skip to content

Commit 461ab6c

Browse files
committed
Still trying to fix tab handling
1 parent b290bc5 commit 461ab6c

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/components/Tabs.vue

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div class="tabs" :id="id">
2+
<div :class="{tabs: true, hide: !hasEnabledTabs} " :id="id">
33
<div class="tabsHeader">
44
<button type="button" v-show="tab.enabled" :class="{'tabItem': true, 'tabActive': tab.active }" @click="selectTab(tab)" v-for="tab in tabs" :key="tab.id">
55
<i :class="['fas', tab.icon]"></i> {{ tab.name }}
@@ -25,11 +25,16 @@ export default {
2525
tabs: []
2626
};
2727
},
28-
created() {
29-
this.tabs = this.$children;
30-
},
3128
mounted() {
32-
this.resetActiveTab();
29+
if (Array.isArray(this.$children)) {
30+
this.tabs = this.$children;
31+
this.resetActiveTab();
32+
}
33+
},
34+
computed: {
35+
hasEnabledTabs() {
36+
return this.tabs.filter(t => t.enabled).length > 0;
37+
}
3338
},
3439
methods: {
3540
getTab(id) {
@@ -61,10 +66,14 @@ export default {
6166
// Get tab by id
6267
selectedTab = this.getTab(selectedTab);
6368
}
64-
if (!selectedTab || activeTab === selectedTab) {
69+
if (activeTab === selectedTab) {
6570
return;
6671
}
67-
if (selectedTab !== null && await selectedTab.show() && activeTab !== null) {
72+
if (!selectedTab || typeof selectedTab.show !== 'function') {
73+
console.error("Invalid tab", selectedTab);
74+
return;
75+
}
76+
if (await selectedTab.show() && activeTab !== null) {
6877
activeTab.hide();
6978
}
7079
},
@@ -92,6 +101,9 @@ export default {
92101
border: 1px solid #aaa;
93102
margin-bottom: 10px;
94103
}
104+
.tabs.hide {
105+
display: none;
106+
}
95107
#viewer .tabs {
96108
height: 97%;
97109
}

0 commit comments

Comments
 (0)