TanStack
Hotkey Sequence API Reference

createHotkeySequenceAttachment

Function: createHotkeySequenceAttachment()

ts
function createHotkeySequenceAttachment(
   sequence, 
   callback, 
options): Attachment<HTMLElement>;

Defined in: packages/svelte-hotkeys/src/createHotkeySequence.svelte.ts:151

Create an attachment for element-scoped keyboard sequences.

Parameters

sequence

MaybeGetter<HotkeySequence>

callback

HotkeyCallback

options

MaybeGetter<CreateHotkeySequenceOptions> = {}

Returns

Attachment<HTMLElement>

Example

svelte
<script lang="ts">
  import { createHotkeySequenceAttachment } from '@tanstack/svelte-hotkeys'

  const vimKeys = createHotkeySequenceAttachment(['G', 'G'], () => {
    scrollToTop()
  })
</script>

<div tabindex="0" {@attach vimKeys}>
  Focus here and press g then g
</div>