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

Function getEventKey

code/third-party/public/app.js:4726–4753  ·  view source on GitHub ↗

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

(nativeEvent)

Source from the content-addressed store, hash-verified

4724 * @return {string} Normalized `key` property.
4725 */
4726function getEventKey(nativeEvent) {
4727 if (nativeEvent.key) {
4728 // Normalize inconsistent values reported by browsers due to
4729 // implementations of a working draft specification.
4730
4731 // FireFox implements `key` but returns `MozPrintableKey` for all
4732 // printable characters (normalized to `Unidentified`), ignore it.
4733 var key = normalizeKey[nativeEvent.key] || nativeEvent.key;
4734 if (key !== 'Unidentified') {
4735 return key;
4736 }
4737 }
4738
4739 // Browser does not implement `key`, polyfill as much of it as we can.
4740 if (nativeEvent.type === 'keypress') {
4741 var charCode = getEventCharCode(nativeEvent);
4742
4743 // The enter-key is technically both printable and non-printable and can
4744 // thus be captured by `keypress`, no other non-printable key should.
4745 return charCode === 13 ? 'Enter' : String.fromCharCode(charCode);
4746 }
4747 if (nativeEvent.type === 'keydown' || nativeEvent.type === 'keyup') {
4748 // While user keyboard layout determines the actual meaning of each
4749 // `keyCode` value, almost all function keys have a universal value.
4750 return translateToKey[nativeEvent.keyCode] || 'Unidentified';
4751 }
4752 return '';
4753}
4754
4755/**
4756 * @interface KeyboardEvent

Callers

nothing calls this directly

Calls 1

getEventCharCodeFunction · 0.70

Tested by

no test coverage detected