# h5p-lib-controls

> Library for adding user input to web applications

Latest version **0.0.17** (published 2026-03-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install h5p-lib-controls
pnpm add h5p-lib-controls
yarn add h5p-lib-controls
bun add h5p-lib-controls
```

## Health

**Score 45/100 (D)** — status: stable.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.0.17 |
| Published | 2026-03-09 |
| First published | 2017-06-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 34.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Tom Arild Jakobsen |
| Maintainers | icc, fnoks, thomasmars, akmentinsm |
| Keywords | h5p, h5p-lib, keyboard |

## Links

- npm: https://www.npmjs.com/package/h5p-lib-controls
- npm.io page: https://npm.io/package/h5p-lib-controls

## Recent versions

- 0.0.17 (latest) — 2026-03-09
- 0.0.15 — 2019-10-21
- 0.0.14 — 2019-09-25
- 0.0.13 — 2019-09-23
- 0.0.12 — 2017-10-02
- 0.0.11 — 2017-09-29
- 0.0.10 — 2017-06-26
- 0.0.9 — 2017-06-22
- 0.0.8 — 2017-06-21
- 0.0.7 — 2017-06-21
- 0.0.6 — 2017-06-19
- 0.0.5 — 2017-06-19
- 0.0.4 — 2017-06-16
- 0.0.3 — 2017-06-09
- 0.0.2 — 2017-06-07
- … 1 more at https://npm.io/package/h5p-lib-controls/versions

## README

H5P Library - Controls
==========

[![Build Status](https://travis-ci.org/h5p/h5p-lib-controls.svg?branch=master)](https://travis-ci.org/h5p/h5p-lib-controls)

## Getting started

Grab all the module:
```bash
npm i --save-development h5p-lib-controls
```

Run tests:
```bash
npm test
```

Build distribution
```bash
npm run build
```

## Usage

### Keyboard navigation

To get keyboard navigation using arrow keys between elements you can do the following:

```javascript
import Controls from 'h5p-lib-controls/src/scripts/controls';
import UIKeyboard from 'h5p-lib-controls/src/scripts/ui/keyboard';

// Add support for arrow keys + HOME + END
const controls =  new Controls([new UIKeyboard()]);

// Add support for ENTER and SPACE
controls.on('select', event => console.log('user selected element', event.element));

// Add support for ESC
controls.on('close', event => console.log('perform closing action'));
```

### Moving [aria-selected]

```javascript
import Controls from 'h5p-lib-controls/src/scripts/controls';
import UIKeyboard from 'h5p-lib-controls/src/scripts/ui/keyboard';
import AriaSelected from 'h5p-lib-controls/src/scripts/aria/selected';

// this control will also apply [aria-selected="true"] on select event
const controls =  new Controls([new UIKeyboard(), new AriaSelected()]);
```

### Drag and drop

```javascript
import Controls from 'h5p-lib-controls/src/scripts/controls';
import AriaDrag from 'h5p-lib-controls/src/scripts/aria/drag';
import AriaDrop from 'h5p-lib-controls/src/scripts/aria/drop';
import UIKeyboard from 'h5p-lib-controls/src/scripts/ui/keyboard';

// trigger [aria-grabbed="true"] with keyboard
const dragControls = new Controls([new UIKeyboard(), new AriaDrag()]);

// trigger [aria-dropeffect="move"] with keyboard
const dropControls = new Controls([new UIKeyboard(), new AriaDrop()]);
```

### Using negative tabindex

By default *h5p-lib-controls* will remove `[tabindex]` from the elements that are not selected. If you instead want to use `[tabindex="-1"]`, you can do the following:

```javascript
const controls =  new Controls([new UIKeyboard()]);
controls.useNegativeTabIndex();
...
```

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