# A Vue component to easily render tabs
The package contains a Vue component to easily display some tabs.
This is how they can be used:
This is the content of the first tabThis is the content of the second tabThis content will be unavailable while :is-disabled prop set to trueThe fragment that is appended to the url can be customizedA prefix and a suffix can be added
When reloading the page the component will automatically display the tab that was previously opened.
The rendered output adheres to the ARIA specification.
You can see a demo here: http://vue-tabs-component.spatie.be
You can install the package via yarn:
yarn add vue-tabs-component
npm install vue-tabs-component --save
The most common use case is to register the component globally.
//in your app.js or similar file;;Vue;Vue;
Alternatively you can do this to register the components:
On your page you can now use html like this to render tabs:
First tab contentSecond tab contentThird tab content
By default it will show the first tab.
If you click on a tab a
href representation of the name will be append to the url. For example clicking on the tab
Second tab will append
#second-tab to the url.
When loading a page with a fragment that matches the
href of a tab, it will open up that tab. For example visiting
/#third-tab will open up the tab with name
Remembering the last opened tab
By default the component will remember which was the last open tab for 5 minutes . If you for instance click on
Third tab and then visit
/ the third tab will be opened.
You can change the cache life time by passing the lifetime in minutes in the
cache-lifetime property of the
Disable modifying the url fragment
When using with other libraries that use the url fragment, you can disable modifying the url fragment by passing the
useUrlFragment options. This helps using it with vue-router, or using vue-tabs-component twice in the same page.
Tabs has two events to which you can bind:
changed is emitted when the tab changes and can be used as handle to load data on request.
clicked is emitted when an active tab is re-clicked and can be used to e.g. reload the data in the current tab.
Adding a suffix and a prefix to the tab name
You can add a suffix and a prefix to the tab by using the
First tab content
The title of the tab will now be
my prefix - First tab - my suffix.
The fragment that's added to the url when clicking the tab will only be based on the
name of a tab, the
name-suffix attributes will be ignored.
When clicking on a tab it's name will be used as a fragment in the url. For example clicking on the
Second tab will append
#second-tab to the current url.
You can customize that fragment by using the
First tab content
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
First tab contentSecond tab content
You can use the CSS from the docs as a starting point for your own styling. The output HTML has namespaced classes to target all nodes directly.
Please see CHANGELOG for more information what has changed recently.
$ yarn test
Please see CONTRIBUTING for details.
If you discover any security related issues, please contact Freek Van der Herten instead of using the issue tracker.
You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.
Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.
We publish all received postcards on our company website.
Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.
Does your business depend on our contributions? Reach out and support us on Patreon. All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.
The MIT License (MIT). Please see License File for more information.