Skip to content

Conversation

@syranide
Copy link
Contributor

Implements the HTML5 key property for all browsers and normalizes behavior of those that already do, only special keys are supported. Non-special keys cannot be supported because they depend on the user's keyboard layout which cannot be determined, among other things. IE (IE9+ even) and latest FF both support the key property, but they are broken for anything but special keys.

Deprecates my PR #502, while you can listen to other values for which and keyCode, doing so relies on the user having a specific keyboard layout, which is quite simply broken behavior (and quite dangerous as it is not immediately apparent).

So all-in-all, this is pretty much as good and reliable as is humanly possible today, in any browser, and it's compatible with the future of HTML5.

Why would you want this? If you're making a webapp that should be in any way "keyboard friendly", like say, listen to enter in a field, or support pressing the arrows keys in a slideshow, then you need this, or you need to make it yourself. In my opinion, this is a hugely useful feature that is quite broken by default in browsers and something that should be solved and not thrust upon the users.

You can play with it here: http://dev.cetrez.com/jsx/ (check the console)

   raw     gz Sizes
341286  68450 build/JSXTransformer.js
135467  27432 build/jasmine.js
1033330182163 build/react-test.js
495169 103484 build/react-with-addons.js
103829  29131 build/react-with-addons.min.js
461512  96312 build/react.js
 97113  27265 build/react.min.js

   raw     gz Compared to master @ 564c8669f8ef511b9fc59e7006af5c8db30e4585
     =      = build/JSXTransformer.js
     =      = build/jasmine.js
     =      = build/react-test.js
 +1379   +551 build/react-with-addons.js
  +691   +387 build/react-with-addons.min.js
 +1379   +545 build/react.js
  +692   +381 build/react.min.js

@vjeux
Copy link
Contributor

vjeux commented Nov 25, 2013

On my mac book pro, the left command key says "OS" and the right says "ContextMenu"

http://pelegri.files.wordpress.com/2010/12/img-20101225-00014.jpg

Is this a feature or a bug?

@syranide
Copy link
Contributor Author

@vjeux Good call, I don't have access to a mac at home, it's a bug. I decided last minute to re-add those two keys, but apparently, we're better off without them as they depend on the physical keyboard type (pc/mac).

They're now removed (saving a few bytes).

yungsters added a commit that referenced this pull request Dec 23, 2013
Polyfill and normalize HTML5 "key", deprecates which and keyCode
@yungsters yungsters merged commit 9e0987c into facebook:master Dec 23, 2013
@syranide syranide deleted the html5key branch December 23, 2013 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants