index.js 963 Bytes
Newer Older
1 2 3 4 5
import React from 'react';
import { Button, Input } from 'antd';

import styles from './index.less';

nikogu's avatar
nikogu committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
export default class SearchInput extends React.Component {
  state = {
    value: this.props.defaultValue,
  }

  handleOnChange = (e) => {
    this.setState({
      value: e.target.value,
    });
  }

  handleOnSearch = () => {
    if (this.props.onSearch) {
      this.props.onSearch(this.state.value);
    }
  }

  handleOnKey = (e) => {
    if (e.keyCode === 13) {
      this.handleOnSearch();
    }
  }

  render() {
    const { text = '搜紒', reset } = this.props;
    return (
      <div className={styles.search}>
        <Input
          onKeyDown={this.handleOnKey}
          placeholder="θ―·θΎ“ε…₯"
          size="large"
          {...reset}
          value={this.state.value}
          onChange={this.handleOnChange}
          addonAfter={<Button onClick={this.handleOnSearch} type="primary">{text}</Button>}
        />
      </div>
    );
  }
}