MCPcopy Create free account
hub / github.com/microsoft/SandDance / getNativeBeforeInputChars

Function getNativeBeforeInputChars

docs/external/js/react-dom.development.js:8969–9014  ·  view source on GitHub ↗

* @param {TopLevelType} topLevelType Number from `TopLevelType`. * @param {object} nativeEvent Native browser event. * @return {?string} The string corresponding to this `beforeInput` event.

(topLevelType, nativeEvent)

Source from the content-addressed store, hash-verified

8967
8968
8969 function getNativeBeforeInputChars(topLevelType, nativeEvent) {
8970 switch (topLevelType) {
8971 case TOP_COMPOSITION_END:
8972 return getDataFromCustomEvent(nativeEvent);
8973
8974 case TOP_KEY_PRESS:
8975 /**
8976 * If native `textInput` events are available, our goal is to make
8977 * use of them. However, there is a special case: the spacebar key.
8978 * In Webkit, preventing default on a spacebar `textInput` event
8979 * cancels character insertion, but it *also* causes the browser
8980 * to fall back to its default spacebar behavior of scrolling the
8981 * page.
8982 *
8983 * Tracking at:
8984 * https://code.google.com/p/chromium/issues/detail?id=355103
8985 *
8986 * To avoid this issue, use the keypress event as if no `textInput`
8987 * event is available.
8988 */
8989 var which = nativeEvent.which;
8990
8991 if (which !== SPACEBAR_CODE) {
8992 return null;
8993 }
8994
8995 hasSpaceKeypress = true;
8996 return SPACEBAR_CHAR;
8997
8998 case TOP_TEXT_INPUT:
8999 // Record the characters to be added to the DOM.
9000 var chars = nativeEvent.data; // If it's a spacebar character, assume that we have already handled
9001 // it at the keypress level and bail immediately. Android Chrome
9002 // doesn't give us keycodes, so we need to ignore it.
9003
9004 if (chars === SPACEBAR_CHAR && hasSpaceKeypress) {
9005 return null;
9006 }
9007
9008 return chars;
9009
9010 default:
9011 // For other native event types, do nothing.
9012 return null;
9013 }
9014 }
9015 /**
9016 * For browsers that do not provide the `textInput` event, extract the
9017 * appropriate string to use for SyntheticInputEvent.

Callers 1

extractBeforeInputEventFunction · 0.85

Calls 1

getDataFromCustomEventFunction · 0.85

Tested by

no test coverage detected