TanStack
Hotkeys API Reference

createHotkeysAttachment

ts
function createHotkeysAttachment(hotkeys, commonOptions?): Attachment<HTMLElement>;

Defined in: packages/svelte-hotkeys/src/createHotkeys.svelte.ts:152

Create an attachment for element-scoped hotkeys: chords, sequences, and app hotkeys listen on the attached element.

Parameters

hotkeys

MaybeGetter<readonly CreateHotkeyDefinition[]>

commonOptions?

MaybeGetter<CreateHotkeyCommonOptions> = {}

Returns

Attachment<HTMLElement>

Example

svelte
<script lang="ts">
  const editorKeys = createHotkeysAttachment([
    { hotkey: 'Mod+S', callback: () => save() },
    { hotkey: ['G', 'G'], callback: () => scrollToTop() },
  ])
</script>

<div tabindex="0" {@attach editorKeys}>Editor content</div>