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

Function getEventKey

code/styling/public/app.js:5493–5520  ·  view source on GitHub ↗

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

(nativeEvent)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 1

getEventCharCodeFunction · 0.70

Tested by

no test coverage detected