mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-22 22:48:29 +08:00
05a0179616
* demo(AutoComplete): opt options type by AutoCompleteProps * lint fix
42 lines
984 B
TypeScript
42 lines
984 B
TypeScript
import React, { useState } from 'react';
|
|
import { AutoComplete, Input } from 'antd';
|
|
import type { AutoCompleteProps } from 'antd';
|
|
|
|
const { TextArea } = Input;
|
|
|
|
const App: React.FC = () => {
|
|
const [options, setOptions] = useState<AutoCompleteProps['options']>([]);
|
|
|
|
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>
|
|
);
|
|
};
|
|
|
|
export default App;
|