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

Add KeyboardEvent.code to synthetic event #18287

Merged
merged 3 commits into from Apr 4, 2020

Conversation

bl00mber
Copy link
Contributor

@bl00mber bl00mber commented Mar 12, 2020

resolve #14102

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 12, 2020

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:

Sandbox Source
currying-butterfly-g8r6f Configuration

@sizebot
Copy link

sizebot commented Mar 12, 2020

No significant bundle size changes to report.

Size changes (experimental)

Generated by 🚫 dangerJS against 223785a

@sizebot
Copy link

sizebot commented Mar 12, 2020

No significant bundle size changes to report.

Size changes (stable)

Generated by 🚫 dangerJS against 223785a

@bl00mber bl00mber force-pushed the bl00mber-patch-KeyboardEvent.code branch 5 times, most recently from 3cc717e to bbdec14 Compare March 14, 2020 12:59
@bl00mber bl00mber force-pushed the bl00mber-patch-KeyboardEvent.code branch from bbdec14 to ee40b3f Compare March 14, 2020 13:00
@@ -16,6 +16,12 @@ import getEventModifierState from './getEventModifierState';
*/
const SyntheticKeyboardEvent = SyntheticUIEvent.extend({
key: getEventKey,
code: function(event) {
if (event.type === 'keydown' || event.type === 'keyup') {
Copy link
Collaborator

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?

Copy link
Contributor Author

@bl00mber bl00mber Apr 2, 2020

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.

@bl00mber bl00mber force-pushed the bl00mber-patch-KeyboardEvent.code branch from 7b9772a to c4e3619 Compare April 2, 2020 11:47
);
expect(codeDown).toBe('KeyQ');
expect(codeUp).toBe('KeyQ');
expect(codePress).toBe(null);
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

This was referenced Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Synthetic KeyboardEvent should support KeyboardEvent.code
4 participants