Skip to content

Commit 8947bbc

Browse files
Merge pull request spatie#55 from matewiszt/add-utility-methods
Add comfortable utility methods to Tabs component
2 parents 3f108e4 + 1c25e5d commit 8947bbc

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/components/Tabs.vue

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
data: () => ({
4646
tabs: [],
4747
activeTabHash: '',
48+
activeTabIndex: 0,
4849
lastActiveTabHash: '',
4950
}),
5051
@@ -110,6 +111,9 @@
110111
111112
this.$emit('changed', { tab: selectedTab });
112113
114+
this.activeTabHash = selectedTab.hash;
115+
this.activeTabIndex = this.getTabIndex(selectedTabHash);
116+
113117
this.lastActiveTabHash = this.activeTabHash = selectedTab.hash;
114118
115119
expiringStorage.set(this.storageKey, selectedTab.hash, this.cacheLifetime);
@@ -139,6 +143,30 @@
139143
});
140144
}
141145
},
146+
147+
getTabIndex(hash){
148+
const tab = this.findTab(hash);
149+
150+
return this.tabs.indexOf(tab);
151+
},
152+
153+
getTabHash(index){
154+
const tab = this.tabs.find(tab => this.tabs.indexOf(tab) === index);
155+
156+
if (!tab) {
157+
return;
158+
}
159+
160+
return tab.hash;
161+
},
162+
163+
getActiveTab(){
164+
return this.findTab(this.activeTabHash);
165+
},
166+
167+
getActiveTabIndex() {
168+
return this.getTabIndex(this.activeTabHash);
169+
},
142170
},
143171
};
144172
</script>

0 commit comments

Comments
 (0)