2019-05-17 12:05:03 +08:00
|
|
|
---
|
|
|
|
order: 3
|
|
|
|
title:
|
|
|
|
zh-CN: 自定义触发字符
|
|
|
|
en-US: Customize Trigger Token
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
通过 `prefix` 属性自定义触发字符。默认为 `@`, 可以定义为数组。
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
|
|
|
Customize Trigger Token by `prefix` props. Default to `@`, `Array<string>` also supported.
|
|
|
|
|
|
|
|
```jsx
|
|
|
|
import { Mentions } from 'antd';
|
|
|
|
|
|
|
|
const { Option } = Mentions;
|
|
|
|
|
|
|
|
const MOCK_DATA = {
|
|
|
|
'@': ['afc163', 'zombiej', 'yesmeck'],
|
|
|
|
'#': ['1.0', '2.0', '3.0'],
|
|
|
|
};
|
|
|
|
|
2022-05-17 10:19:38 +08:00
|
|
|
export default () => {
|
|
|
|
const [prefix, setPrefix] = React.useState('@');
|
2019-05-17 12:05:03 +08:00
|
|
|
|
2022-05-17 10:19:38 +08:00
|
|
|
const onSearch = (_, prefixValue) => {
|
|
|
|
setPrefix(prefixValue);
|
2019-05-17 12:05:03 +08:00
|
|
|
};
|
|
|
|
|
2022-05-17 10:19:38 +08:00
|
|
|
return (
|
|
|
|
<Mentions
|
|
|
|
style={{ width: '100%' }}
|
|
|
|
placeholder="input @ to mention people, # to mention tag"
|
|
|
|
prefix={['@', '#']}
|
|
|
|
onSearch={onSearch}
|
|
|
|
>
|
|
|
|
{(MOCK_DATA[prefix] || []).map(value => (
|
|
|
|
<Option key={value} value={value}>
|
|
|
|
{value}
|
|
|
|
</Option>
|
|
|
|
))}
|
|
|
|
</Mentions>
|
|
|
|
);
|
|
|
|
};
|
2019-05-17 12:05:03 +08:00
|
|
|
```
|