TanStack
Hotkeys API Reference

hotkey

ts
function hotkey(hotkey, options?): <T>(proto, propertyKey, descriptor?) => void;

Defined in: decorators/hotkey.ts:29

Decorator that registers a keyboard hotkey on the element when it connects and unregisters when it disconnects. Uses HotkeyController under the hood.

Parameters

hotkey

RegisterableHotkey

The key or key combo to listen for (e.g. 'Mod+S' or a raw hotkey object).

options?

HotkeyOptions = HOTKEY_DEFAULT_OPTIONS

Optional registration options (target, platform, enabled, etc.).

Returns

A method decorator for use on LitElement methods.

<T>(proto, propertyKey, descriptor?) => void

Example

ts
class MyElement extends LitElement {
  @hotkey('Mod+S')
  save() { this.doSave() }

  @hotkey('Escape')
  close() { this.dismiss() }
}