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

current-input

v2.0.0

Published

Detect the current input (mouse or touch) and fix the sticky :hover bug on touch devices.

Downloads

163

Readme

Current Input

npm bundle size (version) npm type definitions

  • Detects the current input being used (mouse or touch) and adds a current-input-mouse or current-input-touch class to the body indicating the current input type.
  • Used with the appropriate CSS selectors this will fix the sticky :hover bug on touch devices and allow you to work with 3 interactive states in CSS: hover, active, and touch active.
  • current-input is as easy as set it and forget it, and is compatible with all modern browsers. It will automatically add the current-input-mouse or current-input-touch class to the body.

Demo website — demo code in the /docs folder


Installing current-input

Install it in your app:

npm install --save current-input

And then import it in your app (it will run automatically on import).

import 'current-input';

Or add the script to index.html:

Alternatively you can add the script directly to your index.html. The version that comes from the Unpkg CDN is minified and gziped with all dependencies included and will run automatically.

<script src="https://unpkg.com/current-input@2/dist/current-input.umd.production.js"></script>

Using current-input

current-input will run automatically and will add the class current-input-mouse or current-input-touch to the body. Use the appropriate CSS selectors to style elements based on the current input class.

CSS example

Here is an example using CSS to style links such that it fixes the sticky hover problem on touch devices and provides a unique touch active state. See the demo website for a live version of this example (demo code in the /docs folder).

/*
In this example, links will be:
- Black normally
- Green on hover
- Red on active
- Blue on touch active
*/

a {
  color: black;
}

.current-input-mouse a:hover {
  color: green;
}

.current-input-mouse a:active {
  color: red;
}

/* the touch active state */
.current-input-touch a:active {
  color: blue;
}

Sticky :hover bug

The sticky :hover bug on touch devices occurs when you tap something that has a :hover state. The :hover state sticks until you tap someplace else on the screen. The reason for this is back in the early days of mobile, the web relied heavily on hover menus, so on mobile you could tap to see the hover menu. Sites are generally no longer be built this way, so now the sticky hover feature has become a bug. current-input fixes the problem by allowing you to style the :hover state for mouse and touch inputs separately. Now you can only style the :hover state when the current-input-mouse class is present, and do nothing when the current-input-touch class is present, which fixes this bug.