All Projects → jenstornell → tabbis.js

jenstornell / tabbis.js

Licence: MIT License
Pure vanilla javascript tabs with nesting

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to tabbis.js

Tabby
Lightweight, accessible vanilla JS toggle tabs.
Stars: ✭ 449 (+920.45%)
Mutual labels:  tabs, vanilla-js, no-dependencies
Mailtoui
A simple way to enhance your mailto links with a convenient user interface.
Stars: ✭ 162 (+268.18%)
Mutual labels:  vanilla-javascript, vanilla-js, no-dependencies
Medium Zoom
🔎🖼 A JavaScript library for zooming images like Medium
Stars: ✭ 2,799 (+6261.36%)
Mutual labels:  vanilla-javascript, no-dependencies
js-plugin-starter-kit
VanillaJS (pure JavaScript) plugin starter with Webpack 4 and Babel 7.
Stars: ✭ 100 (+127.27%)
Mutual labels:  vanilla-javascript, vanilla-js
form-saver
A simple script that lets users save and reuse form data.
Stars: ✭ 67 (+52.27%)
Mutual labels:  vanilla-js, no-dependencies
vanilla-js-drawer
A dependency-free Vanilla JS drawer. No dependencies, no automation build tools.
Stars: ✭ 20 (-54.55%)
Mutual labels:  vanilla-javascript, vanilla-js
Bs Custom File Input
A little plugin for Bootstrap 4 custom file input
Stars: ✭ 162 (+268.18%)
Mutual labels:  vanilla-javascript, vanilla-js
coding challenge-14
Understanding JavaScript and coding without the help of a library or tool
Stars: ✭ 22 (-50%)
Mutual labels:  vanilla-javascript, vanilla-js
Rallax.js
Dead simple parallax scrolling.
Stars: ✭ 1,441 (+3175%)
Mutual labels:  vanilla-javascript, vanilla-js
event-driven-web-components-realworld-example-app
Exemplary real world application built with Vanilla JS Web Components in an Event Driven Architecture
Stars: ✭ 55 (+25%)
Mutual labels:  vanilla-javascript, vanilla-js
eins-modal
Simple to use modal / alert / dialog / popup. Created with pure JS. No javascript knowledge required! Works on every browser and device! IE9
Stars: ✭ 30 (-31.82%)
Mutual labels:  vanilla-javascript, vanilla-js
mm-components
Music Markups components
Stars: ✭ 50 (+13.64%)
Mutual labels:  vanilla-javascript, vanilla-js
bs-breakpoints
A plugin which detect Bootstrap 4 breakpoints and emit when there is a change
Stars: ✭ 22 (-50%)
Mutual labels:  vanilla-javascript, vanilla-js
Long Press Event
Adds `long-press` event to the DOM in 1k of pure JavaScript
Stars: ✭ 187 (+325%)
Mutual labels:  vanilla-javascript, no-dependencies
Vanillajs Deck
A Vanilla.js Single Page App (SPA) slide deck for a presentation about Vanilla.js written with no frameworks.
Stars: ✭ 119 (+170.45%)
Mutual labels:  vanilla-javascript, vanilla-js
curved-menu
VanillaJS fully configurable curved menu (circular navigation)
Stars: ✭ 30 (-31.82%)
Mutual labels:  vanilla-javascript, vanilla-js
periodic-table.io
periodic-table.io
Stars: ✭ 37 (-15.91%)
Mutual labels:  vanilla-javascript, vanilla-js
Vanilla Semantic Ui
Semantic UI component framework without jQuery
Stars: ✭ 97 (+120.45%)
Mutual labels:  vanilla-javascript, vanilla-js
Router.js
Router.js is a simple and powerful javascript library to handle routing
Stars: ✭ 107 (+143.18%)
Mutual labels:  vanilla-javascript, vanilla-js
tensorflowjs-remove-background
Remove Background from the picture using WebAssembly & TensorFlow.js
Stars: ✭ 79 (+79.55%)
Mutual labels:  vanilla-javascript, vanilla-js

Tabbis

Version 3.0 - See the Changelog or version 1.

If you like Tabbis, please consider making a donation to support my work.

Tabbis

About

Really simple tabs with pure vanilla javascript, no jQuery involved. It's just 3.3 kB minified and 1.2 kB gzipped.

  • Supports old and new browsers - Has both ES5 and ES6 versions
  • Supports unlimited nesting
  • Supports keyboard navigation
  • Supports accessability with automatic aria tags
  • Supports options
  • Supports custom events
  • Supports memory using local storage (needs to be enabled in the options)

