Opened 4 months ago
Last modified 2 months ago
#63759 new enhancement
Replace event.keyCode with event.key
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Awaiting Review | Priority: | normal |
| Severity: | minor | Version: | |
| Component: | General | Keywords: | has-patch |
| Focuses: | javascript | Cc: |
Description
Much of the scripting across non-React JS WordPress codebase uses event.keyCode to manage keyboard events. keyCode has been deprecated for many years, and we really only need to maintain backwards compatibility with this as long as we supported Internet Explorer, since IE11 continued to have buggy support for event.key.
event.code still has unreliable support, which makes this harder to implement, but event.key is widely supported.
In many cases, using event.key is more predictable, as is is less dependent on physical keyboard layout.
Change History (10)
#2
@
4 months ago
There's an entire @wordpress/keycodes package that relies on keyCode. I wonder how best to handle that. Much of the package defines constants to deal with keyCode. Do you have thoughts on what should be done with that package?
#3
@
4 months ago
@jonsurrell I'd say that having a package that depends on a deprecated property continuing to be supported is a bit risky. But it does have the advantage that it's already abstracted, so if it needs to be updated at some point, that should be pretty manageable.
I'm more concerned about the core scripting, because it's not abstracted, so if any browser actually removed keyCode, it would be a pretty big project to resolve it. I think that the abstractions in @wordpress/keycodes make that a much easier task.
I don't honestly think there's a lot of risk here - there's just too much dependence on keyCode across the web for it to be removed, but we can reduce the surface of the problem pretty easily.
This ticket was mentioned in PR #9347 on WordPress/wordpress-develop by @rishabhwp.
4 months ago
#4
- Keywords has-patch added
This ticket was mentioned in PR #9355 on WordPress/wordpress-develop by @rishabhwp.
4 months ago
#5
Trac ticket: https://core.trac.wordpress.org/ticket/63759
This PR replaces the deprecated keyCode property with key in key event handlers within the media folder.
This ticket was mentioned in PR #9357 on WordPress/wordpress-develop by @rishabhwp.
4 months ago
#6
Trac ticket: https://core.trac.wordpress.org/ticket/63759
This PR replaces the deprecated keyCode property with key in key event handlers within the admin and lib folder.
This ticket was mentioned in PR #9358 on WordPress/wordpress-develop by @rishabhwp.
4 months ago
#7
Trac ticket: https://core.trac.wordpress.org/ticket/63759
This PR replaces the deprecated keyCode property with key in key event handlers within the theme folder.
This ticket was mentioned in PR #9359 on WordPress/wordpress-develop by @rishabhwp.
4 months ago
#8
Trac ticket: https://core.trac.wordpress.org/ticket/63759
This PR replaces the deprecated keyCode property with key in key event handlers within the wp folder.
@rishabhwp commented on PR #9347:
4 months ago
#9
There are multiple files that require replacing event.keyCode with event.key. I realized that combining all changes into a single PR would result in too many file modifications, making it difficult to review and test effectively.
To keep things manageable, I’ve decided to create separate PRs for each set of changes.
I’m closing this PR for now. Please let me know if you have any concerns or suggestions.
@joedolson commented on PR #9347:
2 months ago
#10
I think that makes sense. The logical thing is probably to transform the ticket into a task and add smaller tickets to progress towards completion.
I’d like to work on this issue and submit a PR updating the codebase to use
event.keyinstead ofevent.keyCode.