MCPcopy Create free account
hub / github.com/Lucifier129/react-lite / getNativeBeforeInputChars

Function getNativeBeforeInputChars

examples/simple/react.js:319–363  ·  view source on GitHub ↗

* @param {string} topLevelType Record from `EventConstants`. * @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

317 * @return {?string} The string corresponding to this `beforeInput` event.
318 */
319function getNativeBeforeInputChars(topLevelType, nativeEvent) {
320 switch (topLevelType) {
321 case topLevelTypes.topCompositionEnd:
322 return getDataFromCustomEvent(nativeEvent);
323 case topLevelTypes.topKeyPress:
324 /**
325 * If native `textInput` events are available, our goal is to make
326 * use of them. However, there is a special case: the spacebar key.
327 * In Webkit, preventing default on a spacebar `textInput` event
328 * cancels character insertion, but it *also* causes the browser
329 * to fall back to its default spacebar behavior of scrolling the
330 * page.
331 *
332 * Tracking at:
333 * https://code.google.com/p/chromium/issues/detail?id=355103
334 *
335 * To avoid this issue, use the keypress event as if no `textInput`
336 * event is available.
337 */
338 var which = nativeEvent.which;
339 if (which !== SPACEBAR_CODE) {
340 return null;
341 }
342
343 hasSpaceKeypress = true;
344 return SPACEBAR_CHAR;
345
346 case topLevelTypes.topTextInput:
347 // Record the characters to be added to the DOM.
348 var chars = nativeEvent.data;
349
350 // If it's a spacebar character, assume that we have already handled
351 // it at the keypress level and bail immediately. Android Chrome
352 // doesn't give us keycodes, so we need to blacklist it.
353 if (chars === SPACEBAR_CHAR && hasSpaceKeypress) {
354 return null;
355 }
356
357 return chars;
358
359 default:
360 // For other native event types, do nothing.
361 return null;
362 }
363}
364
365/**
366 * For browsers that do not provide the `textInput` event, extract the

Callers 1

extractBeforeInputEventFunction · 0.85

Calls 1

getDataFromCustomEventFunction · 0.85

Tested by

no test coverage detected