Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix(ngAria): change accessibility keypress event to use event.which if it is provided #11340

Closed
wants to merge 1 commit into from

Conversation

andrewaustin
Copy link
Contributor

fix(ngAria): change accessibility keypress event to use event.which if it is provided

In Firefox, keyboard events for printable characters (e.g. space) do not use event.keyCode. Use event.which if it is provided before falling back to event.keyCode.

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.

@andrewaustin
Copy link
Contributor Author

Oops, this computer had my git email set to another one of my emails. I've signed a CLA using that other email as well.

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm.

@andrewaustin
Copy link
Contributor Author

I authored the commit, and both emails are mine.

…f it is provided

In Firefox, keyboard events for printable characters (e.g. space) do not use event.keyCode. Use event.which if it is provided before falling back to event.keyCode.
@googlebot
Copy link

CLAs look good, thanks!

@marcysutton
Copy link
Contributor

👍 nice work! Addresses #11287.

@caitp
Copy link
Contributor

caitp commented Mar 31, 2015

MDN says:

Warning: This attribute is deprecated; you should use key instead, if available.

Why do we want to use this? Then again, it says the same about keyCode

@caitp
Copy link
Contributor

caitp commented Mar 31, 2015

Okay, so DOM 3 keyboard events say you want to use key and check for values Enter or ' ' --- but the various DOM level specs are so crazy and not consistently followed, that it's really hard to come up with anything concrete as a suggestion.

I think it might be wiser to use key if it's available, though.

@andrewaustin
Copy link
Contributor Author

@caitp According to MDN, the keypress event populating key is not implemented in FF and there are a number of related bugs. (Chrome and Safari don't see to populate key at all, according to MDN compatibility tables).

See:

https://developer.mozilla.org/en-US/docs/Web/Events/keypress

and also the related bugs:

https://bugzilla.mozilla.org/show_bug.cgi?id=680830
https://bugzilla.mozilla.org/show_bug.cgi?id=900372

The API is also slightly different, which uses key values (string names) instead of keyCodes, but that is easy enough to fix.

I'm more than happy to update the PR as needed.

(It looks like DOM Level 3 events have been renamed to UI Events and are still a working draft?).

@caitp
Copy link
Contributor

caitp commented Mar 31, 2015

The API is also slightly different, which uses key values (string names) instead of keyCodes, but that is easy enough to fix.

I'm aware of that --- but I think we should go with the most consistent implementations of the most recent DOM events spec. Anyway I stopped caring, lgtm

@caitp
Copy link
Contributor

caitp commented Apr 1, 2015

FWIW, D3E KeyboardEvent is a work in progress in Blink (https://crbug.com/227231), there seem to be some issues with different vendors shuffling around different versions of the draft, which is making things difficult and slow in the classic W3 style. Blink and WebKit currently both implement a keyIdentifier (and apparently have for a number of years) in KeyboardEvent, which has been removed from D3E for some time (last seen in a 2009 version of the draft, http://www.w3.org/TR/2009/WD-DOM-Level-3-Events-20090908/)

It's kind of amazing that WK/Blink are so far behind in this area

@andrewaustin
Copy link
Contributor Author

@caitp What do you think is the best way forward is for this PR? Would you like to see me try and incorporate DOM Level 3? Or do you think this PR still looks okay?

My current understanding, based on what you've shared, is as follows:

Browser KeyboardEvent.key keyIdentifier event.which
FF (<37) x
FF (>37) x x (deprecated)
Chrome x x
Safari x x
IE9 x x
IE10 x x
IE11 x x

Source for FF: https://bugzilla.mozilla.org/show_bug.cgi?id=900372
Source for IE: https://msdn.microsoft.com/en-us/library/ie/ff974892(v=vs.85).aspx
Source for Chrome: https://crbug.com/227231

@caitp
Copy link
Contributor

caitp commented Apr 2, 2015

What you have is fine for now, I had said LGTM above

@Narretz Narretz self-assigned this Apr 20, 2015
@Narretz Narretz closed this in 249f9b8 Apr 20, 2015
netman92 pushed a commit to netman92/angular.js that referenced this pull request Aug 8, 2015
…f it is provided

In Firefox, keyboard events for printable characters (e.g. space) do not use event.keyCode.
Use event.which if it is provided before falling back to event.keyCode.

Closes angular#11340
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants