-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Fixed detection of KeyboardEvents #389
Fixed detection of KeyboardEvents #389
Conversation
@zupolgec is there any way we can add a unit test for this? |
Yep, this will at least need a test |
@zupolgec Good finding but unfortunately the propose solution would introduce a worse bug. See this codepen: https://codepen.io/SimoTod/pen/ZEbOOoX (it assumes that your browser will ask you to autofill a field with name="email"). A probably better solution would be to change A comment above the changed line to explain that we need to check e.key because of a chromium bug would help. I'm not sure you can autofill a field in jest (you can look into it) but you could create an Event with the same fields as the ones generated in chromium, trigger it on an input field, mock the console.error methods and check that:
Please, make sure you run the same test on an unpatched version and you get a failure for 1). I hope it makes sense. |
@SimoTod I understand and you have a valid point. The question is: if the user is listening to I checked what other libraries are doing on autocomplete. Alpine (now) (https://codepen.io/zupolgec/pen/YzyWxPK) Opinion: almost perfect behaviour, only problem is the error Alpine (with my old proposal) (https://codepen.io/zupolgec/pen/ExVygLB) Opinion: wrong, if I have a modifier it shouldn't trigger Alpine (with your proposal) (https://codepen.io/zupolgec/pen/eYpzBdY) Opinion: wrong, if I want to listen to keydown events and Chromium browsers decided that a keydown event is triggered on autocomplete, I should be able to (https://bugs.chromium.org/p/chromium/issues/detail?id=581537 is not a bug, is a "feature") Vue (https://codepen.io/zupolgec/pen/QWjEKga) Opinion: works exactly like my old proposal, so is wrong and maybe I should send this PR to them too 😀 Angular (https://codepen.io/zupolgec/pen/gOaMLPv) Opinion: that's the correct behaviour So, I updated my PR with the correct behaviour and a unit test. You can see it working here: https://codepen.io/zupolgec/pen/YzyWxPK |
It makes sense, to me the autofill is not a keypress but i didn't look into the reason why chromium sends it. If they say it's correct, I'm happy with your second proposal. I do think Vue is wrong and angular right so good job, thanks for looking into it. One final thing, i think you still get an error in console when you have multiple modifiers (like keydown.cmd.e). |
There are no issues with multiple modifiers since the fake |
cool 👍 |
I moved the fix inside the |
Great work on this. Thank you! |
Chrome and Safari (and, I suppose, all Chromium and Webkit browsers) have this behaviour where an Event (not a KeyboardEvent) with type "keydown" (and another with "keyup") is triggered on autocomplete input.
https://bugs.chromium.org/p/chromium/issues/detail?id=581537
This fix updates the
isKeyEvent
function by adding a check on the Event object type, and accepting onlyKeyboardEvent
. This solves a problem of ghost key events that don't have a type property and cause an error whenkeyToModifier
is called withundefined
argument.The first attempt to solve this was by fixing the
keyToModifier
function (zupolgec@2a1f807), but since theisListeningForASpecificKeyThatHasntBeenPressed
function is doing nothing on such fake Events, I thought that this is the best solution.