Home / Function/ getFallbackBeforeInputChars() — react Function Reference

getFallbackBeforeInputChars() — react Function Reference

Architecture documentation for the getFallbackBeforeInputChars() function in BeforeInputEventPlugin.js from the react codebase.

Function javascript CompilerCore Gating calls 3 called by 1

Entity Profile

Dependency Diagram

graph TD
  5713d1c2_b029_934d_03f6_5e773cc99a61["getFallbackBeforeInputChars()"]
  f4c86ed5_34e4_c791_b5c8_631f1402d567["BeforeInputEventPlugin.js"]
  5713d1c2_b029_934d_03f6_5e773cc99a61 -->|defined in| f4c86ed5_34e4_c791_b5c8_631f1402d567
  f74f7204_bf30_6680_43df_89af6a371b60["extractBeforeInputEvent()"]
  f74f7204_bf30_6680_43df_89af6a371b60 -->|calls| 5713d1c2_b029_934d_03f6_5e773cc99a61
  d2e09304_9a1f_4473_6d70_28a3fd6052b3["isFallbackCompositionEnd()"]
  5713d1c2_b029_934d_03f6_5e773cc99a61 -->|calls| d2e09304_9a1f_4473_6d70_28a3fd6052b3
  3bef89ae_499e_c60e_2ab7_dcb17b58a7f7["isKeypressCommand()"]
  5713d1c2_b029_934d_03f6_5e773cc99a61 -->|calls| 3bef89ae_499e_c60e_2ab7_dcb17b58a7f7
  4410dd3a_06ff_449d_a0a6_81038b04547a["isUsingKoreanIME()"]
  5713d1c2_b029_934d_03f6_5e773cc99a61 -->|calls| 4410dd3a_06ff_449d_a0a6_81038b04547a
  style 5713d1c2_b029_934d_03f6_5e773cc99a61 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/react-dom-bindings/src/events/plugins/BeforeInputEventPlugin.js lines 308–373

function getFallbackBeforeInputChars(
  domEventName: DOMEventName,
  nativeEvent: any,
): ?string {
  // If we are currently composing (IME) and using a fallback to do so,
  // try to extract the composed characters from the fallback object.
  // If composition event is available, we extract a string only at
  // compositionevent, otherwise extract it at fallback events.
  if (isComposing) {
    if (
      domEventName === 'compositionend' ||
      (!canUseCompositionEvent &&
        isFallbackCompositionEnd(domEventName, nativeEvent))
    ) {
      const chars = FallbackCompositionStateGetData();
      FallbackCompositionStateReset();
      isComposing = false;
      return chars;
    }
    return null;
  }

  switch (domEventName) {
    case 'paste':
      // If a paste event occurs after a keypress, throw out the input
      // chars. Paste events should not lead to BeforeInput events.
      return null;
    case 'keypress':
      /**
       * As of v27, Firefox may fire keypress events even when no character
       * will be inserted. A few possibilities:
       *
       * - `which` is `0`. Arrow keys, Esc key, etc.
       *
       * - `which` is the pressed key code, but no char is available.
       *   Ex: 'AltGr + d` in Polish. There is no modified character for
       *   this key combination and no character is inserted into the
       *   document, but FF fires the keypress for char code `100` anyway.
       *   No `input` event will occur.
       *
       * - `which` is the pressed key code, but a command combination is
       *   being used. Ex: `Cmd+C`. No character is inserted, and no
       *   `input` event will occur.
       */
      if (!isKeypressCommand(nativeEvent)) {
        // IE fires the `keypress` event when a user types an emoji via
        // Touch keyboard of Windows.  In such a case, the `char` property
        // holds an emoji character like `\uD83D\uDE0A`.  Because its length
        // is 2, the property `which` does not represent an emoji correctly.
        // In such a case, we directly return the `char` property instead of
        // using `which`.
        if (nativeEvent.char && nativeEvent.char.length > 1) {
          return nativeEvent.char;
        } else if (nativeEvent.which) {
          return String.fromCharCode(nativeEvent.which);
        }
      }
      return null;
    case 'compositionend':
      return useFallbackCompositionData && !isUsingKoreanIME(nativeEvent)
        ? null
        : nativeEvent.data;
    default:
      return null;
  }
}

Domain

Subdomains

Frequently Asked Questions

What does getFallbackBeforeInputChars() do?
getFallbackBeforeInputChars() is a function in the react codebase, defined in packages/react-dom-bindings/src/events/plugins/BeforeInputEventPlugin.js.
Where is getFallbackBeforeInputChars() defined?
getFallbackBeforeInputChars() is defined in packages/react-dom-bindings/src/events/plugins/BeforeInputEventPlugin.js at line 308.
What does getFallbackBeforeInputChars() call?
getFallbackBeforeInputChars() calls 3 function(s): isFallbackCompositionEnd, isKeypressCommand, isUsingKoreanIME.
What calls getFallbackBeforeInputChars()?
getFallbackBeforeInputChars() is called by 1 function(s): extractBeforeInputEvent.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free