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

Function getEventCharCode

code/higher-order-components/public/app.js:5389–5418  ·  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

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