You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
import { AutoComplete } from 'antd';
|
|
|
|
import React, { useState } from 'react';
|
|
|
|
|
|
|
|
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,
|
|
|
|
label: `${value}@${domain}`,
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
setOptions(res);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<AutoComplete
|
|
|
|
style={{ width: 200 }}
|
|
|
|
onSearch={handleSearch}
|
|
|
|
placeholder="input here"
|
|
|
|
options={options}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default App;
|