All Projects → focus-trap → Tabbable

focus-trap / Tabbable

Licence: mit
Find descendants of a DOM node that are in the tab order

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Tabbable

Empathy Prompts
💡 Ideas to help consider Inclusive Design principles when making things for others to use.
Stars: ✭ 173 (-30.24%)
Mutual labels:  a11y
Accessible modal window
Accessible modal dialogs
Stars: ✭ 196 (-20.97%)
Mutual labels:  a11y
Handorgel
Accessible W3C conform accordion written in ES6.
Stars: ✭ 239 (-3.63%)
Mutual labels:  a11y
Vue Announcer
A simple way with Vue to announce any useful information for screen readers.
Stars: ✭ 185 (-25.4%)
Mutual labels:  a11y
Tobi
An accessible, open-source lightbox with no dependencies.
Stars: ✭ 195 (-21.37%)
Mutual labels:  a11y
Asqatasun
Mirror of Asqatasun ---> we've moved to GITLAB https://gitlab.com/asqatasun/Asqatasun - Opensource web site analyser, used for web accessibility "a11y"
Stars: ✭ 217 (-12.5%)
Mutual labels:  a11y
Visible
🦉 Accessibility testing framework at the next level
Stars: ✭ 164 (-33.87%)
Mutual labels:  a11y
A11y Css Reset
A small set of global rules to make things accessible and reset default styling
Stars: ✭ 250 (+0.81%)
Mutual labels:  a11y
Equa11y
A stream-lined command line tool for developers to easily run accessibility testing locally through axe-core and puppeteer.
Stars: ✭ 201 (-18.95%)
Mutual labels:  a11y
Accessibility interview questions
A starting point for questions to ask someone that wants you to give them a job
Stars: ✭ 236 (-4.84%)
Mutual labels:  a11y
Bootstrap Vue
BootstrapVue provides one of the most comprehensive implementations of Bootstrap v4 for Vue.js. With extensive and automated WAI-ARIA accessibility markup.
Stars: ✭ 13,603 (+5385.08%)
Mutual labels:  a11y
Design System
Open source design and front-end development resources for creating Section 508 compliant, responsive, and consistent websites.
Stars: ✭ 192 (-22.58%)
Mutual labels:  a11y
Wai Tutorials
W3C WAI’s Web Accessibility Tutorials
Stars: ✭ 229 (-7.66%)
Mutual labels:  a11y
Dialog Polyfill
Polyfill for the HTML dialog element
Stars: ✭ 2,152 (+767.74%)
Mutual labels:  a11y
Focus Layers
Tiny React hooks for isolating focus within subsections of the DOM.
Stars: ✭ 238 (-4.03%)
Mutual labels:  a11y
Focusoverlay
Library for creating animated overlays on focused elements
Stars: ✭ 167 (-32.66%)
Mutual labels:  a11y
Eslint Plugin Jsx A11y
Static AST checker for a11y rules on JSX elements.
Stars: ✭ 2,609 (+952.02%)
Mutual labels:  a11y
Creatability Components
Web components for making creative tools more accessible.
Stars: ✭ 248 (+0%)
Mutual labels:  a11y
React Uid
Render-less container for generating UID for a11y, consistent react key, and any other good reason 🦄
Stars: ✭ 244 (-1.61%)
Mutual labels:  a11y
Accessibilitysnapshot
Easy regression testing for iOS accessibility
Stars: ✭ 236 (-4.84%)
Mutual labels:  a11y

tabbable CI Codecov license

All Contributors

Small utility that returns an array of all* tabbable DOM nodes within a containing node.

*all has some necessary caveats, which you'll learn about by reading below.

The following are considered tabbable:

  • <button> elements
  • <input> elements
  • <select> elements
  • <textarea> elements
  • <a> elements with an href attribute
  • <audio> and <video> elements with controls attributes
  • the first <summary> element directly under a <details> element
  • <details> element without a <summary> element
  • elements with the [contenteditable] attribute
  • anything with a non-negative tabindex attribute

Any of the above will not be considered tabbable, though, if any of the following are also true about it:

  • has a negative tabindex attribute
  • has a disabled attribute
  • either the node itself or an ancestor of it is hidden via display: none or visibility: hidden
  • is nested under a closed <details> element (with the exception of the first <summary> element)
  • is an <input type="radio"> element and a different radio in its group is checked

If you think a node should be included in your array of tabbables but it's not, all you need to do is add tabindex="0" to deliberately include it. (Or if it is in your array but you don't want it, you can add tabindex="-1" to deliberately exclude it.) This will also result in more consistent cross-browser behavior. For information about why your special node might not be included, see "More details", below.

