-
Notifications
You must be signed in to change notification settings - Fork 47.5k
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
Composition Events(Chinese, Japanese IME) problem in controlled components(input, textarea) #8683
Comments
related to pull request #8438 |
onCompositionUpdate={(e)=>this.chInProcessing=true}
onChange={()=>{
if(this.chInProcessing){
this.chInProcessing=false;
return ;
}
}} |
@zuimeiaj this approach instantly closes the IME composition box and completely blocks all input using Google (Japanese) IME (on Ubuntu 16.04 / Chrome 63). @eyesofkids is completely right in saying "I found there are 3 different results (events fired sequence) at least." (in different browsers). There's definitely inconsistency between browser implementations as to when and how many times they fire start/change/end. This may not have any implications as regards React onChange but it's also worth mentioning that some software keyboards on mobile devices also fire composition events for autocomplete suggestions. Note that this is even with normal English input (latin characters), so the general problem isn't necessarily restricted to just Chinese Japanese etc IME composition. |
I also found that not only browser behaves differently in the sequence of emitting composition events and onInput events. The different IME may also behave differently in these events. For example, the native Apple keyboard in iOS will emit composition event after the input event. But if you use Google keyboard, the composition event will never be emitted. |
I'm going to close this as a duplicate of #3926 — but I appreciate the extra details in this issue. I'll include them into the original issue. |
Do you want to request a feature or report a bug?
both.
What is the current behavior?
There is a existed issue #3926 but it is just one of the problems in some kind of browsers.
I have uploaded the detail, demo files, test results and temporary solution in react-compositionevent
The main problem is when users type these words from IME(Chinese, Japanese or maybe Korean) and do something like search the database or filter out from some data, sometimes these functions will be unworkable. For example, if users type "ni" during the composition session, maybe it will be one of "你尼泥腻" in Chinese or one of "にニ尼煮" in Japanese. But in this moment, the
change
event also be fired. If the search or filter functions of the application are designed to be invoked whenchange
event occured, there maybe something wrong logically. These functions should be invoked after users finished the composition session.In React, there are three synthetic events -
onCompositionEnd
,onCompositionStart
andonCompositionUpdate
. If the input components(<input...>
and<textarea.../>
) are "uncontrolled", we can use them to helponChange
to capture the text correctly. The only different point is Google Chrome change its events sequence after v53. Check Cinput.js and Ctextarea.js files.But if these input components are "controlled", it will be hard to solve the problem.
Because these the
value
of a controlled component is came fromstate
. We can't modifystate
directly and the only way to update state is usingthis.setState()
to schedule update. Butthis.setState()
may be asynchronous.After test, i found different OS/browsers could have different results. I have written some code to solve it. But i thought it isn't a good solution. It uses the browser detection and two properties of the
state
object. One is for input, another is for internal functions(search, filter...etc). It can't just use one property of thestate
object because i can't stop anychange
events, state need it to update the value of the input element. If i stop some change events during composition session, i would get nothing after typing these words from IME.If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://jsfiddle.net or similar (template: https://jsfiddle.net/reactjs/69z2wepo/).
You can use online test demo: https://eyesofkids.github.io/
or use a normal input component(controlled/uncontrolled) to test.
What is the expected behavior?
The input(and textarea) controlled components in React should ensure these fired "change" and "composition" events is consistent in different browsers. I found there are 3 different results(events fired sequence) at least.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
The text was updated successfully, but these errors were encountered: