Skip to content

Commit

Permalink
fix: 修复autocomplete更新datasource后异常的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ShanaMaid committed Oct 31, 2018
1 parent dffb0ba commit b989819
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion components/AutoComplete/AutoComplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,22 @@ export class AutoComplete extends Component<IAutoCompleteProps, IAutoCompleteSta
options: this.props.dataSource,
show: false,
active: this.props.activeFirstOption ? 0 : -1,
value: this.props.defaultValue,
value: this.props.defaultValue!,
};

componentWillReceiveProps(netxProps: IAutoCompleteProps) {
const { dataSource } = this.props;
const { dataSource: nextDataSource } = netxProps;
if (JSON.stringify(dataSource) !== JSON.stringify(nextDataSource)) {
this.setState({
options: nextDataSource.filter((item) => {
return String(item).match(new RegExp(this.getValue()));
}),
});
}
}


onFocus: React.FormEventHandler<HTMLInputElement> = (e) => {
const {onFocus} = this.props;
if (onFocus) {
Expand Down

0 comments on commit b989819

Please sign in to comment.