forked from matrix/element-web
FilteredList, now being a controlled component does not need state
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
04bca93e0d
commit
662a6297e7
|
@ -252,24 +252,15 @@ class FilteredList extends React.Component {
|
||||||
constructor(props, context) {
|
constructor(props, context) {
|
||||||
super(props, context);
|
super(props, context);
|
||||||
this.onQuery = this.onQuery.bind(this);
|
this.onQuery = this.onQuery.bind(this);
|
||||||
|
|
||||||
this.state = {
|
|
||||||
query: this.props.query,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
|
||||||
if (this.state.query !== nextProps.query) this.setState({ query: nextProps.query });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onQuery(ev) {
|
onQuery(ev) {
|
||||||
this.setState({ query: ev.target.value });
|
|
||||||
if (this.props.onChange) this.props.onChange(ev.target.value);
|
if (this.props.onChange) this.props.onChange(ev.target.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
filterChildren() {
|
filterChildren() {
|
||||||
if (this.state.query) {
|
if (this.props.query) {
|
||||||
const lowerQuery = this.state.query.toLowerCase();
|
const lowerQuery = this.props.query.toLowerCase();
|
||||||
return this.props.children.filter((child) => child.key.toLowerCase().includes(lowerQuery));
|
return this.props.children.filter((child) => child.key.toLowerCase().includes(lowerQuery));
|
||||||
}
|
}
|
||||||
return this.props.children;
|
return this.props.children;
|
||||||
|
@ -279,7 +270,7 @@ class FilteredList extends React.Component {
|
||||||
return <div>
|
return <div>
|
||||||
<input size="64"
|
<input size="64"
|
||||||
onChange={this.onQuery}
|
onChange={this.onQuery}
|
||||||
value={this.state.query}
|
value={this.props.query}
|
||||||
placeholder={_t('Filter results')}
|
placeholder={_t('Filter results')}
|
||||||
className="mx_TextInputDialog_input mx_DevTools_RoomStateExplorer_query" />
|
className="mx_TextInputDialog_input mx_DevTools_RoomStateExplorer_query" />
|
||||||
{ this.filterChildren() }
|
{ this.filterChildren() }
|
||||||
|
|
Loading…
Reference in New Issue