0.3.1 • Published 1 year ago

makeup-focusables v0.3.1

Weekly downloads
97
License
MIT
Repository
github
Last release
1 year ago

makeup-focusables

Returns an array of all focusable descendants of the given element.

Experimental

This module is still in an experimental state, until it reaches v1 you must consider all minor releases as breaking changes.

Example

Markup:

<div class="widget">
    <h2 tabindex="-1">Widget Title</h2>
    <p>Widget Text</p>
    <button type="button">Widget Button</button>
    <a href="#">Widget Link</a>
</div>
import focusables from 'makeup-focusables';

// get element reference
const widgetEl = document.querySelector('.widget');

// get array of all focusable elements (keyboard and programmatic)
const allItems = focusables(widgetEl);

console.log(allItems.length) // outputs: 3

// get array of only keyboard focusable elements
const keyboardItems = focusables(widgetEl, true);

console.log(keyboardItems.length) // outputs: 2

Parameters

  • el: the element to search (default: undefined)
  • keyboardOnly: return only elements focusable in sequential keyboard navigation (default: false)
  • callback: if set, will call focusables after requestAnimationFrame and will pass the list of focusables in a callback method

Custom Events

  • None
0.3.1

1 year ago

0.3.0

2 years ago

0.2.0

3 years ago

0.1.0

4 years ago

0.0.5

4 years ago

0.0.4

5 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago