2016-10-31 15:49:35 +08:00
|
|
|
---
|
|
|
|
order: 6
|
|
|
|
title:
|
|
|
|
zh-CN: 建议渲染父节点
|
|
|
|
en-US: SuggestionContainer
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
指定提示渲染的父节点。
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
|
|
|
To set the container of the suggestion.
|
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
```jsx
|
2016-10-31 15:49:35 +08:00
|
|
|
import { Mention, Popover, Button } from 'antd';
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2017-05-05 14:53:46 +08:00
|
|
|
const { toString, toContentState } = Mention;
|
2016-10-31 15:49:35 +08:00
|
|
|
|
|
|
|
function onChange(editorState) {
|
|
|
|
console.log(toString(editorState));
|
|
|
|
}
|
|
|
|
|
|
|
|
function onSelect(suggestion) {
|
|
|
|
console.log('onSelect', suggestion);
|
|
|
|
}
|
|
|
|
|
2017-02-20 21:39:07 +08:00
|
|
|
class PopoverContainer extends React.Component {
|
2019-05-07 14:57:32 +08:00
|
|
|
getSuggestionContainer = () => this.popover.getPopupDomNode();
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
visibleChange = visible => {
|
2018-03-06 20:59:03 +08:00
|
|
|
if (visible && this.mention) {
|
|
|
|
this.mention.focus();
|
|
|
|
}
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2016-10-31 15:49:35 +08:00
|
|
|
render() {
|
2017-02-20 21:39:07 +08:00
|
|
|
const mention = (
|
|
|
|
<Mention
|
2019-05-07 14:57:32 +08:00
|
|
|
ref={ele => (this.mention = ele)}
|
2017-09-25 22:42:07 +08:00
|
|
|
style={{ width: '100%' }}
|
2017-02-20 21:39:07 +08:00
|
|
|
onChange={onChange}
|
2017-05-05 14:53:46 +08:00
|
|
|
defaultValue={toContentState('@afc163')}
|
2018-12-18 18:32:21 +08:00
|
|
|
defaultSuggestions={['afc163', 'benjycui', 'yiminghe', 'RaoHai', '中文', 'にほんご']}
|
2017-02-20 21:39:07 +08:00
|
|
|
onSelect={onSelect}
|
|
|
|
getSuggestionContainer={this.getSuggestionContainer}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
return (
|
2018-03-06 20:59:03 +08:00
|
|
|
<Popover
|
|
|
|
trigger="click"
|
|
|
|
content={mention}
|
|
|
|
title="Title"
|
2019-05-07 14:57:32 +08:00
|
|
|
ref={popover => (this.popover = popover)}
|
2018-03-06 20:59:03 +08:00
|
|
|
onVisibleChange={this.visibleChange}
|
|
|
|
>
|
2017-02-20 21:39:07 +08:00
|
|
|
<Button type="primary">Click Me</Button>
|
|
|
|
</Popover>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-31 15:49:35 +08:00
|
|
|
ReactDOM.render(<PopoverContainer />, mountNode);
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|