Chrome processes keypress event twice when forcing element focus on keypress
Reported by
frederik...@gmail.com,
Jun 2 2017
|
||
Issue description
UserAgent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36
Steps to reproduce the problem:
1. Create a document containing nothing but the following markup:
```
<form action="/">
<input type="search" name="q">
</form>
```
2. Run the following snippet of JavaScript:
```
document.body.addEventListener('keypress', function(e) {
const inputElem = document.querySelector('input');
const previousValue = inputElem.value;
inputElem.value = previousValue + e.key;
inputElem.focus();
});
```
3. Without focussing the input, press the "a" button on your keyboard.
What is the expected behavior?
The input field should now be in a focused state and contain the letter "a".
What went wrong?
The input field contains the letter "a" twice.
Did this work before? N/A
Chrome version: 58.0.3029.110 Channel: stable
OS Version:
Flash Version: Shockwave Flash 25.0 r0
Online fiddle to reproduce the issue: https://jsfiddle.net/s1Lztfne/
Works as expected in other major browsers.
,
Jun 2 2017
,
Jun 3 2017
I'm aware of `preventDefault` and this is how I deal with it in my actual code, yet against your claims this still behaves differently in Firefox for me (both on my Linux machine as well as on BrowserStack) so I thought I'd raise this issue. Anyways thanks for looking at this. |
||
►
Sign in to add a comment |
||
Comment 1 by dtapu...@chromium.org
, Jun 2 2017