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.

Arrow keys with meta keys don't work as expected

See original GitHub issue
  • @testing-library/user-event version: 12.2.0
  • Testing Framework and version: jest 24.1.0
  • DOM Environment: react-dom 16.13.1

Relevant code or config

See reproduction below.

Reproduction repository

https://codesandbox.io/s/smoosh-violet-el3sh?file=/src/index.test.js

Problem description

The library doesn’t seem to support the combination of arrow keys and meta keys within an input. For instance, on Chrome, Firefox and Safari, when the cursor is at the end of the text value and you press Alt + ArrowLeft, it jumps back one word. When you press Meta + ArrowLeft, it jumps back the entire value and sets the cursor at the beginning. Same goes with ArrowRight, in the opposite direction.

For example, if I type “hello world” then hit Alt + ArrowLeft, my cursor should be right before “there” (index 6). If I hit Meta + ArrowLeft, it should be right before “hello” (index 0).

You can try this in the Browser tab.

However, the test using userEvent.type with {alt} or {meta} don’t pass (see Tests tab). It also doesn’t work with fireEvent.keyDown, but interestingly, the output is different (see failing tests).

I don’t know if these combinations are considered standard, but they do work out of the box on the major browsers, so it might be interesting to implement them.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
nickmccurdycommented, Nov 10, 2020

It may be easier to use something like this:

userEvent.type(`hello there${"{arrowleft}".repeat(5)}{backspace}`)
0reactions
sarahdayancommented, Nov 10, 2020

Totally understand that this is non-standard behavior, and doesn’t belong in the library.

@nickmccurdy In the example I gave, the way to circumvent it is to actually move the cursor manually, either by hitting ArrowLeft the right number of times (e.g., "hello there{arrowleft}{arrowleft}{arrowleft}{arrowleft}{arrowleft}{backspace}") or by setting the cursor with HTMLInputElement.setSelectionRange and triggering a click event.

Closing it, thanks for the discussion!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Backspace and arrow keys not working as expected
The backspace doesn't work, but the delete key does. The only solution I have found so far is to close all open documents...
Read more >
Arrow keys don't work after programmatically setting ListView ...
The problem comes when the user subsequently uses arrow keys to navigate through the ListView. The first up or down arrow after a...
Read more >
Arrow Keys Not Working in Excel? 5 Ways to Troubleshoot
1. Click Start and type "on screen keyboard." · 2. When you see On-Screen Keyboard appear in search results, click it. The on-screen...
Read more >
arrow keys don't work in insert mode
What's causing the behaviour. When you press the left arrow, your terminal is sending the following escape sequence: ESC O D.
Read more >
Keys not interpreted correctly under 1.14.2 - General Discussion
I'm seeing a similar issue, where the arrow keys mostly work as expected but in one particular case they don't work the same...
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