Skip to content

Commit

Permalink
Issue spatie#69: Allow setting default tab
Browse files Browse the repository at this point in the history
This adds the ability to set a defaultTabHash so that you can stop from
just arbitrarily displaying the first tab if nothing is selected.

This is especially useful when turning off caching

Tests passing, does not break functionality so bumping version in
changelog to 1.5.0
  • Loading branch information
Ben Roberts committed Jul 2, 2018
1 parent 88b969c commit 5022bbb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

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

## 1.5.0 - 2018-07-02
- Added `defaultTabHash` option

## 1.4.0 - 2017-11-06
- Added `isDisabled` prop to `Tab`

Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,22 @@ You can customize that fragment by using the `id` attribute.

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


### Setting a default tab

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.

```html
<tabs :options="{ defaultTabHash: 'second-tab' }">
<tab id="first-tab" name="First tab">
First tab content
</tab>
<tab id="second-tab" name="Default tab">
Second tab content
</tab>
</tabs>
```

### CSS

You can use the [CSS](docs/resources/tabs-component.css) from the docs as a starting point for your own styling.
Expand Down
6 changes: 6 additions & 0 deletions src/components/Tabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
required: false,
default: () => ({
useUrlFragment: true,
defaultTabHash: null,
}),
},
},
Expand Down Expand Up @@ -72,6 +73,11 @@
return;
}
if(this.options.defaultTabHash !== null && this.findTab("#" + this.options.defaultTabHash)) {
this.selectTab("#" + this.options.defaultTabHash);
return;
}
if (this.tabs.length) {
this.selectTab(this.tabs[0].hash);
}
Expand Down

0 comments on commit 5022bbb

Please sign in to comment.