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

search-with-your-keyboard

v2.0.0

Published

Add keyboard navigation to your existing client-side search interface

Downloads

430

Readme

search-with-your-keyboard

Add keyboard navigation to your existing client-side search interface.

This module is designed to make Algolia InstantSearch results (aka "hits") navigable with a keyboard. It's not Algolia-specific though, and should work with any search setup so long as it includes a search input and a list of client-side-updated results.

Behavior

Key | Action --- | ------ / | Focuses the search input. esc | Focuses the search input and clears it. down | Adds an active class to the next (visible) hit. Only applies when the search input contains a value. up | Adds an active class to the previous (visible) hit. If already on the first search hit, the search input is focused. Only applies when the search input contains a value. enter | Sets window.location to the href of the first <a> tag in the current .active hit, if present. cmdOrCtrl+Enter | Opens the window in new tab and focus it.

Installation

npm install search-with-your-keyboard

Usage

The module exports a single function that expects two CSS selector strings as arguments: one for the input element, one for the set of hit elements.

const searchWithYourKeyboard = require('search-with-your-keyboard')

searchWithYourKeyboard('#search-input', '.ais-hits--item')

Styles

You should specify styles for the .active class on your hits, to make the currently active hit visible to the user. You may want this to be the same style as :hovering on a hit:

.ais-hits--item:hover, .ais-hits--item.active {
  background-color: #F0F0F0;
}

API

searchWithYourKeyboard(inputSelector, hitsSelector)

Arguments:

  • inputSelector String (required) - A CSS selector used to find the search input, e.g. #search-input
  • hitsSelector String (required) - A CSS selector used to find all hits, e.g. .ais-hits--item

Tests

npm install
npm test

License

MIT