I want key modifiers for keyboard events.
See original GitHub issueThere are many times when we want to support keyboard operations as part of accessibility.
In such cases, you may want to include a filtering process in your code so that it only works with certain keys, as shown below.
moveTab(evt) {
switch(evt.key) {
case 'ArrowLeft':
....
case 'ArrowRight':
...
}
}
This is redundant and can easily lead to deviations from the function name. (It is tempting to disobey the teachings of Stimulus and name the function onKeydown().)
In particular, ArrowDown/ArrowUp/ArrowLeft/ArrowRight/Enter/Space/Escape/Home/End
are frequently used keys.
I think it would be ideal if we could use data-action="keydown.left->tabs#switchLeft"
like in some libraries.
Is there any consideration to implement such a modifier?
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Key values for keyboard events - Web APIs - MDN Web Docs
Modifiers are special keys which are used to generate special characters or cause special actions when used in combination with other keys.
Read more >Appendix A: Keyboard events and key identifiers - W3C
Keyboard input uses modifier keys to change the normal behavior of a key. Keys associated with modifiers generate, like other keys, ...
Read more >Capturing Keyboard Event Modifiers Across ... - Ben Nadel
Ben Nadel looks at capturing keyboard event modifiers across different operating systems in JavaScript; using the Command / Meta keys on ...
Read more >The key Event
The event-key module adds the "key" event for subscribing to keyboard events triggered by users entering specific keys. The subscription signature includes ...
Read more >Keyboard events - Windows apps | Microsoft Learn
You can detect shortcut key combinations in the KeyDown and KeyUp event handlers. When a keyboard event occurs for a non-modifier key, you...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
stimulus-hotkeys is a really great experiment! However, if I’m being honest, I’d like to see official support for it. The 3rd party library requires a set of element selector and controller names as information, which makes the specification redundant, and it lacks the concept of scope of stimulus actions. And the fact that there are two ways to control events,
data-action
anddata-hotkeys...
is also complicated. I think this is unavoidable since it is a 3rd party library. Is there still room for discussion?Thank you, I am very happy to know the different approaches. The stimulus-use implementation looks very simple, although not declarative (from the HTML side). I’ll consider hiring these if PR is not accepted 😃