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

Function getEventKey

code/controlled-uncontrolled/public/app.js:4817–4844  ·  view source on GitHub ↗

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

(nativeEvent)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 1

getEventCharCodeFunction · 0.70

Tested by

no test coverage detected