-
-
Notifications
You must be signed in to change notification settings - Fork 32.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
[TextField] Fix TextField with Chinese input method #6562
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,6 +191,9 @@ class TextField extends Component { | |
* @param {string} newValue The new value of the text field. | ||
*/ | ||
onChange: PropTypes.func, | ||
onCompositionEnd: PropTypes.func, | ||
onCompositionStart: PropTypes.func, | ||
onCompositionUpdate: PropTypes.func, | ||
/** @ignore */ | ||
onFocus: PropTypes.func, | ||
/** | ||
|
@@ -259,6 +262,7 @@ class TextField extends Component { | |
isFocused: false, | ||
errorText: undefined, | ||
hasValue: false, | ||
isTyping: false, | ||
}; | ||
|
||
componentWillMount() { | ||
|
@@ -348,6 +352,7 @@ class TextField extends Component { | |
}; | ||
|
||
handleInputChange = (event) => { | ||
if (this.state.isTyping) return; | ||
if (!this.props.hasOwnProperty('value')) { | ||
this.setState({hasValue: isValid(event.target.value)}); | ||
} | ||
|
@@ -356,6 +361,14 @@ class TextField extends Component { | |
} | ||
}; | ||
|
||
handleComposition = (event) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please could you add a TODO comment explaining why this is needed (reference the FB issue), so we can revisit and remove the workaround if / when Facebook finally fix it (there is a PR pending review since Dec 2016). |
||
switch (event.type) { | ||
case 'compositionupdate': | ||
case 'compositionstart': this.setState({isTyping: true}); break; | ||
case 'compositionend': this.setState({isTyping: false}); break; | ||
} | ||
}; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You also need to pass the event though to the appropriate composition prop if set. There are a couple of patterns for that, in use, either test if the prop is defined or (my preference) give the props empty arrow function defaults: |
||
handleInputFocus = (event) => { | ||
if (this.props.disabled) { | ||
return; | ||
|
@@ -399,6 +412,9 @@ class TextField extends Component { | |
onBlur, // eslint-disable-line no-unused-vars | ||
onChange, // eslint-disable-line no-unused-vars | ||
onFocus, // eslint-disable-line no-unused-vars | ||
onCompositionStart, // eslint-disable-line no-unused-vars | ||
onCompositionUpdate, // eslint-disable-line no-unused-vars | ||
onCompositionEnd, // eslint-disable-line no-unused-vars | ||
style, | ||
type, | ||
underlineDisabledStyle, | ||
|
@@ -444,6 +460,9 @@ class TextField extends Component { | |
disabled: this.props.disabled, | ||
onBlur: this.handleInputBlur, | ||
onChange: this.handleInputChange, | ||
onCompositionStart: this.handleComposition, | ||
onCompositionUpdate: this.handleComposition, | ||
onCompositionEnd: this.handleComposition, | ||
onFocus: this.handleInputFocus, | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can
@ignore
these.