Skip to content

shortcut: get keyboard event / actual target #256

Answered by vnphanquang
moklick asked this question in Q&A
Discussion options

You must be logged in to vote

@moklick hmm, I see. thank you for the question.

shortcut is a CustomEvent, whose target is whatever node the Svelte action is placed on, so the observed behavior makes sense. For your use case we need to access the original KeyboardEvent object, which is not exposed in the current version.

How do you feel about an additional originalEvent in the event.detail object, something like this:

function onShortcut(event) {
  if (event.detail.originalEvent.target.tagName === 'INPUT') {
    ...
  }
}

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@moklick
Comment options

@vnphanquang
Comment options

@moklick
Comment options

Answer selected by vnphanquang
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
scope:shortcut @svelte-put/shortcut type:enhance
2 participants