Skip to content

Commit

Permalink
Use prop instead of state for searchText
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed Oct 17, 2016
1 parent ffbaac9 commit ed061df
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions web/client/components/mapcontrols/search/SearchBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,8 @@ let SearchBar = React.createClass({
searchText: ""
};
},
getInitialState() {
return {
searchText: this.props.searchText || ""
};
},
onChange() {
var text = this.refs.input.getValue();
this.setState({searchText: text});
this.props.onSearchTextChange(text);
if (this.props.typeAhead) {
delay(() => {this.search(); }, this.props.delay);
Expand All @@ -89,7 +83,7 @@ let SearchBar = React.createClass({
render() {
// const innerGlyphicon = <Button onClick={this.search}></Button>;
const remove = <Glyphicon className="searchclear" glyph="remove" onClick={this.clearSearch}/>;
var showRemove = this.state.searchText !== "";
var showRemove = this.props.searchText !== "";
let placeholder;
if (!this.props.placeholder && this.context.messages) {
let placeholderLocMessage = LocaleUtils.getMessageById(this.context.messages, this.props.placeholderMsgId);
Expand All @@ -108,7 +102,7 @@ let SearchBar = React.createClass({
style={{
textOverflow: "ellipsis"
}}
value={this.state.searchText}
value={this.props.searchText}
ref="input"
addonAfter={showRemove ? remove : <Glyphicon glyph="search"/>}
onKeyDown={this.onKeyDown}
Expand All @@ -122,16 +116,13 @@ let SearchBar = React.createClass({
var text = this.refs.input.getValue();
if (text === undefined || text === "") {
this.props.onSearchReset();
this.setState({searchText: text });
} else {
this.props.onSearch(text);
this.setState({searchText: text });
}

},

clearSearch() {
this.setState({ searchText: ""});
this.props.onSearchReset();
}
});
Expand Down

0 comments on commit ed061df

Please sign in to comment.