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 🙏

© 2026 – Pkg Stats / Ryan Hefner

svelte-keyboard-navigation

v0.1.1

Published

A lightweight Svelte action to add keyboard navigation to your Svelte app.

Readme

svelte-keyboard-navigation

A lightweight Svelte action to add keyboard navigation to your Svelte app.

Features

  • 📦 Tiny: 1.4KB min+gzip
  • ⚛️ Reactive: Change key combinations on-the-fly
  • 😀 Simple: Easy-to-use API

Installation

pnpm add svelte-keyboard-navigation

# ... or with npm
npm install --save svelte-keyboard-navigation

# ... or with yarn
yarn add svelte-keyboard-navigation

Usage

Basic usage

<script>
  import { keyboardNavigation, KeyCombo, KeyMap } from "mylib/wrappers/svelte";

  const stringSelected = `Selected; press Shift+A to change`;
  const stringUnselected = `Not selected; press A to change`;

  // define our keymap...
  const keymap = new KeyMap();

  // ... and attach a behavior to it, which is invoked when "a" is pressed
  keymap.attachBehavior(["a"], {
    behavior: (options) => {
      const { element } = options.target;
      element.innerText = stringSelected;
      element.style.background = "#66BB6A";
    },
    stack: false,
  });
  // attach another behavior to it, which is invoked when "shift" and "a" are
  // pressed together
  // we'll use the `KeyCombo` class for that
  keymap.attachBehavior([new KeyCombo("shift", "a")], {
    behavior: (options) => {
      const { element } = options.target;
      element.innerText = stringUnselected;
      element.style.background = "#EF5350";
    },
    stack: false,
  });
</script>

<div
  use:keyboardNavigation={{
    // our keymap
    keymap,
    // ... and a selector that can select any direct child of this `div`
    selector: ".child",
  }}
>
  <div tabindex="0" class="child">Click me and press "A"/"Shift+A"</div>
</div>

<!-- some styling to make it look good -->
<style>
  div.child {
    background: #42a5f5;
    font-family: sans-serif;
    outline: 0.25rem solid black;
    padding: 2.5rem;
  }
</style>

Attaching a Behavior

To attach a behavior that executes when, say, "A" or "B" is pressed, do:

keymap.attachBehavior(["A", "B"], {
  behavior: () => {
    // do cool stuff
  },
  stack: false,
});

Detaching a Behavior

To detach/remove a behavior, for example, the behavior that executes when "A" is pressed in the basic usage, do:

keymap.detachBehavior(["A"]);

Duplicating a Keymap

// we want to copy `keymap1` into `keymap2`
keymap2.copy(keymap1);

// alternate method
const keymap2 = new KeyMap(keymap1);

Preventing Default Browser Behavior

Sometimes, you may want to prevent default browser behavior from running (for example, adding a custom save prompt box). You can disable it when attaching the behavior:

keymap.attachBehavior([...], {
  behavior: ...,
  stack: ...,
  // disable default browser behavior
  preventsDefault: true,
});

Using Key Combos

Currently, key combos of type <modifier key^> + <alphanumeric key> are supported. To use such a combination, do:

import { KeyCombo } from "svelte-keyboard-navigation";
...
keymap.attachBehavior([
  new KeyCombo("<your modifier key>", "<your alphanumeric key>")
], ...);

^ Modifier key (Wikipedia)

Behavior ➡️ options.target.position

To use options.target.position in the behavior arguments, you'll have to define data-number property on every element that your selector can select. See the Svelte demo's source for an example.

API Reference

Will be available soon.

Demos

Note: You'll need pnpm installed to run the demo.

Run a live demo on your local machine. Run the following commands:

git clone https://github.com/harshulvijay/keyboard-navigation
cd keyboard-navigation/demo
pnpm lib:install # installs the library
pnpm dev:svelte # starts the Svelte demo

Open the URL that you see in the terminal to see the demo.

Contributing

Feel free to open an issue with feature requests/bug reports.

Note: Please create an issue before opening a PR.

License

License