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

Function getEventKey

code/composition/public/app.js:5631–5658  ·  view source on GitHub ↗

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

(nativeEvent)

Source from the content-addressed store, hash-verified

5629 * @return {string} Normalized `key` property.
5630 */
5631function getEventKey(nativeEvent) {
5632 if (nativeEvent.key) {
5633 // Normalize inconsistent values reported by browsers due to
5634 // implementations of a working draft specification.
5635
5636 // FireFox implements `key` but returns `MozPrintableKey` for all
5637 // printable characters (normalized to `Unidentified`), ignore it.
5638 var key = normalizeKey[nativeEvent.key] || nativeEvent.key;
5639 if (key !== 'Unidentified') {
5640 return key;
5641 }
5642 }
5643
5644 // Browser does not implement `key`, polyfill as much of it as we can.
5645 if (nativeEvent.type === 'keypress') {
5646 var charCode = getEventCharCode(nativeEvent);
5647
5648 // The enter-key is technically both printable and non-printable and can
5649 // thus be captured by `keypress`, no other non-printable key should.
5650 return charCode === 13 ? 'Enter' : String.fromCharCode(charCode);
5651 }
5652 if (nativeEvent.type === 'keydown' || nativeEvent.type === 'keyup') {
5653 // While user keyboard layout determines the actual meaning of each
5654 // `keyCode` value, almost all function keys have a universal value.
5655 return translateToKey[nativeEvent.keyCode] || 'Unidentified';
5656 }
5657 return '';
5658}
5659
5660/**
5661 * @interface KeyboardEvent

Callers

nothing calls this directly

Calls 1

getEventCharCodeFunction · 0.70

Tested by

no test coverage detected