onKeyPress event
Hello there, I'm trying to capture key-presses to make a gallery go left/right with the arrow keys.
In react I would do:
yet, when I do that in solidjs I don't see anything printed in the console.
I must be missing something really simple, can anyone help me out?
12 Replies
Could you add some content to the div so you can actually focus it?
@lexlohr I tried
but it still didn't send anythign to the console
Sorry, I'm on my mobile, which makes it difficult to test this myself.
thank you for taking the time to answer on your mobile 😉
so there is definitely content, and I can also see the
tabIndex="0"
being setLooks like the buttons inside might catch the focus.
mhm, if I first click on the div, and then press a button it starts to have focus and then consumes my keydown
but I don't want the use to have to click anywhere
also as soon as I click anywhere else the focus is gone again
i also tried
but that doesn't seem to be called at all
You could use actual events using on:keypress or even oncapture:keypress, if you intend to stop the event's propagation.
You might need to extend the JSX namespace to satisfy typescript: https://www.solidjs.com/docs/latest/api#special-jsx-attributes
SolidJS
Solid is a purely reactive library. It was designed from the ground up with a reactive core. It's influenced by reactive principles developed by previous libraries.
If you want to capture global key events, you need to use document.
yeah, it was the
document
vs window