Skip to content
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

KeyboardEvent: keyCode deprecation hints have contradicting info wrt what to use instead #33694

Closed
evaK-de opened this issue May 21, 2024 · 0 comments · Fixed by #34122
Closed
Labels
Content:WebAPI Web API docs goal: consistency (Experimental label) Issues about inconsistent/conflicting/contradictory content. help wanted If you know something about this topic, we would love your help!

Comments

@evaK-de
Copy link

evaK-de commented May 21, 2024

MDN URL

https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode

What specific section or headline is this issue about?

You should avoid using this if possible; it's been deprecated for some time. Instead, you should use KeyboardEvent.code, if it's implemented.

What information was incorrect, unhelpful, or incomplete?

The page https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode recommends using KeyboardEvent.code instead of the deprecated KeyboardEvent.keyCode:

You should avoid using this if possible; it's been deprecated for some time. Instead, you should use KeyboardEvent.code, if it's implemented.

But the overview page https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent recommends using KeyboardEvent.key in this section:
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#:~:text=KeyboardEvent.keyCode

Warning: This property is deprecated; you should use KeyboardEvent.key instead, if available.

What did you expect to see?

I would expect both places to recommend the same approach to replacing the deprecated keyCode. Maybe it would be best to explain that using key or code depends on the use case and give a very brief explanation of the difference between the two.
But if only one alternative is suggested, I'd say that in a clear majority of cases key makes more sense.

Do you have any supporting links, references, or citations?

https://blog.andri.co/022-should-i-use-ecode-or-ekey-when-handling-keyboard-events/
Nicely explains the (main?) difference between key and code

Do you have anything more you want to share?

No response

@evaK-de evaK-de added the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label May 21, 2024
@github-actions github-actions bot added the Content:WebAPI Web API docs label May 21, 2024
@Josh-Cena Josh-Cena added help wanted If you know something about this topic, we would love your help! goal: consistency (Experimental label) Issues about inconsistent/conflicting/contradictory content. and removed needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. labels Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:WebAPI Web API docs goal: consistency (Experimental label) Issues about inconsistent/conflicting/contradictory content. help wanted If you know something about this topic, we would love your help!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants