All Projects → AcceDe-Web → tablist

AcceDe-Web / tablist

Licence: ISC license
WAI-ARIA tab plugin without dependencies.

Programming Languages

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

Projects that are alternatives of or similar to tablist

Core Components
Accessible and lightweight Javascript components
Stars: ✭ 85 (+304.76%)
Mutual labels:  a11y, vanilla-js
js-plugin-starter-kit
VanillaJS (pure JavaScript) plugin starter with Webpack 4 and Babel 7.
Stars: ✭ 100 (+376.19%)
Mutual labels:  vanilla-javascript, vanilla-js
A11y accordions
ES5 ARIA Accordion Component
Stars: ✭ 108 (+414.29%)
Mutual labels:  a11y, vanilla-javascript
Vanillajs Deck
A Vanilla.js Single Page App (SPA) slide deck for a presentation about Vanilla.js written with no frameworks.
Stars: ✭ 119 (+466.67%)
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 (+42.86%)
Mutual labels:  vanilla-javascript, vanilla-js
Mailtoui
A simple way to enhance your mailto links with a convenient user interface.
Stars: ✭ 162 (+671.43%)
Mutual labels:  vanilla-javascript, vanilla-js
Handorgel
Accessible W3C conform accordion written in ES6.
Stars: ✭ 239 (+1038.1%)
Mutual labels:  a11y, vanilla-js
Bin
A tiny (<1kb) localStorage and sessionStorage helper library.
Stars: ✭ 70 (+233.33%)
Mutual labels:  vanilla-javascript, vanilla-js
tensorflowjs-remove-background
Remove Background from the picture using WebAssembly & TensorFlow.js
Stars: ✭ 79 (+276.19%)
Mutual labels:  vanilla-javascript, vanilla-js
coding challenge-14
Understanding JavaScript and coding without the help of a library or tool
Stars: ✭ 22 (+4.76%)
Mutual labels:  vanilla-javascript, vanilla-js
Rallax.js
Dead simple parallax scrolling.
Stars: ✭ 1,441 (+6761.9%)
Mutual labels:  vanilla-javascript, vanilla-js
mm-components
Music Markups components
Stars: ✭ 50 (+138.1%)
Mutual labels:  vanilla-javascript, vanilla-js
Router.js
Router.js is a simple and powerful javascript library to handle routing
Stars: ✭ 107 (+409.52%)
Mutual labels:  vanilla-javascript, vanilla-js
Bs Custom File Input
A little plugin for Bootstrap 4 custom file input
Stars: ✭ 162 (+671.43%)
Mutual labels:  vanilla-javascript, vanilla-js
Vanilla Semantic Ui
Semantic UI component framework without jQuery
Stars: ✭ 97 (+361.9%)
Mutual labels:  vanilla-javascript, vanilla-js
Houdini
A simple, accessible show-and-hide/accordion script.
Stars: ✭ 148 (+604.76%)
Mutual labels:  a11y, vanilla-js
Vanilla Ui Router
Simple vanilla JavaScript router
Stars: ✭ 42 (+100%)
Mutual labels:  vanilla-javascript, vanilla-js
Fine Uploader
Multiple file upload plugin with image previews, drag and drop, progress bars. S3 and Azure support, image scaling, form support, chunking, resume, pause, and tons of other features.
Stars: ✭ 8,158 (+38747.62%)
Mutual labels:  vanilla-javascript, vanilla-js
curved-menu
VanillaJS fully configurable curved menu (circular navigation)
Stars: ✭ 30 (+42.86%)
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 (+161.9%)
Mutual labels:  vanilla-javascript, vanilla-js

AcceDe Web - tablist

WAI-ARIA tab plugin without dependencies.

Requirements

HTML

Basic HTML structure with roles tablist, tab, and tabpanel.

HTML structure

<ul role="tablist">
  <li role="tab" aria-controls="tab-1">Tab 1</li>
  <li role="tab" aria-controls="tab-2">Tab 2</li>
  <li role="tab" aria-disabled="true" aria-controls="tab-3">Tab 3</li>
  <li role="tab" aria-controls="tab-4">Tab 4</li>
</ul>

<div role="tabpanel" id="tab-1">
  <p>---</p>
</div>
<div role="tabpanel" id="tab-2">
  <p>---</p>
</div>
<div role="tabpanel" id="tab-3">
  <p>---</p>
</div>
<div role="tabpanel" id="tab-4">
  <p>---</p>
</div>

An aria-disabled attribute set to true on a tab will disable the tab and the associated tabpanel making them unfocusable and unselectable.

