# @shelf/hotkeys

> Hotkeys react bindings to make best user experience

Latest version **1.2.4** (published 2026-09-02) · UNLICENSED license · 0 weekly downloads

## Install

```sh
npm install @shelf/hotkeys
pnpm add @shelf/hotkeys
yarn add @shelf/hotkeys
bun add @shelf/hotkeys
```

## Health

**Score 70/100 (B)** — status: active.

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.2.4 |
| Published | 2026-09-02 |
| First published | 2023-12-15 |
| Weekly downloads | 0 |
| License | UNLICENSED |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 1 |
| Unpacked size | 6.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Shelf |
| Maintainers | el_scrambone, yuliiakovalchuk, anton-russo, gemshelf, hartzler, olesiamuller, vladgolubev, hmelenok, knupman, maaraanas, terret, chapelskyi.slavik, ahavrysh, pihorb, diana.kryskuv, andy.raven, demiansua, yuriil, vadymaslovskyi, ktv18, drews_abuse, rostyslav-horytskyi, whodeen, andriisermiahin, mpushkin, ss1l, oles.zadorozhnyy, maksym.hayovets, domovoj, vladmarchuk, ncqpele, pawelpiasecki, marianna-milovanova, andrii-nastenko, maksym.tarnavskyi, plazowicz, timorohnershelf, pietras, ulianak, vladabramov, paulchiappetta, isadovyi, denys-boichuk, theholiday, yaroslav_korolchuk, osipenks, yaroslava-tkachuk |
| Keywords | hotkeys, keyboard, react, hooks, shortcuts, hotkey, hotkeys-js, tinykeys |

## Links

- npm: https://www.npmjs.com/package/@shelf/hotkeys
- Repository: https://github.com/shelfio/libs-frontend
- Homepage: https://github.com/shelfio/libs-frontend#readme
- Issues: https://github.com/shelfio/libs-frontend/issues
- npm.io page: https://npm.io/package/@shelf/hotkeys

## Dependencies (1)

- [tinykeys](https://npm.io/package/tinykeys.md) 3.1.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.2.4 (latest) — 2026-09-02
- 1.2.3 — 2026-08-22
- 1.2.2 — 2026-08-10
- 1.2.1 — 2026-08-07
- 1.2.0 — 2026-07-06
- 1.1.2 — 2026-07-06
- 1.1.1 — 2025-09-24
- 1.1.0 — 2024-03-01
- 1.0.35 — 2024-02-29
- 1.0.34 — 2024-02-29
- 1.0.33 — 2024-02-19
- 1.0.32 — 2024-02-19
- 1.0.31 — 2024-02-19
- 1.0.30 — 2024-02-19
- 1.0.29 — 2024-02-16
- … 37 more at https://npm.io/package/@shelf/hotkeys/versions

## README

# @shelf/hotkeys

> A tiny (1Kb) set of React hotkeys utilities to make great user experience 🚀.
> Build on top of [tinykeys](https://github.com/jamiebuilds/tinykeys)

Features:

- [x] Global hotkeys
- [x] Element specific hotkeys
- [x] Modifiers support
- [x] Sequence hotkeys
- [x] Disabled on input elements by default
- [x] TypeScript support
- [x] 100% test coverage
- [x] Pure ESM build. [See](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c)

## Installation

```sh
yarn add @shelf/hotkeys react
```

## Usage

```tsx
import {Hotkey} from '@shelf/hotkeys';

function Demo() {
  return (
    <Hotkey
      binding={'$mod+a'}
      onAction={() => {
        // Do some amazing stuff 🚀
      }}
    />
  );
}
```

### Hotkey

`binding`
See [tinykeys](https://github.com/jamiebuilds/tinykeys/blob/main/README.md#commonly-used-keys-and-codes) for more info

`onAction`
Function to be called when hotkey is pressed. Accept Keyboard event as first argument.

`options.disableOnInputs`
Disable hotkey when input/textarea element is focused. Default: `true`

Examples:

```tsx
<Hotkey binding={'a'} onAction={}/> // single key case insensitive
<Hotkey binding={'1'} onAction={}/> // number keys
<Hotkey binding={'Escape'} onAction={}/>
<Hotkey binding={'Enter'} onAction={}/>

// ⌘ + a on macOS, Ctrl + a on Windows and Linux
<Hotkey binding={'$mod+a'} onAction={}/>

// sequence hotkey support by empty space
<Hotkey binding={'g i'} onAction={}/>

// combination of keys, make sure no spaces between keys
<Hotkey binding={'Control+a'} onAction={}/>

// $mod is a special key for ⌘ on macOS and Ctrl on Windows and Linux
<Hotkey binding={'$mod+a'} onAction={}/>


// Prevent default browser action opening new tab
<Hotkey binding={'$mod+T'} onAction={event => {
  event.preventDefault();
}}/>


// Enable hotkey when input/textarea element is focused
<Hotkey
  binding={'a'}
  onAction={}
  options={{
    disableOnInputs: false,
    event: 'keyup' // default is keydown
  }}
/>
```

### useHotkeys

`useHotkeys(keymap, [options], [element])` is a hook that allows you to register multiple hotkeys at once.

```tsx
import {useHotkeys} from '@shelf/hotkeys';

function Demo() {
  useHotkeys(
    {
      '$mod+a': () => {},
      'g i': () => {},
      // Do some amazing stuff 🚀
    },
    {
      disableOnInputs: false,
    }
  );

  return <div>...</div>;
}
```

## Publish

```sh
$ git checkout master
$ yarn version
$ yarn publish
$ git push origin master --tags
```

## License

MIT © [Shelf](https://shelf.io)

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