-
Notifications
You must be signed in to change notification settings - Fork 46.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
Add KeyboardEvent.code to synthetic event #18287
Add KeyboardEvent.code to synthetic event #18287
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 223785a:
|
3cc717e
to
bbdec14
Compare
bbdec14
to
ee40b3f
Compare
@@ -16,6 +16,12 @@ import getEventModifierState from './getEventModifierState'; | |||
*/ | |||
const SyntheticKeyboardEvent = SyntheticUIEvent.extend({ | |||
key: getEventKey, | |||
code: function(event) { | |||
if (event.type === 'keydown' || event.type === 'keyup') { |
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.
Can we just have code: null
? Why does it need special handling?
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 assumed this structure had something with react internals or KeyboardEvent
specification because lower on this interface similar blocks are placed. When keypress
callback is executed without react, code
is equal to output of keydown
and keyup
events. However, if it executed with react, the output will be null
.
7b9772a
to
c4e3619
Compare
); | ||
expect(codeDown).toBe('KeyQ'); | ||
expect(codeUp).toBe('KeyQ'); | ||
expect(codePress).toBe(null); |
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.
What does the spec say it should be?
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 says it should be a valid code. For some reason onKeyPress callback do not called when dispatched without charCode! I added charCode and codePress initializes now.
6fd72ce
to
223785a
Compare
resolve #14102