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
Change (deprecated) KeyboardEvent.keyCode -> KeyboardEvent.key #18530
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
event.key
is a string
type like "ArrowUp"
, so I think you'll also need to update src/key-codes.js
(or maybe make a src/keys.js
: P)
Done! Should I be concerned that no test failed :/ Swapped out KeyCodes to be strings instead of numbers. Used the console output here: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key to get the new values |
Hmm I checked and it doesn't look concerning. I think the tests didn't fail because your changes updated the property name to be correct in the tests, and the non-test values and properties matched in the mock event objects. It looks like the spec agrees with your results https://www.w3.org/TR/uievents-key/#named-key-attribute-values |
eventObj.keyCode = KeyCodes.RIGHT_ARROW; | ||
eventObj.which = KeyCodes.RIGHT_ARROW; | ||
eventObj.key = Keys.RIGHT_ARROW; | ||
eventObj.which = Keys.RIGHT_ARROW; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spec defines which
to be a specifically numerical value. https://www.w3.org/TR/uievents/#dom-keyboardevent-which The test code should either remove which
if it is not needed, or if it is needed, the value should conform to the spec. I am not sure why this code mocks the which
property, since I don't see it used in non-test code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out keyCode
and which
might differ on some browsers. https://unixpapa.com/js/key.html
I thought it safest to keep the code check to numeric here.
Fixed in the latest patch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh that must be why it's deprecated. Thanks for the fix, there are also 3 more instances of which
in the test code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM after the last 3 which
assignments are updated
Made the changes in the other spots. Thanks for the review! |
…oject#18530) * Change KeyboardEvent.keyCode -> KeyboardEvent.key * Linter issues * Change KeyCodes enum to be strings * which fix
ampproject#18530)" This reverts commit 36fe72c.
…oject#18530) * Change KeyboardEvent.keyCode -> KeyboardEvent.key * Linter issues * Change KeyCodes enum to be strings * which fix
…oject#18530) * Change KeyboardEvent.keyCode -> KeyboardEvent.key * Linter issues * Change KeyCodes enum to be strings * which fix
Fixes #17553
KeyboardEvent.keyCode is deprecated in favor KeyboardEvent.key.
KeyboardEvent.key has broad support and a better API.
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key