-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
RichText: Fix dead key input on Windows #37777
Conversation
See #35086 In `useSpace`, don't intercept character composition that involves the Space key. For example, to input a standalone diacritic (like ´ or `) using a keyboard with dead keys, one must first press the dead key and then press the Space key. Many operating systems handle this in such a way that the second KeyboardEvent contains the property `keyCode: 229`. According to the spec, 229 allows the system to indicate that an Input Method Editor (IDE) is processing some key input. However, Windows doesn't use `keyCode: 229` for dead key composition, instead emitting an event with values `keyCode: SPACE` and `key: '´'`. That is why checking the `key` property for values other than `SPACE` is important. This should serve as a reminder that the `KeyboardEvent.keyCode` attribute is officially deprecated and that we should consider more consistent interfaces.
Size Change: +7 B (0%) Total Size: 1.13 MB
ℹ️ View Unchanged
|
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.
Tested this in Storybook on Windows, this fixes the issue for both Firefox and Chrome.
@@ -21,13 +21,38 @@ export function useSpace() { | |||
return; | |||
} | |||
|
|||
const { keyCode, altKey, metaKey, ctrlKey } = event; | |||
const { keyCode, altKey, metaKey, ctrlKey, key } = event; | |||
|
|||
// Only consider the space key without modifiers pressed. | |||
if ( keyCode !== SPACE || altKey || metaKey || ctrlKey ) { |
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.
Should we remove keyCode !== SPACE
, or will that cause problems?
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.
Right now I just patched the existing approach, so I wouldn't touch that condition. But ideally we would ditch keyCode
altogether and rely mostly on key
, which is the main non-deprecated property for this stuff. Then we'll know what shortcomings key
presents, and we could mitigate them with properties like code
, location
, etc.
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.
We should also mind the composition events.
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 just reading this interesting thread on keydown
and event.key
- https://twitter.com/jaffathecake/status/1480493537112248325.
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.
Thank you so much for looking into this issue! 🙂 Everything looks good to me.
@noisysocks should we pick this up for RC 2? |
I also support backporting this one as it's a very bad bug. |
Fixes #35086
Description
In
useSpace
, don't intercept character composition that involves the Space key. For example, to input a standalone diacritic (like ´ or `) using a keyboard with dead keys, one must first press the dead key and then press the Space key.Many operating systems handle this in such a way that the second KeyboardEvent contains the property
keyCode: 229
. According to the spec, 229 allows the system to indicate that an Input Method Editor (IDE) is processing some key input.However, Windows doesn't use
keyCode: 229
for dead key composition, instead emitting an event with valueskeyCode: SPACE
andkey: '´'
. That is why checking thekey
property for values other thanSPACE
is important.This should serve as a reminder that the
KeyboardEvent.keyCode
attribute is officially deprecated and that we should consider more consistent interfaces.cc @ellatrix @Flameeyes
How has this been tested?
See parent issue (#35086).
Screenshots
Types of changes
Bug fix (regression) affecting a particular system.
Checklist:
*.native.js
files for terms that need renaming or removal).