npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

focus-traversal-api-polyfill

v2.1.1

Published

Focus Traversal API polyfill.

Downloads

13

Readme

Focus Traversal API

The Focus Traversal API is a proposed change to the W3C/wHATWG HTML Specification for making working with Browser UI Focus more useful and more powerful. The proposal has been brought to the W3C WICG and the WHATWG for discussion and hopefully implementation and is currently in the discussion phase within both communities. If you would like more details about the proposal, an EXPLAINER is provided at: EXPLAINER

Additionally, a polyfill for the proposed additions can be found here to allow the community to try and demonstrate the usefulness of Focus Traversal and we encourage everyone to give it a try.

Also, we are always looking for people to get involved with the Focus Traversal API and proposal. Please consider helping us by spreading the word, commenting on the proposal, or participating in this repo!

Check out our GETTING INVOLVED page for more details on how you can help!

Focus Traversal API Features

  • Implements proposed Focus Traversal API standard.
  • Programatically move the focus forward or backwards.
  • Identify the next and previous items to receive focus.
  • Supports handling focus in Shadow DOM hidden components.
  • History of the last n focus holders.
  • Works on all modern browsers including Internet Explorer 9 or later.

Usage

Install from npm...

npm install focus-traversal-api-polyfill

Copy the polyfill into your own project...

cp focus-traversal-api-polyfill/focus-traversal-api-polyfill.min.js .

Include in your index.html...

<script src="./focus-traversal-api-polyfill.min.js" type="text/javascript"></script>

You may now use the focusManager as described in the section below.

API Documentation

window.focusManager.currentlyFocused - Contains the element currently holding the focus, if any.

window.focusManager.previouslyFocused - Contains the element that held the focus prior to the current focus, if any.

window.focusManager.history - An array of the last n historical focus holders.

window.focusManager.historyLimit - A number indicating how may focus history events should be retained. Defaults to 50.

window.focusManager.isFocusable(element) - Returns true if the given element can receive focus.

window.focusManager.hasFocusable(element) - Returns true if the given element currently has the focus.

window.focusManager.focus(element,focusOption) - Focus on the given element. Functionally the same as element.focus(). Returns void.

window.focusManager.forward(focusOption) - Move the focus to the next focusable element. Returns void.

window.focusManager.backward(focusOption) - Move the focus to the previous focusable element. Returns void.

window.focusManager.next(element) - Returns the element that would receive the focus if window.focusManager.forward() was called when the given element has the focus. If no element is given, the currently focused element is used.

window.focusManager.previous(element) - Returns the element that would receive the focus if window.focusManager.backward() was called when the given element has the focus. If no element is given, the currently focused element is used.

window.focusManager.list(container) - Returns an array of all focusable elements in the order that focus traversal would occur. If container is provided and a valid HTMLElement, this would limit the results to only the children of the given container. If no container is provided, the current document is used as the container.

window.focusManager.first(container) - Returns the first element that would receive focus for the given container, or the current document if no container is provided.

window.focusManager.last(container) - Returns the first element that would receive focus for the given container, or the current document if no container is provided.

window.focusManager.parent(element) - returns the first focusable ancestor of the given element.

window.focusManager.child(element) - returns the first focusable descendant of the given element. The same as first(element).

window.focusManager.order(element,element,element,etc) - Programatically set the traversal order of one or more elements. Given an array of elements (or multiple arguments) order them in the order they are given.

window.focusManager.trap() - Trap focus within a given element(s), such that any focus event outside and of the given element(s) descendants will refocus the last focused element within the element's descendants. Traps calls stack, such that the latest trap always wins, but removing a trap will set th enext prior trap running.

window.focusManager.untrap() - Removes a trap.

window.focusManager.proxy(source,target) - When the given source element receives the focus, forward that focus immediately to the target element.

window.focusManager.unproxy(source,target) - Removes a proxy.

Issues

If you would like to comment on the proposal, please open an issue.

License

The proposal and the polyfill library are available under the MIT License.