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

Function getNativeBeforeInputChars

code/third-party/public/app.js:2567–2611  ·  view source on GitHub ↗

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

2565 * @return {?string} The string corresponding to this `beforeInput` event.
2566 */
2567function getNativeBeforeInputChars(topLevelType, nativeEvent) {
2568 switch (topLevelType) {
2569 case 'topCompositionEnd':
2570 return getDataFromCustomEvent(nativeEvent);
2571 case 'topKeyPress':
2572 /**
2573 * If native `textInput` events are available, our goal is to make
2574 * use of them. However, there is a special case: the spacebar key.
2575 * In Webkit, preventing default on a spacebar `textInput` event
2576 * cancels character insertion, but it *also* causes the browser
2577 * to fall back to its default spacebar behavior of scrolling the
2578 * page.
2579 *
2580 * Tracking at:
2581 * https://code.google.com/p/chromium/issues/detail?id=355103
2582 *
2583 * To avoid this issue, use the keypress event as if no `textInput`
2584 * event is available.
2585 */
2586 var which = nativeEvent.which;
2587 if (which !== SPACEBAR_CODE) {
2588 return null;
2589 }
2590
2591 hasSpaceKeypress = true;
2592 return SPACEBAR_CHAR;
2593
2594 case 'topTextInput':
2595 // Record the characters to be added to the DOM.
2596 var chars = nativeEvent.data;
2597
2598 // If it's a spacebar character, assume that we have already handled
2599 // it at the keypress level and bail immediately. Android Chrome
2600 // doesn't give us keycodes, so we need to blacklist it.
2601 if (chars === SPACEBAR_CHAR && hasSpaceKeypress) {
2602 return null;
2603 }
2604
2605 return chars;
2606
2607 default:
2608 // For other native event types, do nothing.
2609 return null;
2610 }
2611}
2612
2613/**
2614 * For browsers that do not provide the `textInput` event, extract the

Callers 1

extractBeforeInputEventFunction · 0.70

Calls 1

getDataFromCustomEventFunction · 0.70

Tested by

no test coverage detected