Merge pull request #489 from aviraldg/fix-2128

Force-hide autocomplete after sending message.
This commit is contained in:
David Baker 2016-09-22 10:49:23 +01:00 committed by GitHub
commit 898fbcee30
3 changed files with 13 additions and 9 deletions

View file

@ -17,7 +17,8 @@ export default class Autocomplete extends React.Component {
super(props);
this.completionPromise = null;
this.onConfirm = this.onConfirm.bind(this);
this.hide = this.hide.bind(this);
this.onCompletionClicked = this.onCompletionClicked.bind(this);
this.state = {
// list of completionResults, each containing completions
@ -137,6 +138,10 @@ export default class Autocomplete extends React.Component {
e.preventDefault();
// selectionOffset = 0, so we don't end up completing when autocomplete is hidden
this.hide();
}
hide() {
this.setState({hide: true, selectionOffset: 0});
}
@ -152,16 +157,13 @@ export default class Autocomplete extends React.Component {
return done.promise;
}
/** called from MessageComposerInput
* @returns {boolean} whether confirmation was handled
*/
onConfirm(): boolean {
onCompletionClicked(): boolean {
if (this.countCompletions() === 0 || this.state.selectionOffset === COMPOSER_SELECTED) {
return false;
}
let selectedCompletion = this.state.completionList[this.state.selectionOffset - 1];
this.props.onConfirm(selectedCompletion.range, selectedCompletion.completion);
this.props.onConfirm(this.state.completionList[this.state.selectionOffset - 1]);
this.hide();
return true;
}
@ -199,7 +201,7 @@ export default class Autocomplete extends React.Component {
let onMouseOver = () => this.setSelection(componentPosition);
let onClick = () => {
this.setSelection(componentPosition);
this.onConfirm();
this.onCompletionClicked();
};
return React.cloneElement(completion.component, {

View file

@ -178,7 +178,7 @@ export default class MessageComposer extends React.Component {
_tryComplete(): boolean {
if (this.refs.autocomplete) {
return this.refs.autocomplete.onConfirm();
return this.refs.autocomplete.onCompletionClicked();
}
return false;
}

View file

@ -567,6 +567,8 @@ export default class MessageComposerInput extends React.Component {
editorState: this.createEditorState(),
});
this.autocomplete.hide();
return true;
}