Skip to content

Commit

Permalink
Fix incorrect data in compositionend event with Korean IME on IE11 (f…
Browse files Browse the repository at this point in the history
…acebook#10217)

* Add isUsingKoreanIME function to check if a composition event was triggered by Korean IME

* Add Korean IME check alongside useFallbackCompositionData and disable fallback mode with Korean IME
  • Loading branch information
crux153 committed Apr 6, 2018
1 parent cf649b4 commit 06524c6
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions packages/react-dom/src/events/BeforeInputEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,20 @@ function getDataFromCustomEvent(nativeEvent) {
return null;
}

/**
* Check if a composition event was triggered by Korean IME.
* Our fallback mode does not work well with IE's Korean IME,
* so just use native composition events when Korean IME is used.
* Although CompositionEvent.locale property is deprecated,
* it is available in IE, where our fallback mode is enabled.
*
* @param {object} nativeEvent
* @return {boolean}
*/
function isUsingKoreanIME(nativeEvent) {
return nativeEvent.locale === 'ko';
}

// Track the current IME composition status, if any.
let isComposing = false;

Expand Down Expand Up @@ -217,7 +231,7 @@ function extractCompositionEvent(
return null;
}

if (useFallbackCompositionData) {
if (useFallbackCompositionData && !isUsingKoreanIME(nativeEvent)) {
// The current composition is stored statically and must not be
// overwritten while composition continues.
if (!isComposing && eventType === eventTypes.compositionStart) {
Expand Down Expand Up @@ -366,7 +380,9 @@ function getFallbackBeforeInputChars(topLevelType: TopLevelTypes, nativeEvent) {
}
return null;
case 'topCompositionEnd':
return useFallbackCompositionData ? null : nativeEvent.data;
return useFallbackCompositionData && !isUsingKoreanIME(nativeEvent)
? null
: nativeEvent.data;
default:
return null;
}
Expand Down

0 comments on commit 06524c6

Please sign in to comment.