ant-design/components/select/demo/combobox.md
Marius Ileana bde1711597 docs: select/demo/combobox.md - English translation (#3010)
English translation of labels and comments
2016-09-12 10:10:07 +08:00

1.3 KiB
Raw Blame History

order title
4
zh-CN en-US
智能提示 Automatic completion

zh-CN

输入框自动完成功能,下面是一个账号注册表单的例子。

推荐使用 AutoComplete 组件。

en-US

Automatic completion of select input.

Using the AutoComplete component is strongly recommended instead as it is more flexible and capable.

import { Select } from 'antd';
const Option = Select.Option;

const Test = React.createClass({
  getInitialState() {
    return {
      options: [],
    };
  },
  handleChange(value) {
    let options;
    if (!value || value.indexOf('@') >= 0) {
      options = [];
    } else {
      options = ['gmail.com', '163.com', 'qq.com'].map((domain) => {
        const email = `${value}@${domain}`;
        return <Option key={email}>{email}</Option>;
      });
    }
    this.setState({ options });
  },
  render() {
    // filterOption needs to be falseas the value is dynamically generated
    return (
      <Select combobox
        style={{ width: 200 }}
        onChange={this.handleChange}
        filterOption={false}
        placeholder="Enter the account name"
      >
        {this.state.options}
      </Select>
    );
  },
});

ReactDOM.render(<Test />, mountNode);