-
Notifications
You must be signed in to change notification settings - Fork 4.7k
InputControl: Ignore IME events when isPressEnterToChange
#60090
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
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
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.
I think it makes sense to add HOF, but strangely, I was unable to reproduce this problem in my environment (OS: Win11, browser: Chrome/Firefox).
In the video below, I add console.log(key) to observe the key down event of the InputControl component in trunk and start Storybook. During IME input, event.key is always "Process", including the Enter key and Esc key. In your environment, even during IME input, does event.key show the actual key?
afd2173bca8eb62b54e51c5877282267.mp4
tyxla
left a comment
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.
Code-wise this is a straightforward change and looks good, but I'll defer to @t-hamano for actually verifying it works as expected.
t-hamano
left a comment
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.
Interestingly, keyboardEvent.key seems to be different depending on the OS. I would like to introduce two resources.
https://github.com/seawind543/keydown-key
- With IME, the keyDown.key value of Chrome is different on Mac and Windows
- Mac: key ===
Enter- Windows: key ===
Process- With IME, the keyDown.key value of Chrome and FireFox are different on Mac
- FireFox key ===
Processon both Mac and Windows
As stated above, the values seem to vary depending on the OS and browser.
https://youtrack.jetbrains.com/issue/PRJ-514/IME-isnt-supported-for-Mac
It is shown that the value of event.key differs depending on the OS.
If all of these resources are correct, this issue may only occur with the Chrome browser on Mac.
In any case, the changes in this PR have no effect on Windows, so LGTM 👍
torounit
left a comment
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.
I was able to reproduce this issue on macOS 14 / Chrome, and also confirmed that it does not occur in Firefox.
bofore
before.mov
after
after.mov
😭 I'm glad we have both Win/Mac users for coverage though, thank you all for testing! |
…s#60090) * InputControl: Ignore IME events when `isPressEnterToChange` * Add changelog Co-authored-by: mirka <[email protected]> Co-authored-by: t-hamano <[email protected]> Co-authored-by: tyxla <[email protected]> Co-authored-by: torounit <[email protected]>
Follow-up to #59081
Part of #45605
What?
Ignore Enter and Esc keydowns emitted during IME composition when the
isPressEnterToChangeprop is enabled.When this prop is enabled:
onChangeevent is fired. Enter keys pressed during IME composition are not intended to commit the change in the entire input field, so they should be ignored.Why?
This was found during an audit of the components package to see if there is any keydown handling logic that doesn't ignore IME events properly. This was the only violation that I found. (There is unfiltered keydown handling logic in other components too, but they are unlikely to involve IME events.)
Testing Instructions
isPressEnterToChangeprop and reload.onChangeevent in the Actions panel.Screenshots or screencast
Before
CleanShot.2024-03-22.at.03.02.34.mp4
After
CleanShot.2024-03-22.at.03.03.36.mp4