2018-07-29 07:34:49 +08:00
|
|
|
---
|
2018-07-29 07:46:52 +08:00
|
|
|
order: 5
|
2018-07-29 07:34:49 +08:00
|
|
|
title:
|
|
|
|
zh-CN: 悬停点击弹出窗口
|
|
|
|
en-US: Hover with click popover
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
以下示例显示如何创建可悬停和单击的弹出窗口。
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
|
|
|
The following example shows how to create a popover which can be hovered and clicked.
|
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
```jsx
|
2018-07-29 07:34:49 +08:00
|
|
|
import { Popover, Button } from 'antd';
|
|
|
|
|
|
|
|
class App extends React.Component {
|
2018-07-29 15:23:30 +08:00
|
|
|
state = {
|
|
|
|
clicked: false,
|
|
|
|
hovered: false,
|
|
|
|
};
|
2018-07-29 07:34:49 +08:00
|
|
|
|
|
|
|
hide = () => {
|
|
|
|
this.setState({
|
2018-07-29 15:23:30 +08:00
|
|
|
clicked: false,
|
|
|
|
hovered: false,
|
2018-07-29 07:34:49 +08:00
|
|
|
});
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2018-07-29 07:34:49 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
handleHoverChange = visible => {
|
2018-07-29 07:34:49 +08:00
|
|
|
this.setState({
|
|
|
|
hovered: visible,
|
|
|
|
clicked: false,
|
|
|
|
});
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2018-07-29 07:34:49 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
handleClickChange = visible => {
|
2018-07-29 07:34:49 +08:00
|
|
|
this.setState({
|
|
|
|
clicked: visible,
|
|
|
|
hovered: false,
|
|
|
|
});
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2018-07-29 07:34:49 +08:00
|
|
|
|
|
|
|
render() {
|
2019-05-07 14:57:32 +08:00
|
|
|
const hoverContent = <div>This is hover content.</div>;
|
|
|
|
const clickContent = <div>This is click content.</div>;
|
2018-07-29 07:34:49 +08:00
|
|
|
return (
|
|
|
|
<Popover
|
|
|
|
style={{ width: 500 }}
|
|
|
|
content={hoverContent}
|
|
|
|
title="Hover title"
|
|
|
|
trigger="hover"
|
|
|
|
visible={this.state.hovered}
|
|
|
|
onVisibleChange={this.handleHoverChange}
|
|
|
|
>
|
|
|
|
<Popover
|
2019-05-07 14:57:32 +08:00
|
|
|
content={
|
2018-07-29 15:23:30 +08:00
|
|
|
<div>
|
|
|
|
{clickContent}
|
|
|
|
<a onClick={this.hide}>Close</a>
|
|
|
|
</div>
|
2019-05-07 14:57:32 +08:00
|
|
|
}
|
2018-07-29 07:34:49 +08:00
|
|
|
title="Click title"
|
|
|
|
trigger="click"
|
|
|
|
visible={this.state.clicked}
|
|
|
|
onVisibleChange={this.handleClickChange}
|
|
|
|
>
|
|
|
|
<Button>Hover and click / 悬停并单击</Button>
|
|
|
|
</Popover>
|
|
|
|
</Popover>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ReactDOM.render(<App />, mountNode);
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|