Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to generate a beforeInput event for buggy composition scenarios in IE #7926

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/renderers/dom/client/eventPlugins/BeforeInputEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ function getDataFromCustomEvent(nativeEvent) {

// Track the current IME composition fallback object, if any.
var currentComposition = null;
var compositionWithoutEvent = null;

/**
* @return {?object} A SyntheticCompositionEvent.
Expand All @@ -244,6 +245,16 @@ function extractCompositionEvent(
eventType = eventTypes.compositionEnd;
}

// Even when composition events are available, in some cases IE will still not always produce these.
// Try to detect such cases so we can still produce a beforeInput event.
if (canUseCompositionEvent && !eventType && !currentComposition
&& useFallbackCompositionData && isFallbackCompositionStart(topLevelType, nativeEvent)) {
compositionWithoutEvent = FallbackCompositionState.getPooled(nativeEventTarget);
} else if (eventType || currentComposition) {
compositionWithoutEvent = null;
}


if (!eventType) {
return null;
}
Expand Down Expand Up @@ -357,6 +368,11 @@ function getFallbackBeforeInputChars(topLevelType: TopLevelTypes, nativeEvent) {
return chars;
}
return null;
} else if (compositionWithoutEvent && topLevelType === 'topKeyUp') {
var data = compositionWithoutEvent.getData();
FallbackCompositionState.release(compositionWithoutEvent);
compositionWithoutEvent = null;
return data;
}

switch (topLevelType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,34 @@ describe('BeforeInputEventPlugin', function() {
verifyEvents(events, ExpectedResult());
}

it('extract onBeforeInput from native textinput events', function() {
it('extracts onBeforeInput from native textinput events', function() {
TestEditableReactComponent(
simulateWebkit, Scenario_Composition, Expected_Webkit);
});

it('extract onBeforeInput from fallback objects', function() {
it('extracts onBeforeInput from fallback objects', function() {
TestEditableReactComponent(
simulateIE11, Scenario_Composition, Expected_IE11);
});


var buggyIEScenario = [
{run: accumulateEvents, arg: ['keydown', {keyCode: 229}]},
{run: setElementText, arg: ['。']},
{run: accumulateEvents, arg: ['keyup', {keyCode: 190}]},
];

var buggyIEScenarioExpectations = () => [
{type: null}, {type: null}, // keyDown of 229
{type: null}, // keyUp of 190
{type: ModuleCache.SyntheticInputEvent, data: {data: '。'}},
];

// In some cases, such as when entering full-width Chinese punctuation on IE with Sogou Wubi,
// the composition event is missing. In this case, we still expect a proper input event.
it('extracts onBeforeInput from buggy IE interaction without composition events', function() {
TestEditableReactComponent(
simulateIE11, buggyIEScenario, buggyIEScenarioExpectations);
});

});