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.

Add support for arrowdown and arrowup events

See original GitHub issue
  • Testing-library/user-event` version: 12.2.2
  • Testing Framework and version: jest/26.0.15
  • DOM Environment: react-dom/17.0.0

What you did:

I have a module I’m migrating from Enzyme over to testing-library, the module is a React hook that for the most part manages keyboard controls to follow accessibility guidelines for dropdown menus. Part of our tests simulate arrowdown and arrowup events while focused on list items to ensure the correct resulting focused element is obtained. We ran into this issue while trying to replicate that behavior using userEvent.

What happened:

userEvent.type only supports ArrowLeft and ArrowRight keys.

Problem description:

While trying to implement tests to replace Enzyme with testing-library we were attempting to use userEvent instead of fireEvent where ever possible, as suggested by the documentation. However, we are currently unable to replicate tests that used ArrowDown and ArrowUp as that’s just not one of the special characters supported by userEvent.type.

Suggested solution:

Add ArrowDown and ArrowUp as supported special keys for userEvent.type. Also, while reading over the documentation and through some issues, the documentation for userEvent.type seems off the mark for the variety of purposes it is used for now:

Writes text inside an or a <textarea>.

This should probably be modified to indicate that it’s used with a variety of types of elements now, or a new method could be added to userEvent meant for these situations were you aren’t necessarily “typing”.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
corymharpercommented, Dec 1, 2020

And if you would like, I’m more than willing to pick up the work for this refactoring.

0reactions
github-actions[bot]commented, Dec 3, 2020

🎉 This issue has been resolved in version 12.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Read more comments on GitHub >

github_iconTop Results From Across the Web

Detecting arrow key presses in JavaScript - Stack Overflow
To support users who are using non-qwerty/English keyboard layouts, ... "ArrowUp", or "ArrowDown" switch (key) { // change to event.key to key to...
Read more >
KeyboardEvent.key - Web APIs | MDN
These events get mapped to DOM keyboard events, and are listed among the "Virtual key ... A keyup event is fired once the...
Read more >
How to Detect Arrow Key Presses in JavaScript?
In this article, we'll look at how to detect arrow key presses in JavaScript. Use the keyCode Property. We can listen to the...
Read more >
javascript arrow down event Code Example
1. //detecting arrow key presses ; 2. document.addEventListener('keydown', function(e) { ; 3. switch (e.keyCode) { ; 4. case 37: ; 5. alert('left');.
Read more >
How To Bind Specific Keys to the Keyup and Keydown Events ...
A shortcut way to trigger events only when certain keys are pressed by adding the key name(s) with the keydown or keyup event...
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