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

Function getEventKey

code/event-handlers/public/app.js:4823–4850  ·  view source on GitHub ↗

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

(nativeEvent)

Source from the content-addressed store, hash-verified

4821 * @return {string} Normalized `key` property.
4822 */
4823function getEventKey(nativeEvent) {
4824 if (nativeEvent.key) {
4825 // Normalize inconsistent values reported by browsers due to
4826 // implementations of a working draft specification.
4827
4828 // FireFox implements `key` but returns `MozPrintableKey` for all
4829 // printable characters (normalized to `Unidentified`), ignore it.
4830 var key = normalizeKey[nativeEvent.key] || nativeEvent.key;
4831 if (key !== 'Unidentified') {
4832 return key;
4833 }
4834 }
4835
4836 // Browser does not implement `key`, polyfill as much of it as we can.
4837 if (nativeEvent.type === 'keypress') {
4838 var charCode = getEventCharCode(nativeEvent);
4839
4840 // The enter-key is technically both printable and non-printable and can
4841 // thus be captured by `keypress`, no other non-printable key should.
4842 return charCode === 13 ? 'Enter' : String.fromCharCode(charCode);
4843 }
4844 if (nativeEvent.type === 'keydown' || nativeEvent.type === 'keyup') {
4845 // While user keyboard layout determines the actual meaning of each
4846 // `keyCode` value, almost all function keys have a universal value.
4847 return translateToKey[nativeEvent.keyCode] || 'Unidentified';
4848 }
4849 return '';
4850}
4851
4852/**
4853 * @interface KeyboardEvent

Callers

nothing calls this directly

Calls 1

getEventCharCodeFunction · 0.70

Tested by

no test coverage detected