MCPcopy Create free account
hub / github.com/krasimir/react-in-patterns / getEventCharCode

Function getEventCharCode

code/styling/public/app.js:5395–5424  ·  view source on GitHub ↗

* `charCode` represents the actual "character code" and is safe to use with * `String.fromCharCode`. As such, only keys that correspond to printable * characters produce a valid `charCode`, the only exception to this is Enter. * The Tab-key is considered non-printable and does not have a `charCod

(nativeEvent)

Source from the content-addressed store, hash-verified

5393 * @return {number} Normalized `charCode` property.
5394 */
5395function getEventCharCode(nativeEvent) {
5396 var charCode = void 0;
5397 var keyCode = nativeEvent.keyCode;
5398
5399 if ('charCode' in nativeEvent) {
5400 charCode = nativeEvent.charCode;
5401
5402 // FF does not set `charCode` for the Enter-key, check against `keyCode`.
5403 if (charCode === 0 && keyCode === 13) {
5404 charCode = 13;
5405 }
5406 } else {
5407 // IE8 does not implement `charCode`, but `keyCode` has the correct value.
5408 charCode = keyCode;
5409 }
5410
5411 // IE and Edge (on Windows) and Chrome / Safari (on Windows and Linux)
5412 // report Enter as charCode 10 when ctrl is pressed.
5413 if (charCode === 10) {
5414 charCode = 13;
5415 }
5416
5417 // Some non-printable keys are reported in `charCode`/`keyCode`, discard them.
5418 // Must not discard the (non-)printable Enter-key.
5419 if (charCode >= 32 || charCode === 13) {
5420 return charCode;
5421 }
5422
5423 return 0;
5424}
5425
5426/**
5427 * Normalization of deprecated HTML5 `key` values

Callers 2

getEventKeyFunction · 0.70
app.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected