You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.0 KiB

import React from 'react';
import classNames from 'classnames';
7 years ago
import Input, { InputProps } from './Input';
import Icon from '../icon';
7 years ago
export interface SearchProps extends InputProps {
onSearch?: (value: string) => any;
}
8 years ago
export default class Search extends React.Component<SearchProps, any> {
static defaultProps = {
prefixCls: 'ant-input-search',
};
input: Input;
onSearch = () => {
const { onSearch } = this.props;
if (onSearch) {
onSearch(this.input.input.value);
}
this.input.focus();
}
saveInput = (node) => {
this.input = node;
}
render() {
const { className, prefixCls, ...others } = this.props;
delete (others as any).onSearch;
const searchSuffix = (
<Icon
className={`${prefixCls}-icon`}
onClick={this.onSearch}
type="search"
/>
);
return (
<Input
onPressEnter={this.onSearch}
{...others}
className={classNames(prefixCls, className)}
suffix={searchSuffix}
ref={this.saveInput}
/>
);
}
}