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

tactical-focus

v0.3.0

Published

Tiny utility that applies a class hook for tactical :focus styling

Downloads

12

Readme

tactical-focus

A micro utility that applies a class hook for tactical :focus styling.

Why?

tl;dr

The need for this utility is nuanced. There's a good chance you want to use :focus-visible (MDN/CanIUse). That said ...

tactical-focus lets you write CSS targeting currently-focused elements when a user is actively navigating via keyboard. Note that it's subtly different than the :focus-visible selector.

.tactical-focus a:focus {
  outline: 2px solid green;
}

Demo, Please

Here's a demo comparing tactical-focus VS :focus-visible VS browser defaults.

If you don't spot the differences, go with :focus-visible. You won't lose!

Not Too Long; Did Read

Browsers apply default user agent styles to focusable DOM elements based on native heuristics, like those blue or yellow outlines in Webkit/Blink-based browsers or Firefox's dotted gray borders. Removing these defaults makes keyboard operability difficult, if not impossible since you have no idea which element is focused.

Clicking on focusable elements gives them focus, too. This often spurs design conflicts when we want something other than that bespoke button or form input getting a giant glowing ring around it when clicked.

Enter tactical-focus. This tiny (about 600 bytes) library toggles a class name on an HTML document's body (or other element of your choice) so you can craft :focus styles applied only when a user navigates via keyboard.

Installation and Usage

First, install tactical-focus --

npm install tactical-focus

Then, import and initialize it in your project.

import { initTacticalFocus } from 'tactical-focus';

...

initTacticalFocus();

Recommended Placement

tactical-focus is super lightweight and only runs once. You don't need to stress optimal script placement or execution timing; follow common sense and best practices.

Since it's a utility that assists in-page navigation, however, it's recommended you run it as soon as practical after the DOM is ready.

Customization Options

// all options and their defaults
initTacticalFocus({
  // class hook that gets toggled on keyboard/mouse mode of operation
  name: 'tactical-focus',
  // element where the class hook gets applied; accepts a selector string or DOM node
  target: 'body',
  // adds semi-helpful console logging
  debug: false,
})

Types

Type declarations are included for out-of-the-box TypeScript support; no @types needed.

License

MIT