Skip to content

Commit 0e838f9

Browse files
Merge pull request spatie#70 from dissolve/69-default-tab
Issue spatie#69: Allow setting default tab
2 parents e2aad1e + 3ece2ba commit 0e838f9

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

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

5-
## 1.5.0 - 2018-06-06
5+
## 1.5.0 - 2018-XX-XX
6+
- Added `defaultTabHash` option
67
- Fixed bug #32 `changed` event fires twice on each change
78
- Added `clicked` event, fires when active tab is clicked
89

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,22 @@ You can customize that fragment by using the `id` attribute.
182182

183183
Clicking on `My tab` will then append `#custom-fragment` to the url.
184184

185+
186+
### Setting a default tab
187+
188+
When disabling the cache, it can be useful to specify a default tab to load which is not the first one. You can select this by passing the `defaultTabHash` option.
189+
190+
```html
191+
<tabs :options="{ defaultTabHash: 'second-tab' }">
192+
<tab id="first-tab" name="First tab">
193+
First tab content
194+
</tab>
195+
<tab id="second-tab" name="Default tab">
196+
Second tab content
197+
</tab>
198+
</tabs>
199+
```
200+
185201
### CSS
186202

187203
You can use the [CSS](docs/resources/tabs-component.css) from the docs as a starting point for your own styling.

src/components/Tabs.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
required: false,
3939
default: () => ({
4040
useUrlFragment: true,
41+
defaultTabHash: null,
4142
}),
4243
},
4344
},
@@ -74,6 +75,11 @@
7475
return;
7576
}
7677
78+
if(this.options.defaultTabHash !== null && this.findTab("#" + this.options.defaultTabHash)) {
79+
this.selectTab("#" + this.options.defaultTabHash);
80+
return;
81+
}
82+
7783
if (this.tabs.length) {
7884
this.selectTab(this.tabs[0].hash);
7985
}

0 commit comments

Comments
 (0)