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

Function getEventCharCode

code/composition/public/app.js:5533–5562  ·  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

5531 * @return {number} Normalized `charCode` property.
5532 */
5533function getEventCharCode(nativeEvent) {
5534 var charCode = void 0;
5535 var keyCode = nativeEvent.keyCode;
5536
5537 if ('charCode' in nativeEvent) {
5538 charCode = nativeEvent.charCode;
5539
5540 // FF does not set `charCode` for the Enter-key, check against `keyCode`.
5541 if (charCode === 0 && keyCode === 13) {
5542 charCode = 13;
5543 }
5544 } else {
5545 // IE8 does not implement `charCode`, but `keyCode` has the correct value.
5546 charCode = keyCode;
5547 }
5548
5549 // IE and Edge (on Windows) and Chrome / Safari (on Windows and Linux)
5550 // report Enter as charCode 10 when ctrl is pressed.
5551 if (charCode === 10) {
5552 charCode = 13;
5553 }
5554
5555 // Some non-printable keys are reported in `charCode`/`keyCode`, discard them.
5556 // Must not discard the (non-)printable Enter-key.
5557 if (charCode >= 32 || charCode === 13) {
5558 return charCode;
5559 }
5560
5561 return 0;
5562}
5563
5564/**
5565 * 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