mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-25 03:29:59 +08:00
a307a7acf7
* remove unnecessary computed props for classNames * rollback autocomplete optimization for possible css style order issue * update snapshots * remove more unnecessary computed props at Input
59 lines
1.4 KiB
TypeScript
59 lines
1.4 KiB
TypeScript
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<any>;
|
|
onSearch?: (value: string) => any;
|
|
size?: 'large' | 'default' | 'small';
|
|
disabled?: boolean;
|
|
readOnly?: boolean;
|
|
}
|
|
|
|
export default class Search extends React.Component<SearchProps, any> {
|
|
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 (
|
|
<div className={wrapperCls} style={style}>
|
|
<Input
|
|
className={prefixCls}
|
|
onPressEnter={this.onSearch}
|
|
ref={node => this.input = node}
|
|
{...others}
|
|
/>
|
|
<Icon
|
|
className={`${prefixCls}-icon`}
|
|
onClick={this.onSearch}
|
|
type="search"
|
|
/>
|
|
</div>
|
|
);
|
|
}
|
|
}
|