Popover
The floating card popped by clicking or hovering.
When To Use#
A simple popup menu to provide extra information or operations.
Comparing with Tooltip
, besides information Popover
card can also provide action elements like links and buttons.
Examples
import { Popover, Button } from 'antd';
const content = (
<div>
<p>Content</p>
<p>Content</p>
</div>
);
ReactDOM.render(
<Popover content={content} title="Title">
<Button type="primary">Hover me</Button>
</Popover>
, mountNode);
import { Popover, Button } from 'antd';
const text = <span>Title</span>;
const content = (
<div>
<p>Content</p>
<p>Content</p>
</div>
);
const buttonWidth = 70;
ReactDOM.render(
<div className="demo">
<div style={{ marginLeft: buttonWidth, whiteSpace: 'nowrap' }}>
<Popover placement="topLeft" title={text} content={content} trigger="click">
<Button>TL</Button>
</Popover>
<Popover placement="top" title={text} content={content} trigger="click">
<Button>Top</Button>
</Popover>
<Popover placement="topRight" title={text} content={content} trigger="click">
<Button>TR</Button>
</Popover>
</div>
<div style={{ width: buttonWidth, float: 'left' }}>
<Popover placement="leftTop" title={text} content={content} trigger="click">
<Button>LT</Button>
</Popover>
<Popover placement="left" title={text} content={content} trigger="click">
<Button>Left</Button>
</Popover>
<Popover placement="leftBottom" title={text} content={content} trigger="click">
<Button>LB</Button>
</Popover>
</div>
<div style={{ width: buttonWidth, marginLeft: (buttonWidth * 4) + 24 }}>
<Popover placement="rightTop" title={text} content={content} trigger="click">
<Button>RT</Button>
</Popover>
<Popover placement="right" title={text} content={content} trigger="click">
<Button>Right</Button>
</Popover>
<Popover placement="rightBottom" title={text} content={content} trigger="click">
<Button>RB</Button>
</Popover>
</div>
<div style={{ marginLeft: buttonWidth, clear: 'both', whiteSpace: 'nowrap' }}>
<Popover placement="bottomLeft" title={text} content={content} trigger="click">
<Button>BL</Button>
</Popover>
<Popover placement="bottom" title={text} content={content} trigger="click">
<Button>Bottom</Button>
</Popover>
<Popover placement="bottomRight" title={text} content={content} trigger="click">
<Button>BR</Button>
</Popover>
</div>
</div>
, mountNode);
import { Popover, Button } from 'antd';
const text = <span>Title</span>;
const content = (
<div>
<p>Content</p>
<p>Content</p>
</div>
);
ReactDOM.render(
<div>
<Popover placement="topLeft" title={text} content={content}>
<Button>Align edge / 边缘对齐</Button>
</Popover>
<Popover placement="topLeft" title={text} content={content} arrowPointAtCenter>
<Button>Arrow points to center / 箭头指向中心</Button>
</Popover>
</div>
, mountNode);
import { Popover, Button } from 'antd';
const content = (
<div>
<p>Content</p>
<p>Content</p>
</div>
);
ReactDOM.render(
<div>
<Popover content={content} title="Title" trigger="hover">
<Button>Hover me</Button>
</Popover>
<Popover content={content} title="Title" trigger="focus">
<Button>Focus me</Button>
</Popover>
<Popover content={content} title="Title" trigger="click">
<Button>Click me</Button>
</Popover>
</div>
, mountNode);
import { Popover, Button } from 'antd';
class App extends React.Component {
state = {
visible: false,
}
hide = () => {
this.setState({
visible: false,
});
}
handleVisibleChange = (visible) => {
this.setState({ visible });
}
render() {
return (
<Popover
content={<a onClick={this.hide}>Close</a>}
title="Title"
trigger="click"
visible={this.state.visible}
onVisibleChange={this.handleVisibleChange}
>
<Button type="primary">Click me</Button>
</Popover>
);
}
}
ReactDOM.render(<App />, mountNode);
API#
Param | Description | Type | Default value |
---|---|---|---|
title | Title of the card | string|ReactNode | - |
content | Content of the card | string|ReactNode | - |
Consult Tooltip's documentation to find more APIs.
Note#
Please ensure that the child node of Popover
accepts onMouseEnter
, onMouseLeave
, onFocus
, onClick
events.