Replies: 1 comment
-
Figured it out: Add an event handler on body to react to the keydown event and trigger the corresponding event. <body _="on keydown[key is 'Escape'] trigger closeModal"> On the div though 2 event handlers are needed:
And that had me confused - only after I read the documentation thoroughly I understood that the event scoping is local by default (well, that's on me for not reading the manual first ;) ). I think it could be useful though to have another magic keyword for from: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I've been playing around with htmx and hyperscript, following the example here https://htmx.org/examples/modal-custom/
But what I'm missing there and what I can't figure out with the hyperscript documentation: How can I register keystrokes?
For example, from the docs https://hyperscript.org/docs/#event I would have thought I can use something like
on keyup[key is 'Escape'] trigger closeModal
. But when I do that nothing happens. When I replacetrigger closeModal
withlog event
I also get nothing.So, I'm a bit stuck. Is this a focus thing? That the event is not registered because it's part of the underlay, instead of the "highest" div?
I know that regular elements react to ESC by default, is there a way to replicate this with hyperscript?
Beta Was this translation helpful? Give feedback.
All reactions