Skip to content

Instantly share code, notes, and snippets.

@monkindey
Created November 16, 2017 07:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monkindey/98c1f80474d540810f53f5ebf8887a0a to your computer and use it in GitHub Desktop.
Save monkindey/98c1f80474d540810f53f5ebf8887a0a to your computer and use it in GitHub Desktop.
import React from 'react';
import ReactDOM from 'react-dom';
class Issue3926 extends React.Component {
constructor() {
super();
this.handleChange = this.handleChange.bind(this);
this.handleComposition = this.handleComposition.bind(this);
this.onComposition = false;
this.state = {
value: ''
};
}
handleChange(e) {
if (!this.onComposition) {
console.log(e.type, e.target.value);
this.setState({
value: e.target.value
});
}
}
handleComposition(e) {
console.log(e.type);
if (e.type === 'compositionend') {
this.onComposition = false;
} else {
this.onComposition = true;
}
}
render() {
return (
<div>
<input
type="text"
onCompositionStart={this.handleComposition}
onCompositionUpdate={this.handleComposition}
onCompositionEnd={this.handleComposition}
onChange={this.handleChange}
/>
</div>
);
}
}
ReactDOM.render(<Issue3926 />, document.getElementById('app'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment