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

Function getEventKey

code/higher-order-components/public/app.js:5487–5514  ·  view source on GitHub ↗

* @param {object} nativeEvent Native browser event. * @return {string} Normalized `key` property.

(nativeEvent)

Source from the content-addressed store, hash-verified

5485 * @return {string} Normalized `key` property.
5486 */
5487function getEventKey(nativeEvent) {
5488 if (nativeEvent.key) {
5489 // Normalize inconsistent values reported by browsers due to
5490 // implementations of a working draft specification.
5491
5492 // FireFox implements `key` but returns `MozPrintableKey` for all
5493 // printable characters (normalized to `Unidentified`), ignore it.
5494 var key = normalizeKey[nativeEvent.key] || nativeEvent.key;
5495 if (key !== 'Unidentified') {
5496 return key;
5497 }
5498 }
5499
5500 // Browser does not implement `key`, polyfill as much of it as we can.
5501 if (nativeEvent.type === 'keypress') {
5502 var charCode = getEventCharCode(nativeEvent);
5503
5504 // The enter-key is technically both printable and non-printable and can
5505 // thus be captured by `keypress`, no other non-printable key should.
5506 return charCode === 13 ? 'Enter' : String.fromCharCode(charCode);
5507 }
5508 if (nativeEvent.type === 'keydown' || nativeEvent.type === 'keyup') {
5509 // While user keyboard layout determines the actual meaning of each
5510 // `keyCode` value, almost all function keys have a universal value.
5511 return translateToKey[nativeEvent.keyCode] || 'Unidentified';
5512 }
5513 return '';
5514}
5515
5516/**
5517 * @interface KeyboardEvent

Callers

nothing calls this directly

Calls 1

getEventCharCodeFunction · 0.70

Tested by

no test coverage detected