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

access-key-label-polyfill

v0.1.1

Published

Polyfills the accessKeyLabel property to improve discoverability of native keyboard shortcuts for your website. Tiny (< 1KB) and dependency-free.

Downloads

183

Readme

AccessKeyLabelPolyfill

Polyfills the accessKeyLabel property to improve discoverability of native keyboard shortcuts for your website. Tiny (< 1KB) and dependency-free.

With the accesskey HTML property, you can easily provide keyboard shortcuts for the buttons of your web application.

<button accesskey="D">Do crazy stuff</button>
<!-- Can be activated using Ctrl + Alt + D -->

Sadly, most users don't even know these shortcuts can be used, even if the web developer provided them. To make these shortcuts more discoverable you might decide to use the title property, a tooltip or some other UI element to display the keyboard shortcut.

<button accesskey="D">Do crazy stuff</button>
<small>Hint: Use Ctrl + Alt + D to quickly access this button!</small>

A good idea, but browsers use different combinations of modifier keys. But thanks to the accessKeyLabel property, we can easily get a string representation of the keyboard shortcut assigned by the browser. Sooo, we're good, right? Alas, not quite. Though the API has been around for years, browser support isn't good enough. Especially, since Chrome is still missing out. To help bridge the gap, you can use this polyfill and finally let your users benefit from the keyboard shortcuts you provide!

Demo

Full length article about accessKey and accessKeyLabel on dev.to

Usage

NPM

Simply install the polyfill:

npm i access-key-label-polyfill
# or
yarn add access-key-label-polyfill

And the import and run the install function:

import installAccessKeyLabelPolyfill from 'access-key-label-polyfill';
installAccessKeyLabelPolyfill();

Note: CJS, UMD and ESM are available, just take a look in the package.

Browser

You can also use this polyfill 'oldschool'. Simply download the demo files and add the AccessKeyLabelPolyfill.umd.js file to your body:

<body>
  <!-- ... -->
  <script src="path/to/AccessKeyLabelPolyfill.umd.js"></script>
  <script>
    accessKeyLabelPolyfill(); // lowerCamelCase!
  </script>

Demo

You can view the demo here: https://tillsanders.github.io/access-key-label-polyfill/

The demo will tell you wether the polyfill detected native support for accessKeyLabel or not and will display either output below the button.

How does it work?

First, the polyfill will try to detect wether the browser already supports accessKeyLabel. If it does, it will exit immediately. If the browser doesn't support this API, the polyfill will add a small function to fill the gap. This function will try to detect the browser / operating system and return the correct label. You can then use accessKeyLabel as expected.

Caveats

  • To return the correct label, the polyfill needs to determine the correct operating system, browser and sometimes even the browser version. This is done with a very lightweight script and based on the user-agent. While this has been tested successfully and should work reliably, wrong user-agents can still mess it up, of course.
  • The polyfill currently supports the major browsers on macOS (including Firefox < v14), namely Chrome. As well as Internet Explorer, Edge and Safari on iOS / iPadOS. There might be more browsers, that need this polyfill, but there is surprisingly little information regarding support, so please feel free to open an issue if you come across an unsupported case.
  • Chrome on Android does not seem to support accessKey, or at least, I was unable to guess (why is this not documented anywhere?!) the correct modifier keys. Would love to get help with this!

Changelog

0.1.1 – (10.01.2021)

  • Fix browser detection of Edge

0.1.0 – (09.01.2021)

  • Initial implementation