mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-16 18:09:22 +08:00
066be35de3
* feat: support options * feat: update package * feat: update package * feat: update doc * feat: update doc * feat: update doc * feat: add test case
51 lines
1.0 KiB
Markdown
51 lines
1.0 KiB
Markdown
---
|
|
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.
|
|
|
|
```tsx
|
|
import React, { useState } from 'react';
|
|
import { Mentions } from 'antd';
|
|
|
|
const MOCK_DATA = {
|
|
'@': ['afc163', 'zombiej', 'yesmeck'],
|
|
'#': ['1.0', '2.0', '3.0'],
|
|
};
|
|
|
|
type PrefixType = keyof typeof MOCK_DATA;
|
|
|
|
const App: React.FC = () => {
|
|
const [prefix, setPrefix] = useState<PrefixType>('@');
|
|
|
|
const onSearch = (_: string, newPrefix: PrefixType) => {
|
|
setPrefix(newPrefix);
|
|
};
|
|
|
|
return (
|
|
<Mentions
|
|
style={{ width: '100%' }}
|
|
placeholder="input @ to mention people, # to mention tag"
|
|
prefix={['@', '#']}
|
|
onSearch={onSearch}
|
|
options={(MOCK_DATA[prefix] || []).map(value => ({
|
|
key: value,
|
|
value,
|
|
label: value,
|
|
}))}
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default App;
|
|
```
|