2017-01-13 21:19:23 +08:00
|
|
|
---
|
|
|
|
order: 3
|
|
|
|
title:
|
|
|
|
zh-CN: 自定义输入组件
|
|
|
|
en-US: Customize Input Component
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
自定义输入组件。
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
|
|
|
Customize Input Component
|
|
|
|
|
2020-01-21 16:21:37 +08:00
|
|
|
```tsx
|
2020-01-22 12:11:49 +08:00
|
|
|
import React, { useState } from 'react';
|
2017-07-12 21:43:06 +08:00
|
|
|
import { AutoComplete, Input } from 'antd';
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2017-07-12 21:43:06 +08:00
|
|
|
const { TextArea } = Input;
|
2017-01-13 21:19:23 +08:00
|
|
|
|
2020-01-21 17:14:58 +08:00
|
|
|
const Complete: React.FC = () => {
|
2020-01-22 12:11:49 +08:00
|
|
|
const [options, setOptions] = useState<{ value: string }[]>([]);
|
2020-01-21 16:21:37 +08:00
|
|
|
const handleSearch = (value: string) => {
|
|
|
|
setOptions(
|
|
|
|
!value ? [] : [{ value }, { value: value + value }, { value: value + value + value }],
|
|
|
|
);
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2017-02-19 20:12:41 +08:00
|
|
|
|
2020-01-21 16:21:37 +08:00
|
|
|
const handleKeyPress = (ev: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
|
|
|
console.log('handleKeyPress', ev);
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2017-02-19 20:12:41 +08:00
|
|
|
|
2020-01-21 16:21:37 +08:00
|
|
|
const onSelect = (value: string) => {
|
|
|
|
console.log('onSelect', value);
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2017-02-19 20:12:41 +08:00
|
|
|
|
2020-01-21 16:21:37 +08:00
|
|
|
return (
|
|
|
|
<AutoComplete
|
|
|
|
options={options}
|
|
|
|
style={{ width: 200 }}
|
|
|
|
onSelect={onSelect}
|
|
|
|
onSearch={handleSearch}
|
|
|
|
>
|
|
|
|
<TextArea
|
|
|
|
placeholder="input here"
|
|
|
|
className="custom"
|
|
|
|
style={{ height: 50 }}
|
|
|
|
onKeyPress={handleKeyPress}
|
|
|
|
/>
|
|
|
|
</AutoComplete>
|
|
|
|
);
|
|
|
|
};
|
2017-01-13 21:19:23 +08:00
|
|
|
|
2022-04-03 23:27:45 +08:00
|
|
|
export default () => <Complete />;
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|