Move method & don't wastefullt create elements

Put did update with the other react interface methods & don't
bother creating the 'current_value' if we throw it away later.
pull/2362/head
David Baker 2016-09-28 11:05:14 +01:00
parent 455ee4f91b
commit 0db12fcd22
1 changed files with 11 additions and 9 deletions

View File

@ -64,6 +64,12 @@ export default class NetworkDropdown extends React.Component {
document.removeEventListener('click', this.onDocumentClick, false); document.removeEventListener('click', this.onDocumentClick, false);
} }
componentDidUpdate() {
if (this.state.expanded && this.inputTextBox) {
this.inputTextBox.focus();
}
}
onDocumentClick(ev) { onDocumentClick(ev) {
// Close the dropdown if the user clicks anywhere that isn't // Close the dropdown if the user clicks anywhere that isn't
// within our root element // within our root element
@ -181,16 +187,8 @@ export default class NetworkDropdown extends React.Component {
</div>; </div>;
} }
componentDidUpdate() {
if (this.state.expanded && this.inputTextBox) {
this.inputTextBox.focus();
}
}
render() { render() {
let current_value = this._makeMenuOption( let current_value;
this.state.selectedServer, this.state.selectedNetwork, false
);
let menu; let menu;
if (this.state.expanded) { if (this.state.expanded) {
@ -201,6 +199,10 @@ export default class NetworkDropdown extends React.Component {
current_value = <input type="text" className="mx_NetworkDropdown_networkoption" current_value = <input type="text" className="mx_NetworkDropdown_networkoption"
ref={this.collectInputTextBox} onKeyUp={this.onInputKeyUp} ref={this.collectInputTextBox} onKeyUp={this.onInputKeyUp}
/> />
} else {
current_value = this._makeMenuOption(
this.state.selectedServer, this.state.selectedNetwork, false
);
} }
return <div className="mx_NetworkDropdown" ref={this.collectRoot}> return <div className="mx_NetworkDropdown" ref={this.collectRoot}>