mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-15 00:29:12 +08:00
08224052c8
* 修复 auto component 输入demo运行错误的问题 * Update options.tsx Remove unused key. Signed-off-by: 米家-iOS-张文锋 <zhangwfyoupu@126.com> * Update options.tsx Remove the unused param:index Signed-off-by: 米家-iOS-张文锋 <zhangwfyoupu@126.com> --------- Signed-off-by: 米家-iOS-张文锋 <zhangwfyoupu@126.com> Co-authored-by: zhangwenfeng <santcool@126.com> Co-authored-by: afc163 <afc163@gmail.com>
31 lines
727 B
TypeScript
31 lines
727 B
TypeScript
import React, { useState } from 'react';
|
|
import { AutoComplete } from 'antd';
|
|
|
|
const App: React.FC = () => {
|
|
const [options, setOptions] = useState<{ value: string; label: string }[]>([]);
|
|
|
|
const handleSearch = (value: string) => {
|
|
let res: { value: string; label: string }[] = [];
|
|
if (!value || value.indexOf('@') >= 0) {
|
|
res = [];
|
|
} else {
|
|
res = ['gmail.com', '163.com', 'qq.com'].map((domain) => ({
|
|
value: `${value}@${domain}`,
|
|
label: `${value}@${domain}`,
|
|
}));
|
|
}
|
|
setOptions(res);
|
|
};
|
|
|
|
return (
|
|
<AutoComplete
|
|
style={{ width: 200 }}
|
|
onSearch={handleSearch}
|
|
placeholder="input here"
|
|
options={options}
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default App;
|