-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix(select): Allow non-english characters for keyboard selection. #8893
fix(select): Allow non-english characters for keyboard selection. #8893
Conversation
@ThomasBurleson Not sure who would be best to review this besides yourself. |
Your PR improves the interaction, and should probably go through, but I'm going to be honest, I'm not sure how I feel about keyCode. We're translating keyCode to map to character, but I've seen bad results with different operating systems and browsers. keyCode looks deprecated as well, unless I'm reading it wrong: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode Also, á is a Latin character, and still part of ASCII. I believe it's 160. You should put a test for Unicode. |
I looked at switching it out from using keyCode, but the replacement is supposed to be KeyboardEvent.key which as far as I can tell from the Browser Compatibility list is extremely unsupported at the moment (it has 0 support from Safari and only became available in Chrome 51...the current version). I'm certainly open to changing it if we can find a better approach, but I'm honestly thinking we might just wait until |
Darn Safari. We can use keyCode as a fallback. To be honest, keyboard input parsing is very messy. I've had to write a while service/module in the past to deal with getting the right keys. If Unicode works with keyCode, we can backlog moving to ‘key‘. I still would want to do it, since I don't like the idea of swallowing inputs. For example F11 would trigger Fullscreen and Ctrl+ would zoom in. I don't want those actions to be unavailable when somebody triggersa popup |
42e6a7a
to
bea3979
Compare
I added a unicode test. We could add a bit more logic (inside a function) which filters out some of the known ones like the function keys. I didn't think about that. I'll go ahead an work on that and see if I can add some more tests. |
You can also just only stopPropagation if a match is found. I can't think of an instance where that would have a negative effect. |
bea3979
to
6269dc5
Compare
var isNonUsefulKey = (ev.keyCode <= 31); | ||
var isLeftRightSelectKey = (ev.keyCode >= 91 && ev.keyCode <= 93); | ||
var isFnLockKey = (ev.keyCode >= 112 && ev.keyCode <= 145); | ||
|
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's safe to abort if the user press Ctrl
or Meta
or Alt
. I say this because master
locked me out from refreshing the page with Ctrl+Shift+R.
Shift
alone should be okay. I tried with with AltGr
and special Latin characters (ñÑéóö) and Alt
is true while holding AltGr
but gets set to false
when I press AltGr+N. ñ
is detected as it's own key with Alt
set to false
, so it looks safe.
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'm really confused by what you mean here 😄
You're saying we should also test for Ctrl
, Meta
or Alt
and return false too?
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.
Yes return false. So users can refresh (Ctrl+R) or ctrl/alt tab while it's open
@topherfangio - please confirm this PR is valid and still needed. Then please rebase. Thank you. |
6269dc5
to
b6dfd1a
Compare
620abd7
to
cb6d563
Compare
@ThomasBurleson Rebased and ready for a final review. I do believe it is relevant because the old functionality was
whereas the new approach says
In particular, this means that non-english characters are allowed. |
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 a lot cleaner than I remember! Just needs one more minor fix.
function shouldHandleKey(ev, $mdConstant) { | ||
var char = String.fromCharCode(ev.keyCode); | ||
var isNonUsefulKey = (ev.keyCode <= 31); | ||
|
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 need a check to make sure the user isn't performing a keyboard combination. For example, we don't want to stop users from being able to close a window (Ctrl+W) or stop a Refresh (Ctrl+R) simply because one of the combination keys is valid. Basically, we should abort if Alt, Ctrl, or Meta is being held.
This isn't the same as the isMetaKey function, which is only checking for single key presses of meta keys.
Our previous method for checking whether or not the typed character matched the first letter of an `<md-option>` was constrained to the letters `[a-zA-Z]`. Fix by allowing more characters and checking the validity via the `String.fromCharCode()` method. Add tests for Spanish and Simplified Chinese, as well as not swallowing certain keys like function keys (F3), meta, ctrl and comma (`,`). Fixes angular#7730.
cb6d563
to
969c5ba
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.
LGTM!
Our previous method for checking whether or not the typed character matched the first letter of an
<md-option>
was constrained to the letters[a-zA-Z]
.Fix by allowing more characters and checking the validity via the
String.fromCharCode()
method.Fixes #7730.