Skip to content

Commit

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

* 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 authored and gaearon committed Jun 14, 2018
1 parent bc963f3 commit 2e75779
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 @@ -200,6 +200,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 @@ -229,7 +243,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 @@ -378,7 +392,9 @@ function getFallbackBeforeInputChars(topLevelType: TopLevelType, nativeEvent) {
}
return null;
case TOP_COMPOSITION_END:
return useFallbackCompositionData ? null : nativeEvent.data;
return useFallbackCompositionData && !isUsingKoreanIME(nativeEvent)
? null
: nativeEvent.data;
default:
return null;
}
Expand Down

0 comments on commit 2e75779

Please sign in to comment.