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

hot-nav

v1.0.10

Published

intuitive accessibility hot keys

Downloads

151

Readme

HOT NAV

Hot-Nav is an accessibility library for adding hotkey functionality to Next.js applications.

Instructions

Install the hot-nav package in the body of your application:

npm install hot-nav

Import the HotNavProvider component in the root file of your Next.js application and wrap the root of your application in this component:

import { HotNavigationProvider } from 'hot-nav';

export const metadata = {
  title: 'My NextJS App',
  description: 'This app is accessible and amazing thanks to HotNav!',
};

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <HotNavigationProvider>
        <body>{children}</body>
      </HotNavigationProvider>
    </html>
  );
}

Wrap any clickable component you wish in the HotLink component. As you can see, onClick functionality is also supported:

import { HotLink } from "hot-nav";


const SomeReactComponent = () => {
  return (
    <>
      <HotLink>
        <a href="/infinity">TO INFINITY</a>
      </HotLink>
      <HotLink>
        <button onClick={() => alert('HOTNAV IS BEYOND AWESOME!!')}>AND BEYOND</button>
      </HotLink>
    </>
  )
}

The HotLink component can also function independently as a standalone clickable component:

const SomeReactComponent = () => {
  return (
    <>
      <HotLink href="/infinity">TO INFINITY</HotLink>
      <HotLink onClick={() => alert('HOTNAV IS BEYOND AWESOME!!')}>AND BEYOND</HotLink>
    </>
  )
}

Class components are also supported!:

'use client'

import React from 'react';
import { HotLink } from 'hot-nav';

class ClassyLink extends React.Component {
  render() {
    return <a href='/stayClassy'>{this.props.children}</a>;
  }
}

export default class SomeMythicalComponent extends React.Component {
  render() {
    return (
      <HotLink>
        <ClassyLink>BACK TO THE FUTURE</ClassyLink>
      </HotLink>
    )
  }
}

As you can see, the HotLink component is able to access a nested href attribute. This will work for any level of nesting, both for elements that are returned by wrapper components like ClassyLink, and for elements that are children of a component HotLink is wrapping, as you can see in this extreme example here:

<HotLink>
  <div>
    <div>
      <div>
        <div>
          <button onClick={() => alert('peep')}>
            <div>
              <div>
                <div>
                  <a href='/extreme'>This Seems Unreasonable...</a>
                </div>
              </div>
            </div>
          </button>
        </div>
      </div>
    </div>
  </div>
</HotLink>

Now that was extreme! And what in the heck was that button element doing there? Well, as it turns out, HotLink will register both the onClick event, and the nested route to '/extreme'. Pretty cool! However, let's say these elements were to both have 'href' attributes. In this case, the 'href' of the most senior element will take precedence, and the more nested 'href' will be ignored, as is demonstrated below:

//the user will be redirected to '/darthbutton', rather than '/noooooo'
<HotLink>
  <button href='/darthbutton' onClick={() => alert("ANCHOR, I AM YOUR FATHER!")}>
    <a href='/noooooo'>NOOOOOOOOOO!!!!!!</a>
  </button>
</HotLink>

User Experience

The hotkey implementation is simple: a unique number is placed directly to the left of each HotLink-wrapped component on the page. These numbers are in incrementing order, so if there are 5 HotLink components, the numbers 1 through 5 will be used as hotkeys. When the user presses and releases a number that is a hotkey, the corresponding component is 'clicked'.

But what if there are more than 9 components? In this case, multi-digit hotkeys are implemented: 12, 13, 14, 15, etc. In these cases, the user must hold down the '1' key, then press the respective 2nd key. In the case of multi-digit hotkeys, simply pressing down the 2nd key will trigger the 'click' (as opposed to the release of the key triggering the 'click'). A concern here might be that lifting the 2 keys that are still pressed might trigger additional hotkeys, but debouncing has been implemented to disable all hotkeys after a click event until all keys have been lifted.

Demo

demo