Demos

Setup

Instead of going step by step, I give you a full example.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>Tabbis</title>
    <link rel="stylesheet" href="../assets/css/dist/style-default.css">
  </head>
  <body>
    <div data-tabs>
      <button>Tab1</button>
      <button>Tab2</button>
      <button>Tab3</button>
    </div>

    <div data-panes>
      <div>Pane1</div>
      <div>Pane2</div>
      <div>Pane3</div>
    </div>

    <script src="../assets/js/dist/tabbis.es5.min.js"></script>
    <script>tabbis();</script>
  </body>
</html>

For more see the more advanced examples.

Options

The function call below will not change anything compared to tabbis(), because every option is set to its default value.

tabbis({
  keyboardNavigation: true,
  memory: false,
  paneGroup: '[data-pane]',
  prefix: '',
  tabActive: '[data-active]',
  tabActiveFallback: 0,
  tabGroup: '[data-tabs]',
  trigger: 'click'
});
Option Default Description
keyboardNavigation true Enable or disable keyboard navigation
memory false The local storage name. To disable memory you can set it to false. If you set true it will use tabbis as storage name
paneGroup '[data-pane]' A selector for Tabbis to know where your panes are located.
prefix '' By default Tabbis adds ids to the tabs and panes like tab-0-0 and pane-0-0. In case of collision you can add a prefix.
tabActive '[data-active]' You can add data-active to the tab that you want to be active on first load.
tabActiveFallback 0 If no tab is selected on load it will fall back to the first tab. To not select any tab on load set this to false
tabGroup '[data-tabs]' A selector to know where your tabs are located.
trigger click Change the tab trigger event to something like mouseover

Custom event

Instead of a callback, Tabbis uses a custom event that is emitted when a tab is activated.

document.addEventListener("tabbis", e => {
    let data = e.detail;
    console.log(data.tab);
    console.log(data.pane);
}, false );

Keyboard navigation

Tabbis supports keyboard navigation.

  • Arrow keys (left/right, up/down) will activate the next or previous tab to the current activated tab.
  • Tab (left/right) will jump from the active tab to the related pane or the other way around.

Memory

To make the browser remember your tab state after a page refresh, you can add memory: true or memory: 'my-storage-name'. When set to true it will use tabbis as storage name.

Accessability

Aria markup is good for accessability. It's also a great standardized way to have a relationship between the tabs and the panes. That way we don't need to reinvent the wheel.

Tabbis automatically adds aria attributes to the elements, so you don't have to.

Active tab

There are many ways to have a tab activated.

User interaction

When you click a tab or press enter on you keyboard, the current tab will be activated by default.

Memory

In case you have set memory: true, Tabbis will remember the current state of your tabs after you refresh the page.

Selector

By default you can add data-active as an attribute to the tab in a group that should be active. Tabbis will then automatically add aria-selected="true" on the active tab. However, if memory is enabled it will override this state from the memory.

Aria attribute

Not rekommended: It's possible to add aria-selected="true" to the tab in a group that should be active, instead of using data-active. However, if memory is enabled, it will override this state from the memory.

Tab index

If you have not added data-active or not added aria-selected="true" as an attribute to a tab, it will by default fallback to the first tab. You can force Tabbis to not select anything with tabActiveFallback: false.

Requirements

Tabbis is tested with the following browsers.

  • Chrome
  • Edge
  • Firefox
  • Opera

What about IE11? Help me out and try IE11 (with the ES5 version) and report the result as an issue.

FAQ

Why does Tabbis not load?

In some cases you may need to wait for the dom to load. It can be done like below.

window.addEventListener('DOMContentLoaded', () => {
  tabbis();
});

How can I trigger a tab to activate?

There is no built in feature in Tabbis to do that, but it can be done with pure javascript.

const element = document.querySelector('.my-tab');
element.click();

How can I reset the tabs memory?

One way is to use Clear Session which is a Google Chrome extension.

Why is the memory acting wierd when using tabs on multiple pages?

The memory uses a key that is bound to a domain, not a page. You should change the memory: 'tabbis' to something like memory: 'tabbis-page-about' to have a unique memory for each page type.

Disclaimer

This library is provided "as is" with no guarantee. Use it at your own risk and always test it yourself before using it in a production environment. If you find any issues, please create a new issue.

Featured

Inspiration

Credits

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].