ant-design/components/auto-complete/demo/custom.md

58 lines
1.1 KiB
Markdown
Raw Normal View History

---
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
import { AutoComplete, Input } from 'antd';
2022-05-23 14:37:16 +08:00
import React, { useState } from 'react';
2018-06-27 15:55:04 +08:00
const { TextArea } = Input;
const App: 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
};
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
};
2020-01-21 16:21:37 +08:00
const onSelect = (value: string) => {
console.log('onSelect', value);
2019-05-07 14:57:32 +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>
);
};
export default App;
2019-05-07 14:57:32 +08:00
```