Simple toggle tabs.
Download Tabby / View the demo.
In This Documentation
- Getting Started
- Installing with Package Managers
- Options & Settings
- Browser Compatibility
- How to Contribute
- License
- Changelog
- Older Docs
Compiled and production-ready code can be found in the dist
directory. The src
directory contains development code. Unit tests are located in the test
directory.
<link rel="stylesheet" href="css/tabby.css">
<script src="js/classList.js"></script>
<script src="js/bind-polyfill.js"></script>
<script src="js/tabby.js"></script>
Tabby is built with Sass for easy customization. If you don't use Sass, that's ok. The css
folder contains compiled vanilla CSS.
Tabby follows the same coding conventions as Kraken, so you can drop the _tabby.css
file right into Kraken without making any updates. Or, adjust the variables to suit your own project.
Tabby also requires classList.js and bind-polyfill.js
, polyfills that extend ECMAScript 5 API support to more browsers.
Tab toggles can be buttons or links, and can optionally be wrapped in a list element. Make sure that the [data-tab]
value of each tab toggle matches the ID of the matching .tab-pane
.
Add the .active
class to the tab and content that you'd like displayed by default.
Standalone Buttons
<div class="tabs">
<button class="active" data-tab="#tab1">Superheroes</button>
<button data-tab="#tab2">Ice Cream</button>
<button data-tab="#tab3">Seasons</button>
</div>
<div class="tabs-content">
<div class="tabs-pane active" id="tab1">
Superheros
...
</div>
<div class="tabs-pane" id="tab2">
Ice Cream
...
</div>
<div class="tabs-pane" id="tab3">
Seasons
...
</div>
</div>
List Links
<ul class="tabs">
<li class="active"><a data-tab="#tab1" href="#">Superheroes</a></li>
<li><a data-tab="#tab2" href="#">Ice Cream</a></li>
<li><a data-tab="#tab3" href="#">Seasons</a></li>
</ul>
<div class="tabs-content">
<div class="tabs-pane active" id="tab1">
Superheros
...
</div>
...
</div>
<script>
tabby.init();
</script>
In the footer of your page, after the content, initialize Tabby. And that's it, you're done. Nice work!
You can install Tabby with your favorite package manager.
- NPM:
npm install cferdinandi/tabby
- Bower:
bower install https://github.com/cferdinandi/tabby.git
- Component:
component install cferdinandi/tabby
Tabby ships without any default styles, so you can adapt it to whatever project you're working on. For responsive navigation patterns, you might use Tabby with Astro.
If you need something with styling, check out Tabby 3.
Tabby includes smart defaults and works right out of the box. But if you want to customize things, it also has a robust API that provides multiple ways for you to adjust the default options and settings.
You can pass options and callbacks into Tabby through the init()
function:
tabby.init({
toggleActiveClass: 'active', // Class added to active toggle elements
contentActiveClass: 'active', // Class added to active tab content areas
initClass: 'js-tabby', // Class added to <html> element when initiated
callbackBefore: function ( toggle, tabID ) {}, // Function that's run before tab content is toggled
callbackAfter: function ( toggle, tabID ) {} // Function that's run after tab content is toggled
});
You can also call Tabby toggle event in your own scripts.
Show tab content.
tabby.toggleTab(
toggle, // Node that toggles the tab action. ex. document.querySelector('#toggle')
tabID, // The ID of the tab content area to show. ex. '#content'
options, // Classes and callbacks. Same options as those passed into the init() function.
event // Optional, if a DOM event was triggered.
);
Example
var toggle = document.querySelector('[data-tab="#tab2"]');
tabby.toggleTab( toggle, '#tab2' );
Destroy the current tabby.init()
.
tabby.destroy();
Tabby works in all modern browsers, and IE 9 and above.
Tabby is built with modern JavaScript APIs, and uses progressive enhancement. If the JavaScript file fails to load, or if your site is viewed on older and less capable browsers, all content will be displayed by default. If you need to support older browsers, you can still download the jQuery version of Tabby on GitHub.
In lieu of a formal style guide, take care to maintain the existing coding style. Don't forget to update the version number, the changelog (in the readme.md
file), and when applicable, the documentation.
Tabby is licensed under the MIT License.
Tabby uses semantic versioning.
- v7.4.1 - August 31, 2014
- Fixed event listener filter to account for sub elements.
- v7.4.0 - August 23, 2014
- Converted to Ruby Sass.
- Updated unit test path.
- Switched to event bubbling.
- v7.3.2 - August 15, 2014
- Added fix for UMD structure.
- v7.3.1 - August 8, 2014
- Added polyfill for
Functions.prototype.bind
. - Removed Sass paths from
gulpfile.js
.
- Added polyfill for
- v7.3.0 - June 27, 2014
- Updated unit tests.
- Added
destroy()
method. - Fixed a bug that wasn't removing the
.active
class fromli
links.
- v7.2.0 - June 20, 2014
- Converted to gulp.js workflow.
- Added unit testing.
- Updated naming conventions.
- Removed unused
_config.scss
and_mixins.scss
files. - Added minified versions of files.
- v7.1.1 - June 19, 2014
- Fixed factory/root/UMD definition.
- v7.1.1 - June 8, 2014
- Added UMD support.
- Moved public APIs to exports variable.
- Improved feature test.
- Replaced
Array.prototype.forEach
hack with properforEach
function. - Added a more well supported
trim
function. - General code optimizations for better minification and performance.
- Updated to JSDoc documentation.
- Updated to three number versioning system.
- Added package manager installation info.
- v7.0 - April 4, 2014
- Converted from Buoy class helpers to
classList
with polyfill.
- Converted from Buoy class helpers to
- v6.2 - March 18, 2014
- Pass
toggle
andtabID
variables into callbacks. - Run a check for
active
class before running_stopVideos
function to avoid unneccessary reloading ofsrc
. - Checks if toggle is part of a list before crawling up DOM tree to avoid unneccessary class setting.
- Pass
- v6.1 - February 27, 2014
- Converted
_defaults
to a literal object
- Converted
- v6.0 - February 24, 2014
- Better public/private method namespacing.
- Require
init()
call to run. - New API exposes additional methods for use in your own scripts.
- Better documentation.
- v5.3 - February 16, 2014
- v5.2 - February 5, 2014
- Reverted to
Array.prototype.forEach
loops.
- Reverted to
- v5.1 - January 27, 2014
- Updated addEventListener to be more object oriented.
- Moved feature test to script itself.
- v5.0 - January 27, 2014
- Switched to a data attribute for the toggle selector (separates scripts from styles).
- Removed unused
tab-toggle
class. - Prefixed script with a
;
to prevent errors if other scripts are incorrectly closed. - Added namespacing to IIFE.
- v4.0 - December 4, 2013
- Added Sass support.
- Removed horizontal and vertical styling for great design flexibility.
- Add active class to button elements.
- v3.2 - August 27, 2013
- Added missing semicolon.
- Activated strict mode.
- v3.1 - August 26,2013
- Converted to an IIFE pattern.
- Added Buoy vanilla JS micro-library.
- v3.0 - August 13, 2013
- Converted to vanilla JS.
- Removed dependence on jQuery.
- v2.1 - August 5, 2013
- Updated with variable for
$(this)
(better performance).
- Updated with variable for
- v2.0 - June 7, 2013
- Switched to MIT license.
- v2.0 - June 5, 2013
- Switched from
href
todata-target
value for tab id, breaking backward compatibility.
- Switched from
- v1.1 - February 13, 2013
- Renamed
example.html
toindex.html
.
- Renamed
- v1.1 - February 5, 2013
- Switched to relative sizing.
- v1.0 - January 22, 2013
- Initial release.