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

@janiking/key-nav

v2.6.18

Published

Make a list of items keyboard navigable, using arrow, enter, escape and search keys

Downloads

200

Readme

`#key-nav

Make a list of items keyboard navigable, using arrow, enter, escape and search keys

Description

key-nav attaches to a DOM node and makes it keyboard-navigable. It adds state attributes to nodes so they can be styled at your discretion with CSS.

Lists ( such as ul - li) or tables can be navigated. If alphanumeric characters are pressed, the children are searched.

The children are a live NodeList, so any references will update if nodes are added or removed.

To Install

npm install @janiking/key-nav --save

key-nav has a dependency on janiking/on.

Support

key-nav uses ES5 (not ES6), so it is compatible with all browsers, IE11 and above.

This library uses UMD, so it should work in any framework.

Changes

As of version 2, key-nav is a11y.

  • Instead of a .highlighted class, the node is focused, adding: tab-index=-1 and aria-current="true".
  • Instead of, the attribute selected="true", it is now: aria-selected="true";

Usage

Including key-nav in your code will return a keys function.

var controller = keys(listNode, options);

key-nav will automatically determine if the listNode is a list or a table.

The controller can be paused or destroyed:

controller.pause();
controller.resume();
controller.remove();

It also has a few dynamic controls:

controller.setSelected(child);
var selectedChild = controller.getSelected();

The following attributes are added to children, depending upon their state:

  • aria-current - The child has enter a mouseover state, or has been navigated to with an Arrow key.
  • aria-selected - The child has been clicked upon, or ha been selected with the Enter key.

The following custom events are fired from the listNode:

  • key-highlight - The child has enter a mouseover state, or has been navigated to with an Arrow key.
  • key-select - The child has been clicked upon, or has been selected with the Enter key.

Options

The following options are available:

  • canSelectNone - Allows no selection. Defaults to first child.
  • defaultToFirst - First child is selected on init. Defaults to no selection at start
  • multiple - Allows multiple select with Shift or Control/Command. Defaults to single select.
  • searchTime - The time before an alphanumeric search is executed. Defaults to 1000ms.
  • noRoles - This will prevent the default, which is to automatically add Aria roles to the list node and its children.

Events

The following (custom) events are emitted:

  • key-select - Emits on selection.
  • key-highlight - Emits on selection.
  • key-dom-change - Emits on add or remove of a list item.

key-select

{
    detail:{
        value: HTMLElement
    }
}

If no selection, the value is null.

if multiple is true:

{
    detail:{
        value: [HTMLElement, HTMLElement]
    }
}

If no selection, the value is [].

key-highlight

{
    detail:{
        value: HTMLElement
    }
}

key-dom-change

The MutationEvent is passed:

{
    detail:{
        addedNodes: NodeList [],
        removedNodes: NodeList [li],
        attributeName: null,
        attributeNamespace: null,
        nextSibling: null,
        oldValue: null,
        previousSibling: li,
        target: ol#list,
        type: "childList"
    }
}

License

This uses the MIT license. Feel free to use, and redistribute at will.`