userEvent.type: wrong keyCode for dot character?
See original GitHub issue@testing-library/user-event
version: 12.1.6- Testing Framework and version: jest 24.9.0
- DOM Environment: jsdom 14.1.0
I simulate user input with userEvent.type
:
test("log key codes", () => {
const handleKeyUp = (event) => {
console.log({ key: event.key, keyCode: event.keyCode });
};
render(<input type="text" onKeyUp={handleKeyUp} />);
const input = screen.getByRole("textbox");
userEvent.type(input, ".");
userEvent.type(input, "{del}");
});
Both the dot character and the delete key seem to have the same key code:
console.log src/App.test.js:7
{ key: '.', keyCode: 46 }
console.log src/App.test.js:7
{ key: 'Delete', keyCode: 46 }
However, according to http://www.javascriptkeycode.com/ the dot character is supposed to have a key code of 190
.
Am I missing something or is there a bug somewhere?
Reproduction repository: https://github.com/andreaswilli/user-event-test
(created with create-react-app
and updated @testing-library/jest-dom
, @testing-library/react
and @testing-library/user-event
to most recent version)
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
user-event v13 - Testing Library
user-event is a companion library for Testing Library that provides ... <input id="my-input" type="text" value="This is a bad example" />
Read more >How to get the '.' dot character KeyPressEvent on Android ...
Please try this public boolean onKeyDown(int keyCode, KeyEvent event) { if(keyCode == KeyEvent.KEYCODE_NUMPAD_DOT) { Log.d("dot pressed" "dot presed"); } ...
Read more >UI Events - W3C
5.5.2 Input Event Order; 5.5.3 Input Event Types ... 8.3.1 How to determine keyCode for keydown and keyup events ... Type, error.
Read more >Server Administration Guide - Keycloak
In the Admin Console, two types of realms exist: ... Keycloak shows an error anytime a user attempts to update these fields.
Read more >JSDoc: Source: jquery.fancytree.js - wwWendt.de
Otherwise type of special system node: 'error', 'loading', 'nodata', ... @param {number|string} where The keyCode that would normally trigger this move, ...
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
Resolved in v13.0.0 🚀
Even with the subset you still end up with a mapping that is just probably that of a given user of yours. There is no “true”
keyCode
for a givenkey
as it is assigned by the manufacturer and although most use similar layouts it depends on the keyboard model, the driver and even OS settings.E.g. if you say: “I want to use the button right next to
[L]
” You don’t know thekey
nor thekeyCode
of that button for any given user. On an US-QWERTY-101-keyboard the button next to it is[;]
withkey=;
andkeyCode=186
. On a GER-QWERTZ-101-keyboard the button next to it is[Ö]
withkey=ö
andkeyCode=186
. But e.g. for the Logitech-G110 it haskeyCode=192
.Yes,
code
tries to bring some sanity into this mess. The key right next to[L]
will havecode=Semicolon
. But mappingcode
tokey
is still a case of probability.This issue exists only for the physical location of a button. For
key
there is no issue: https://github.com/testing-library/user-event/blob/5feaa942f46bb37d96c2f2fbeb4b33e8beff75ad/src/type.js#L294If we want to support that,
We could use the mapping in each direction and provide the option to use either by the user.
We could use different brackets to differenciate between the new usage of defining the button per
code
also allowing single key down/up events for meta keys likeShift
:a[Shift]b
and the previous usage as modifier:"a{shift}b{/shift}"