makeup-focusables

0.3.1 • Public • Published

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

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i makeup-focusables

      Weekly Downloads

      203

      Version

      0.3.1

      License

      MIT

      Unpacked Size

      5.98 kB

      Total Files

      7

      Last publish

      Collaborators

      • saiponnada
      • lulavalva
      • artblue
      • dylanpiercey
      • sendlo
      • ianmcburnie
      • agliga