-
Notifications
You must be signed in to change notification settings - Fork 26.2k
refactor(platform-browser): Updates keyboard event library to support code field #46030
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
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.
Looks awesome! 👍
I'd like to propose a couple options for consideration:
- use
coderight in front of the char, i.e.keydown.alt.code.keys- this might be a bit easier to explain: thecode.is applied to the char that follows it immediately. With the current format, there might be an ambiguity on whethercodeapplies toalt(and other modifiers). - extract
codemodifier to a specially designated place:keydown.alt.keys:code, so the format of the event key remains the same and the:codeapplies to the last bit of the event key (i.e. 'keys').
| if (keycode === ' ') { | ||
| keycode = 'space'; // for readability | ||
| } else if (keycode === '.') { | ||
| keycode = 'dot'; // because '.' is used as a separator in event names | ||
| } |
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'd be awesome to detect a situation when this is actually used and produce a console.warn in the ngDevMode and suggest to use a code. approach instead (and actually deprecate those special cases and eventually remove).
d174862 to
3c7a855
Compare
99eec8e to
3c81e86
Compare
3c81e86 to
8851115
Compare
9599cbc to
6e6eb64
Compare
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.
This looks basically good to me. I have no preference on the design questions Andrew K posed above, although you'll likely want to settle that before merging. This deletes a bunch of code too, which is awesome!
reviewed-for: fw-core, size-tracking
cee7b7c to
8606fbe
Compare
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.
@jessicajaniuk the change looks great 👍 Special thanks for adding tests as well (for new and existing key patterns)!
In the current implementation the code. is a prefix for the entire event name, for ex. : code.alt.meta.KeyS. When there are some modifiers, the code. and the actual key code are separated by those modifiers. I was thinking if a possible option might be to colocate the prefix and the code like this: alt.meta.code.KeyS. WDYT?
|
@AndrewKushnir My personal preference is the proposed structure with {event}.{type}.{optional modifier}.{key/code}. To me it sort of groups more logically for me. Event / type followed by key combinations. I think it reads more clearly. |
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.
LGTM, thanks for implementing this feature! 👍
Discussed offline: I'm happy with both code.alt.KeyS and alt.code.KeyS, so my feedback is not a blocker.
One additional comment: it'd be great to find a good place in our docs to add an example of a keyboard event binding using code (and may be also describe when it makes sense to use it). This is also not a blocker and we can do it after this PR lands.
Reviewed-for: size-tracking, public-api
8606fbe to
2f04769
Compare
|
@AndrewKushnir I've updated method comments to clarify the order of what happens with the methods here and how normalization of the event string occurs for internal processing. I've also added test cases for placing |
2f04769 to
d37487f
Compare
d37487f to
8df188d
Compare
8df188d to
1e8c6d0
Compare
… code field On MacOS, pressing the alt key and another key turns into symbols, and doesn't match the intended behavior. For example, `keydown.alt.s` reports instead as `keydown.alt.ß`. We rely on the `key` field and not the `code` field, which properly reports the code for S in this case. This change adds support to allow users to specify they want to look at the `code` field instead of the `key` field within their event string. Example: `keydown.code.alt.leftshift` would only match the LeftShift and not the right shift based on code values. It would also allow the user to specify `keydown.code.alt.keys` to match S instead of ß when alt / option is pressed on MacOS and would also work on Windows. Fixes angular#45992
1e8c6d0 to
a275fb0
Compare
|
Passing TGP as of this morning. |
|
This PR was merged into the repository by commit a67a8b2. |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Right now we only ever rely on the keyboardEvent
keyfield, which islimiting to users as far as matching keyboard events across OS and
different keyboard layouts. The alt / option key behavior with MacOS
is a specific issue.
Issue Number: resolves #45992
What is the new behavior?
On MacOS, pressing the alt key and another key turns into symbols, and
doesn't match the intended behavior. For example,
keydown.alt.sreports instead as
keydown.alt.ß. We rely on thekeyfield and notthe
codefield, which properly reports the code for S in this case.This change adds support to allow users to specify they want to look at
the
codefield instead of thekeyfield within their event string.Example:
keydown.code.alt.leftshiftwould only match the LeftShift andnot the right shift based on code values. It would also allow the user
to specify
keydown.code.alt.keysto match S instead of ß when alt /option is pressed on MacOS and would also work on Windows.
The proposed structure is
{event}.{type}.{optional modifier}.{key/code}.Alternatively we could do
{event}.{optional modifier}.{type}.{key/code}.Does this PR introduce a breaking change?
Other information