# focus-elements

> Determines which child elements are interactive according to the WHATWG spec

Latest version **1.0.0** (published 2019-06-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install focus-elements
pnpm add focus-elements
yarn add focus-elements
bun add focus-elements
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2019-06-30 |
| First published | 2019-06-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 24.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Parker Ledoux |
| Maintainers | parkerledoux |
| Keywords | focusable, focus, elements, interactive, WHATWG, accessibility, modal, focus, trap |

## Links

- npm: https://www.npmjs.com/package/focus-elements
- Repository: https://github.com/Parker-Ledoux/focus-elements
- Homepage: https://github.com/Parker-Ledoux/focus-elements#readme
- Issues: https://github.com/Parker-Ledoux/focus-elements/issues
- npm.io page: https://npm.io/package/focus-elements

## Alternatives

- [@sveltejs/kit](https://npm.io/package/@sveltejs/kit.md) — 2.2M weekly downloads
- [@atlaskit/theme](https://npm.io/package/@atlaskit/theme.md) — 402.0K weekly downloads
- [@tangle-network/brand](https://npm.io/package/@tangle-network/brand.md) — 10.0K weekly downloads
- [seneca](https://npm.io/package/seneca.md) — 7.4K weekly downloads
- [@bsb/base](https://npm.io/package/@bsb/base.md) — 7.2K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2019-06-30

## README

# focus-elements

Helpful utilities to determine which child elements are interactive according to the
[WHATWG spec](https://html.spec.whatwg.org/dev/dom.html#interactive-content).

This is especially useful to make accessible modals to:

1. Focus the first interactive element on show
2. Trap focus inside of an element (the modal)

## Installation

```
npm install focus-elements
```

## What's Included

### `getInteractiveChildElements(parent: HTMLElement): HTMLElement[]`

> Returns a collection of which child elements are interactive.

#### Usage

DOM structure

```html
<div id="123">
  <button>Hello World</button>
  <div>
    <form>
      <input type="text" />
      <input type="number" disabled />
    </form>
  </div>
  <a href="https://www.website.com">Next Page</a>
</div>
<div tabindex="0">Goodbye</div>
```

JS File

```typescript
import {getInteractiveChildElements} from 'focus-elements';

const focusElements = getInteractiveChildElements(document.getElementById('123'));
console.log(focusElements);
// Prints:
// <button>Hello World</button>
// <input type="text" />
// <a href="https://www.website.com">Next Page</a>
```

---

### `isElementInteractive(element: HTMLElement): boolean`

> Determines if a given element is interactive.

#### Usage

DOM structure

```html
<div id="123" />
<button id="abc">Hello</button>
<div tabindex="0" id="xyz">World</div>
```

JS File

```typescript
import {isElementInteractive} from 'focus-elements';

isElementInteractive(document.getElementById('123')); // false
isElementInteractive(document.getElementById('abc')); // true
isElementInteractive(document.getElementById('xyz')); // true
```

## Versioning

We use [SemVer](http://semver.org/) for versioning. For the versions available, see the
[tags on this repository](https://github.com/your/project/tags).

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