-
Notifications
You must be signed in to change notification settings - Fork 252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
userEvent.type: wrong keyCode for dot character? #456
Comments
KeyCode is basically not implemented at all - special chars aside. This only works for numbers and uppercase letters: Line 295 in 5feaa94
KeyCodes are subject to the keyboard layout. But I guess best approach would be to ignore those and add a mapping for all chars and functional keys as on common US-keyboards. (Maybe with an option to inject own mappings for other localizations.) So one could use num9 {key: "9", keyCode: 105}
. {key: "Shift", keyCode: 16}{key: ".", keyCode: 190}{key: "Shift", keyCode: 16}
fOo {key: "f", keyCode: 70}{key: "O", keyCode: 79}{key: "o", keyCode: 79}
& {key: "Shift", keyCode: 16}{key: "&", keyCode: 55}{key: "Shift", keyCode: 16}
bar {key: "b", keyCode: 66}{key: "a", keyCode: 65}{key: "r", keyCode: 82}
f4 {key: "f4", keyCode: 115} |
I see. Maybe it should be mentioned in the docs until something like this is implemented.
@ph-fritsche Are you saying it might be a bad idea to depend on keyCodes in my application? |
Depends on what you're trying to accomplish. |
Assuming a keyboard US layout sounds like it could cause difficult to debug issues for software tested in other regions. Is there a subset of keycodes we could support that would be consistent on any QWERTY keyboard? |
I briefly looked into this.
New properties are
|
Sounds good. Should we edit this issue to focus on supporting |
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" E.g. if you say: "I want to use the button right next to
Yes,
This issue exists only for the physical location of a button. Line 294 in 5feaa94
If we want to support that,
We could use the mapping in each direction and provide the option to use either by the user. userEvent.type(el, "a9[Semicolon][Numpad9]")
// could translate to:
{key: "a", keyCode: 65, code: "KeyA"}
{key: "9", keyCode: 57, code: "Digit9"}
{key: ";", keyCode: 186, code: "Semicolon"}
{key: "NumPad 9", keyCode: 105, code: "Numpad9"} We could use different brackets to differenciate between |
Resolved in v13.0.0 🚀 |
@testing-library/user-event
version: 12.1.6I simulate user input with
userEvent.type
:Both the dot character and the delete key seem to have the same key code:
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)The text was updated successfully, but these errors were encountered: