Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

space key / dispatch 'Space' #9

Closed
notYou263 opened this issue Jan 21, 2022 · 3 comments · Fixed by #10
Closed

space key / dispatch 'Space' #9

notYou263 opened this issue Jan 21, 2022 · 3 comments · Fixed by #10
Labels
enhancement New feature or request

Comments

@notYou263
Copy link

The keyboard event for space key is
KeyboardEvent: key=' ' | code='Space'

This leads to call of dispatch with key value ' ' for space key.
Mapping it to 'Space' would be great so one can use on:Space on a component as like for Enter and Escape

@metonym metonym added the enhancement New feature or request label Jan 21, 2022
@notYou263
Copy link
Author

notYou263 commented Jan 22, 2022

From Svelte documentation (https://svelte.dev/docs#run-time-svelte-createeventdispatcher)

Component events created with createEventDispatcher create a CustomEvent. These events do not bubble and are not cancellable with event.preventDefault()

However, if you pass a function which calls the original keyboard events preventDefault , you can use it from
svelte-keydown event handler. I just missed that one to prevent site scrolling on space key

Keydown.svelte

  on:keydown={(evt) => {
    let { key, target} = evt
...

  dispatch("key",   { key, preventDefault: () => evt.preventDefault() });
}

App.svelte


<Keydown
  pauseOnInput
  on:key={(e) => {
      e.detail.preventDefault()

      console.log("Keydown event, key: ", e.detail.key)
  }}
/>

something like that

@metonym
Copy link
Owner

metonym commented Jan 22, 2022

@notYou263 Nice – I think that's a separate feature request though.

@metonym
Copy link
Owner

metonym commented Jan 22, 2022

@notYou263 The on:Space is fixed in v0.4.1. I've opened #11 to track the other feature request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants