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

power-focusable

v4.1.1

Published

High-precision focus management utility with full composed tree support

Downloads

3,272

Readme

Power Focusable

High-precision focus management utility with full composed tree support. Handles complex focus rules including tabindex ordering, radio groups, inert.

[!NOTE] Supports shadow DOM traversal via the composed tree. Only open shadow roots are included; closed shadow roots are not accessible.

Install

npm i power-focusable
// npm
import {
  createFocusTrap,
  getFocusables,
  getNextFocusable,
  getPreviousFocusable,
  hasFocusable,
  inertOutside,
  isFocusable,
} from 'power-focusable';

// CDNs
import { ... } 'https://esm.sh/power-focusable'
// or
import { ... } 'https://cdn.jsdelivr.net/npm/power-focusable/+esm';
// or
import { ... } 'https://unpkg.com/power-focusable/dist/index.js';

🪄 Options

interface PowerFocusableOptions {
  anchor?: Element | null;                 // default: document.activeElement
  composed?: boolean;                      // default: false
  filter?: (element: Element) => boolean;  // default: () => true
  include?: (element: Element) => boolean; // default: undefined
  wrap?: boolean;                          // default: false
}

anchor

Specifies the starting element.

Used by getNextFocusable and getPreviousFocusable.

composed

If true, traverses the composed tree (including shadow DOM; slower)

Used by getFocusables, getNextFocusable, getPreviousFocusable, and hasFocusable.

filter

Custom filter function for excluding elements from focus traversal.

The function should return true to include the element, or false to exclude it.

Used by getFocusables, getNextFocusable, getPreviousFocusable, and hasFocusable.

include

Custom include function for adding elements to focus traversal even if they are not normally focusable.

The function should return true to include the element, or false to ignore it.

Used by getFocusables, getNextFocusable, getPreviousFocusable, and hasFocusable.

wrap

If true, wraps around to the first or last element when reaching the end.

Used by getNextFocusable and getPreviousFocusable.

📦 APIs

createFocusTrap

Creates a keyboard focus trap within the container. Automatically focuses the container itself when possible; otherwise focuses the first available focusable element.

const cleanup = createFocusTrap(container);
// => () => void
//
// container: Element

getFocusables

Returns all focusable elements within the container.

getFocusables(container);
// => Element[]
//
// container (optional): Element (default: <body>)

// Traverses the composed tree (including shadow DOM; slower)
getFocusables(container, { composed: true });

// Uses custom filter function
getFocusables(container, { filter: (element) => !element.matches('[data-skip-focus]') });

getNextFocusable

Returns the next focusable element within the container, starting from document.activeElement.

getNextFocusable(container);
// => Element | null
//
// container (optional): Element (default: <body>)

// Specifies the starting element
getNextFocusable(container, { anchor: document.querySelector('.button') });

// Traverses the composed tree (including shadow DOM; slower)
getNextFocusable(container, { composed: true });

// Uses custom filter function
getNextFocusable(container, { filter: (element) => !element.matches('[data-skip-focus]') });

// Wraps around to the first element when reaching the end
getNextFocusable(container, { wrap: true });

getPreviousFocusable

Returns the previous focusable element within the container, starting from document.activeElement.

getPreviousFocusable(container);
// => Element | null
//
// container (optional): Element (default: <body>)

// Specifies the starting element
getPreviousFocusable(container, { anchor: document.querySelector('.button') });

// Traverses the composed tree (including shadow DOM; slower)
getPreviousFocusable(container, { composed: true });

// Uses custom filter function
getPreviousFocusable(container, { filter: (element) => !element.matches('[data-skip-focus]') });

//Wraps around to the last element when reaching the end
getPreviousFocusable(container, { wrap: true });

hasFocusable

Returns whether the container contains at least one focusable element.

hasFocusable(container);
// => boolean
//
// container (optional): Element (default: <body>)

// Traverses the composed tree (including shadow DOM; slower)
hasFocusable(container, { composed: true });

// Uses custom filter function
hasFocusable(container, { filter: (element) => !element.matches('[data-skip-focus]') });

inertOutside

Temporarily applies inert to all elements outside the target element. Useful for modals, dialogs, and overlays.

const cleanup = inertOutside(element);
// => () => void
//
// element: Element

isFocusable

Returns whether the given element is focusable.

isFocusable(element);
// => boolean
//
// element: Element