ant-design/components/mention/demo/popupContainer.md

66 lines
1.4 KiB
Markdown
Raw Normal View History

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.
2017-02-13 10:55:53 +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
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);
}
class PopoverContainer extends React.Component {
2018-11-28 15:00:03 +08:00
getSuggestionContainer = () => this.popover.getPopupDomNode()
2018-06-27 15:55:04 +08:00
2018-03-06 20:59:03 +08:00
visibleChange = (visible) => {
if (visible && this.mention) {
this.mention.focus();
}
}
2018-06-27 15:55:04 +08:00
2016-10-31 15:49:35 +08:00
render() {
const mention = (
<Mention
2018-03-06 20:59:03 +08:00
ref={ele => this.mention = ele}
2017-09-25 22:42:07 +08:00
style={{ width: '100%' }}
onChange={onChange}
defaultValue={toContentState('@afc163')}
suggestions={['afc163', 'benjycui', 'yiminghe', 'RaoHai', '中文', 'にほんご']}
onSelect={onSelect}
getSuggestionContainer={this.getSuggestionContainer}
/>
);
return (
2018-03-06 20:59:03 +08:00
<Popover
trigger="click"
content={mention}
title="Title"
ref={popover => this.popover = popover}
onVisibleChange={this.visibleChange}
>
<Button type="primary">Click Me</Button>
</Popover>
);
}
}
2016-10-31 15:49:35 +08:00
ReactDOM.render(<PopoverContainer />, mountNode);
````