# focusable-selectors

> A list of CSS selectors for focusable elements

Latest version **0.8.4** (published 2023-10-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install focusable-selectors
pnpm add focusable-selectors
yarn add focusable-selectors
bun add focusable-selectors
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.8.4 |
| Published | 2023-10-04 |
| First published | 2021-02-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 81 |
| Author | Kitty Giraudel |
| Maintainers | kittygiraudel |
| Keywords | css, selectors, focus, a11y |

## Links

- npm: https://www.npmjs.com/package/focusable-selectors
- Repository: https://github.com/KittyGiraudel/focusable-selectors
- Homepage: https://github.com/KittyGiraudel/focusable-selectors#readme
- Issues: https://github.com/KittyGiraudel/focusable-selectors/issues
- npm.io page: https://npm.io/package/focusable-selectors

## Alternatives

- [style-dictionary](https://npm.io/package/style-dictionary.md) — 2.0M weekly downloads
- [postcss-merge-idents](https://npm.io/package/postcss-merge-idents.md) — 1.7M weekly downloads
- [@fontsource/noto-sans](https://npm.io/package/@fontsource/noto-sans.md) — 93.0K weekly downloads
- [uglifycss](https://npm.io/package/uglifycss.md) — 71.6K weekly downloads
- [mat4-interpolate](https://npm.io/package/mat4-interpolate.md) — 23.3K weekly downloads

## Recent versions

- 0.8.4 (latest) — 2023-10-04
- 0.8.3 — 2023-10-04
- 0.8.2 — 2023-10-04
- 0.8.1 — 2023-07-08
- 0.8.0 — 2023-01-27
- 0.7.0 — 2023-01-23
- 0.6.0 — 2023-01-22
- 0.5.0 — 2023-01-14
- 0.4.0 — 2022-07-07
- 0.3.1 — 2021-08-07
- 0.3.0 — 2021-02-27
- 0.2.0 — 2021-02-17
- 0.1.0 — 2021-02-14

## README

# Focusable Selectors

`focusable-selectors` is a micro-lib exporting an array of CSS selectors for focusable HTML elements. Figuring out which element can be focused is not always trivial and is sometimes necessary to build fully accessible widgets such as [a11y-dialog](https://github.com/KittyGiraudel/a11y-dialog).

It supports:

- All natively focusable elements,
- … and any element with the `contenteditable` attribute,
- … provided they are not disabled,
- … and do not have a negative `tabindex` attribute,
- … and do not have the [`inert` attribute](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/inert).

For a more advanced solution using JavaScript and covering more edge cases, refer to [focus-trap/tabbable](https://github.com/focus-trap/tabbable).

## Usage

```sh
npm install --save focusable-selectors
```

```js
import focusableSelectors from 'focusable-selectors'
```

To have a single CSS selector out of it, join the array with commas:

```js
const selector = selectors.join(',')
const focusableElements = document.querySelectorAll(selector)
```

## Considering styles

The “focusability” of an element is not solely based on its type, but also on its styles. A relatively straightforward solution is to use JavaScript to figure out whether focusable elements are effectively visible by checking their dimensions.

```js
function isVisible(element) {
  return Boolean(
    element.offsetWidth ||
      element.offsetHeight ||
      element.getClientRects().length
  )
}

const selector = selectors.join(',')
const focusableElements = Array.from(
  document.querySelectorAll(selector)
).filter(isVisible)
```

---
_Source: https://npm.io/package/focusable-selectors · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
