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

Function getEventCharCode

code/event-handlers/public/app.js:4725–4754  ·  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

4723 * @return {number} Normalized `charCode` property.
4724 */
4725function getEventCharCode(nativeEvent) {
4726 var charCode = void 0;
4727 var keyCode = nativeEvent.keyCode;
4728
4729 if ('charCode' in nativeEvent) {
4730 charCode = nativeEvent.charCode;
4731
4732 // FF does not set `charCode` for the Enter-key, check against `keyCode`.
4733 if (charCode === 0 && keyCode === 13) {
4734 charCode = 13;
4735 }
4736 } else {
4737 // IE8 does not implement `charCode`, but `keyCode` has the correct value.
4738 charCode = keyCode;
4739 }
4740
4741 // IE and Edge (on Windows) and Chrome / Safari (on Windows and Linux)
4742 // report Enter as charCode 10 when ctrl is pressed.
4743 if (charCode === 10) {
4744 charCode = 13;
4745 }
4746
4747 // Some non-printable keys are reported in `charCode`/`keyCode`, discard them.
4748 // Must not discard the (non-)printable Enter-key.
4749 if (charCode >= 32 || charCode === 13) {
4750 return charCode;
4751 }
4752
4753 return 0;
4754}
4755
4756/**
4757 * 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