import React from 'react'; import classNames from 'classnames'; import Input from './Input'; import Icon from '../icon'; import splitObject from '../_util/splitObject'; export interface SearchProps { className?: string; placeholder?: string; prefixCls?: string; style?: React.CSSProperties; defaultValue?: any; value?: any; onChange?: React.FormEventHandler; onSearch?: (value: string) => any; size?: 'large' | 'default' | 'small'; disabled?: boolean; readOnly?: boolean; } export default class Search extends React.Component { static defaultProps = { prefixCls: 'ant-input-search', onSearch() {}, }; input: any; onSearch = () => { const { onSearch } = this.props; if (onSearch) { onSearch(this.input.refs.input.value); } this.input.refs.input.focus(); } render() { const [{ className, prefixCls, style }, others] = splitObject( this.props, ['className', 'prefixCls', 'style'] ); delete others.onSearch; const wrapperCls = classNames({ [`${prefixCls}-wrapper`]: true, }, className); return (
this.input = node} {...others} />
); } }