2017-02-13 15:50:38 +08:00
|
|
|
---
|
|
|
|
order: 8
|
|
|
|
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.
|
|
|
|
|
2017-02-20 13:32:48 +08:00
|
|
|
````jsx
|
2017-02-13 15:50:38 +08:00
|
|
|
import { Mention } from 'antd';
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2017-02-20 13:39:01 +08:00
|
|
|
const { toString } = Mention;
|
2017-02-13 15:50:38 +08:00
|
|
|
|
|
|
|
function onChange(editorState) {
|
|
|
|
console.log(toString(editorState));
|
|
|
|
}
|
|
|
|
|
|
|
|
function onSelect(suggestion) {
|
|
|
|
console.log('onSelect', suggestion);
|
|
|
|
}
|
|
|
|
|
|
|
|
const users = ['afc163', 'benjycui', 'yiminghe', 'jljsj33', 'dqaria', 'RaoHai'];
|
|
|
|
const tags = ['1.0', '2.0', '3.0'];
|
|
|
|
|
|
|
|
class App extends React.Component {
|
2017-02-20 13:39:01 +08:00
|
|
|
constructor() {
|
2017-02-13 15:50:38 +08:00
|
|
|
super();
|
|
|
|
this.state = {
|
|
|
|
suggestions: [],
|
|
|
|
};
|
|
|
|
}
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2017-02-13 15:50:38 +08:00
|
|
|
onSearchChange = (value, trigger) => {
|
|
|
|
console.log('onSearchChange', value, trigger);
|
|
|
|
const dataSource = trigger === '@' ? users : tags;
|
|
|
|
this.setState({
|
2017-02-20 13:39:01 +08:00
|
|
|
suggestions: dataSource.filter(item => item.indexOf(value) !== -1),
|
2017-02-13 15:50:38 +08:00
|
|
|
});
|
|
|
|
}
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2017-02-13 15:50:38 +08:00
|
|
|
render() {
|
2017-02-20 13:39:01 +08:00
|
|
|
return (
|
|
|
|
<Mention
|
2017-09-25 22:42:07 +08:00
|
|
|
style={{ width: '100%' }}
|
2017-02-20 13:39:01 +08:00
|
|
|
onChange={onChange}
|
|
|
|
placeholder="input @ to mention people, # to mention tag"
|
|
|
|
prefix={['@', '#']}
|
|
|
|
onSearchChange={this.onSearchChange}
|
|
|
|
suggestions={this.state.suggestions}
|
|
|
|
onSelect={onSelect}
|
|
|
|
/>
|
|
|
|
);
|
2017-02-13 15:50:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ReactDOM.render(
|
2018-06-27 15:55:04 +08:00
|
|
|
<App />,
|
|
|
|
mountNode);
|
2017-02-13 15:50:38 +08:00
|
|
|
````
|