Skip to main content

createHotkeysAttachment

还没翻译译自英文(tanstack.com)本页 11 段都还没译

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

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

Create an attachment for element-scoped multi-hotkey registration.

Parameters

hotkeys

MaybeGetter<CreateHotkeyDefinition[]>

commonOptions?

MaybeGetter<CreateHotkeyOptions> = {}

Returns

Attachment<HTMLElement>

Example

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

  const editorKeys = createHotkeysAttachment([
    { hotkey: 'Mod+S', callback: () => save() },
    { hotkey: 'Mod+Z', callback: () => undo() },
  ])
</script>

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

  Editor content

</div>