Goals

  • Accurate (or, as accurate as possible & reasonable)
  • No dependencies
  • Small
  • Fast

Browser Support

Basically IE9+.

Why? It uses Element.querySelectorAll() and Window.getComputedStyle().

Note: When used with any version of IE, CSS.escape needs a polyfill for tabbable to work properly with radio buttons that have name attributes containing special characters.

Installation

npm install tabbable

Dependencies: none.

API

tabbable

import { tabbable } from 'tabbable';

tabbable(rootNode, [options]);

Returns an array of ordered tabbable nodes (i.e. in tab order) within the rootNode.

Summary of ordering principles:

  • First include any nodes with positive tabindex attributes (1 or higher), ordered by ascending tabindex and source order.
  • Then include any nodes with a zero tabindex and any element that by default receives focus (listed above) and does not have a positive tabindex set, in source order.

rootNode

Type: Node. Required.

options

includeContainer

Type: boolean. Default: false.

If set to true, rootNode will be included in the returned tabbable node array, if rootNode is tabbable.

isTabbable

import { isTabbable } from 'tabbable';

isTabbable(node);

Returns a boolean indicating whether the provided node is considered tabbable.

isFocusable

import { isFocusable } from 'tabbable';

isFocusable(node);

Returns a boolean indicating whether the provided node is considered focusable.

All tabbable elements are focusable, but not all focusable elements are tabbable. For example, elements with tabindex="-1" are focusable but not tabbable.

focusable

import { focusable } from 'tabbable';

focusable(rootNode, [options]);

Returns an array of focusable nodes within the rootNode, in DOM order. This will not match the order in which tabbable() returns nodes.

rootNode

Type: Node. Required.

options

includeContainer

Type: boolean. Default: false.

If set to true, rootNode will be included in the returned focusable node array, if rootNode is focusable.

More details

  • Tabbable tries to identify elements that are reliably tabbable across (not dead) browsers. Browsers are inconsistent in their behavior, though — especially for edge-case elements like <object> and <iframe> — so this means some elements that you can tab to in some browsers will be left out of the results. (To learn more about this inconsistency, see this amazing table). To provide better consistency across browsers and ensure the elements you want in your tabbables list show up there, try adding tabindex="0" to edge-case elements that Tabbable ignores.
  • (Exemplifying the above ^^:) The tabbability of <iframe>s, <embed>s, <object>s, <summary>s, and <svg>s is inconsistent across browsers, so if you need an accurate read on one of these elements you should try giving it a tabindex. (You'll also need to pay attention to the focusable attribute on SVGs in IE & Edge.) But you also might not be able to get an accurate read — so you should avoid relying on it.
  • Radio groups have some edge cases, which you can avoid by always having a checked one in each group (and that is what you should usually do anyway). If there is no checked radio in the radio group, all of the radios will be considered tabbable. (Some browsers do this, otherwise don't — there's not consistency.)
  • If you're thinking, "Why not just use the right querySelectorAll?", you may be on to something ... but, as with most "just" statements, you're probably not. For example, a simple querySelectorAll approach will not figure out whether an element is hidden, and therefore not actually tabbable. (That said, if you do think Tabbable can be simplified or otherwise improved, I'd love to hear your idea.)
  • jQuery UI's :tabbable selector ignores elements with height and width of 0. I'm not sure why — because I've found that I can still tab to those elements. So I kept them in. Only elements hidden with display: none or visibility: hidden are left out.
  • Although Tabbable tries to deal with positive tabindexes, you should not use positive tabindexes. Accessibility experts seem to be in (rare) unanimous and clear consent about this: rely on the order of elements in the document.
  • Safari on Mac OS X does not Tab to <a> elements by default: you have to change a setting to get the standard behavior. Tabbable does not know whether you've changed that setting or not, so it will include <a> elements in its list.

Feedback and contributions more than welcome!

Contributing

See CONTRIBUTING.

Contributors

In alphabetical order:


Bryan Murphy

🐛 💻

David Clark

💻 🐛 🚇 ⚠️ 📖 🚧

Dependabot

🚧

Ido Rosenthal

🐛 💻 👀

Kristian Hamilton

🐛

Mateusz Burzyński

💻 🐛 📖

Stefan Cameron

💻 🐛 🚇 ⚠️ 📖 🚧

Tyler Hawkins

🔧 ⚠️ 🚇 📖

pebble2050

🐛
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].