Skip to content

Commit 1c25e5d

Browse files
Merge branch 'master' into add-utility-methods
2 parents 1e53642 + 3f108e4 commit 1c25e5d

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to `vue-tabs-component` will be documented in this file
44

5+
## 1.5.0 - 2018-06-06
6+
- Fixed bug #32 `changed` event fires twice on each change
7+
- Added `clicked` event, fires when active tab is clicked
8+
59
## 1.4.0 - 2017-11-06
610
- Added `isDisabled` prop to `Tab`
711

README.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# A Vue component to easily render tabs
1+
# A Vue component to easily render tabs
22

33
[![Latest Version on NPM](https://img.shields.io/npm/v/vue-tabs-component.svg?style=flat-square)](https://npmjs.com/package/vue-tabs-component)
44
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
@@ -8,10 +8,10 @@
88
The package contains a [Vue](https://vuejs.org/) component to easily display some tabs.
99

1010
This is how they can be used:
11-
11+
=
1212
```html
1313
<div>
14-
<tabs>
14+
<tabs :options="{ useUrlFragment: false }" @clicked="tabClicked" @changed="tabChanged">
1515
<tab name="First tab">
1616
This is the content of the first tab
1717
</tab>
@@ -122,6 +122,34 @@ When using with other libraries that use the url fragment, you can disable modif
122122
</tabs>
123123
```
124124

125+
### Callbacks
126+
Tabs has two events to which you can bind: `changed` and `clicked`
127+
128+
```html
129+
<tabs @clicked="tabClicked" @changed="tabChanged">
130+
...
131+
</tabs>
132+
```
133+
134+
```js
135+
export default {
136+
...
137+
methods: {
138+
...
139+
tabClicked (selectedTab) {
140+
console.log('Current tab re-clicked:' + selectedTab.tab.name);
141+
},
142+
tabChanged (selectedTab) {
143+
console.log('Tab changed to:' + selectedTab.tab.name);
144+
},
145+
...
146+
}
147+
}
148+
```
149+
150+
`changed` is emitted when the tab changes and can be used as handle to load data on request.
151+
`clicked` is emitted when an active tab is re-clicked and can be used to e.g. reload the data in the current tab.
152+
125153
### Adding a suffix and a prefix to the tab name
126154

127155
You can add a suffix and a prefix to the tab by using the `suffix` and `prefix` attributes.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-tabs-component",
3-
"version": "1.4.0",
3+
"version": "1.5.0",
44
"description": "A Vue component to easily render tabs",
55
"main": "dist/index.js",
66
"jsnext:main": "src/index.js",

src/components/Tabs.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
tabs: [],
4747
activeTabHash: '',
4848
activeTabIndex: 0,
49+
lastActiveTabHash: '',
4950
}),
5051
5152
computed: {
@@ -99,6 +100,11 @@
99100
return;
100101
}
101102
103+
if (this.lastActiveTabHash === selectedTab.hash) {
104+
this.$emit('clicked', { tab: selectedTab });
105+
return;
106+
}
107+
102108
this.tabs.forEach(tab => {
103109
tab.isActive = (tab.hash === selectedTab.hash);
104110
});
@@ -108,6 +114,8 @@
108114
this.activeTabHash = selectedTab.hash;
109115
this.activeTabIndex = this.getTabIndex(selectedTabHash);
110116
117+
this.lastActiveTabHash = this.activeTabHash = selectedTab.hash;
118+
111119
expiringStorage.set(this.storageKey, selectedTab.hash, this.cacheLifetime);
112120
},
113121

0 commit comments

Comments
 (0)