import * as React from 'react'; import { PureComponent } from 'react'; import { Input, IInputChangeEvent } from 'zent'; export interface ISearchProps { prefixCls?: string; value?: any; placeholder?: string; keyword?: string; onChange(val: string): void; ready?: boolean; } class Search extends PureComponent { focused: boolean; inputRef = React.createRef(); constructor(props: ISearchProps) { super(props); this.changeHandler = this.changeHandler.bind(this); this.focused = false; } componentDidUpdate() { if (!this.focused && this.props.ready) { setTimeout(() => { this.inputRef.current && this.inputRef.current.focus(); }, 150); this.focused = true; } } changeHandler(ev: IInputChangeEvent) { this.props.onChange(ev.target.value); } render() { const { prefixCls, placeholder, keyword } = this.props; return ( ); } } export default Search;