If you wish to open one specific tab when the script starts, just add the data-open attribute with the value of true on the desired tab:

<ul role="tablist">
  <li role="tab" aria-controls="tab-1">Tab 1</li>
  <li role="tab" aria-controls="tab-2" data-open="true">Tab 2</li>
  <li role="tab" aria-controls="tab-3">Tab 3</li>
  <li role="tab" aria-controls="tab-4">Tab 4</li>
</ul>

<!-- -->

CSS

At least a CSS selector for panels to be hidden when not selected:

[role=tabpanel][aria-hidden=true] {
  display: none;
}

The selector can be anything you want, like a class, as the script allows callback when opening or closing a panel; you can add your own class using the callbacks.

JavaScript

The script itself, either from npm:

$ npm install @accede-web/tablist

and later in your code:

var Tablist = require( '@accede-web/tablist' );

// or

import Tablist from @accede-web/tablist

or downloaded from Github and added to the page (minified and non minified versions available in the dist folder)

<script src="./js/tablist.min.js"></script>

Using the later, the script will be available on window under the namespace Tablist.

Now to kick off the script:

// get the tablist element
var list = document.querySelector( '[role="tablist"]' );

// create the tablist instance
var tablist = new window.Tablist( list );

// optionnaly add callbacks to on show and hide a tab
tablist.on( 'show', function( tab, tabPanel ){
  
});

tablist.on( 'hide', function( tab, tabPanel ){
  
});

// start the plugin
tablist.mount();

Parameters

The script takes one parameter:

  • the tablist DOM element

As the script takes only one tablist element as parameter you have to loop over each tablist to kick off the script on each of them.

var lists = document.querySelectorAll( '[role="tablist"]' );

Array.prototype.forEach.call( lists, function( list ) {
  new window.Tablist( list ).mount();
});

Methods

The Tablist constructor returns 4 methods:

  • mount() - bind all events and apply required attributes
  • unmount() - unbind keyboard and mouse events
  • on( event, callback ) - bind a callback to either the show or hide event triggered when changing tab. Both tab and tabPanel HTMLElement are passed on the callback
  • off( event, callback ) - unbind a callback to either the show or hide event triggered when changing tab

Properties

To know which tab and tabPanel is open use tablist.current. It will return an array containing tab and tabPanel

// ES6 destructuring array
const { tab, tabPanel } = tablist.current;

tab; // return the `tab`
tabPanel; // return the `tabPanel`

// ES5
var elements = tablist.current;

elements.tab; // return the `tab`
elements.tabPanel; // return the `tabPanel`

Keyboard Interaction

The keyboard interactions are based on Atalan's AcceDe Web guidelines (in French) and the WAI-AIRA 1.0 Authoring Practices

  • Tab - only the active tab is in the tab order. The user reaches the tabbed panel component by pressing the tab key until the active tab title receives focus.
  • Left Arrow - with focus on a tab, pressing the left arrow will move focus to the previous tab in the tab list and activate that tab. Pressing the left arrow when the focus is on the first tab in the tab list will move focus and activate the last tab in the list.
  • Right Arrow - with focus on a tab, pressing the right arrow will move focus to the next tab in the tab list and activate that tab. Pressing the right arrow when the focus is on the last tab in the tab list will move focus to and activate the first tab in the list.
  • Up arrow - behaves the same as left arrow in order to support vertical tabs.
  • Down arrow - behaves the same as right arrow in order to support vertical tabs.
  • Home - with focus on a tab, pressing the Home key will move the focus to the first tab
  • End - with focus on a tab, pressing the End key will move the focus to the last tab
  • Control+Up Arrow - with focus anywhere within the tab panel, pressing Control+Up Arrow will move focus to the tab for that panel. This is not standard behavior.
  • Control+PageUp - When focus is inside of a tab panel, pressing Control+PageUp moves focus to the tab of the previous tab in the tab list and activates that tab. When focus is in the first tab panel in the tab list, pressing Control+PageUp will move focus to the last tab in the tab list and activate that tab.
  • Control+PageDown When focus is inside of a tab panel, pressing Control+PageDown moves focus to the tab of the next tab in the tab list and activates that tab. When focus is in the last tab panel in the tab list, pressing Control+PageUpwill move focus to the first tab in the tab list and activate that tab.

Compatibilty

This plugin is tested against the following browsers:

  • Internet Explorer 9 and higher
  • Microsoft Edge
  • Chrome
  • Firefox
  • Safari

Testing

Install the project dependencies:

$ npm install

Run the automated test cases:

$ npm test
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].