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

53 lines
1.1 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';
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 {
getSuggestionContainer = () => {
2016-10-31 15:49:35 +08:00
return this.popover.getPopupDomNode();
}
2016-10-31 15:49:35 +08:00
render() {
const mention = (
<Mention
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 (
<Popover trigger="click" content={mention} title="Title" ref={popover => this.popover = popover}>
<Button type="primary">Click Me</Button>
</Popover>
);
}
}
2016-10-31 15:49:35 +08:00
ReactDOM.render(<PopoverContainer />, mountNode);
````