question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I want key modifiers for keyboard events.

See original GitHub issue

There 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:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
NakajimaTakuyacommented, Sep 3, 2021

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 and data-hotkeys... is also complicated. I think this is unavoidable since it is a 3rd party library. Is there still room for discussion?

0reactions
NakajimaTakuyacommented, Sep 6, 2021

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 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found