From 77ffb21fd6203054dd1e587db7d08a15d31e09ea Mon Sep 17 00:00:00 2001 From: fatse Date: Sat, 11 Jul 2020 22:46:40 -0700 Subject: [PATCH] Emit event when new tab is added. --- docs/README.md | 1 + src/components/VueTabs.js | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/README.md b/docs/README.md index e93e6a4..5a89f7b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -116,6 +116,7 @@ Event Name | Params ------------ | ------------- tab-change | tabIndex, newTab, oldTab input | tabTitle +tab-added | tabsLength ### tab-change example diff --git a/src/components/VueTabs.js b/src/components/VueTabs.js index d48c21c..084c8bf 100644 --- a/src/components/VueTabs.js +++ b/src/components/VueTabs.js @@ -87,6 +87,7 @@ export default { addTab (item) { const index = this.$slots.default.indexOf(item.$vnode); this.tabs.splice(index, 0, item); + this.$emit('tab-added', this.tabs.length); }, removeTab (item) { const tabs = this.tabs; @@ -104,9 +105,9 @@ export default { findTabAndActivate (tabNameOrIndex) { let indexToActivate = this.tabs.findIndex((tab, index) => tab.title === tabNameOrIndex || index === tabNameOrIndex) // if somehow activeTabIndex is not reflected in the actual vue-tab instance, set it. -+ if (indexToActivate === this.activeTabIndex && !this.tabs[this.activeTabIndex].active) { -+ this.tabs[this.activeTabIndex].active = true; -+ } + if (indexToActivate === this.activeTabIndex && !this.tabs[this.activeTabIndex].active) { + this.tabs[this.activeTabIndex].active = true; + } if (indexToActivate !== -1) { this.changeTab(this.activeTabIndex, indexToActivate) } else {