ant-design/components/auto-complete/demo/custom.md
2020-01-21 16:21:37 +08:00

1.1 KiB

order title
3
zh-CN en-US
自定义输入组件 Customize Input Component

zh-CN

自定义输入组件。

en-US

Customize Input Component

import React, { useState, FC } from 'react';

import { AutoComplete, Input } from 'antd';

const { TextArea } = Input;

const Complete: FC = () => {
  const [options, setOptions] = useState<{ value: string }[]>([]);
  const handleSearch = (value: string) => {
    setOptions(
      !value ? [] : [{ value }, { value: value + value }, { value: value + value + value }],
    );
  };

  const handleKeyPress = (ev: React.KeyboardEvent<HTMLTextAreaElement>) => {
    console.log('handleKeyPress', ev);
  };

  const onSelect = (value: string) => {
    console.log('onSelect', value);
  };

  return (
    <AutoComplete
      options={options}
      style={{ width: 200 }}
      onSelect={onSelect}
      onSearch={handleSearch}
    >
      <TextArea
        placeholder="input here"
        className="custom"
        style={{ height: 50 }}
        onKeyPress={handleKeyPress}
      />
    </AutoComplete>
  );
};

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