mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-16 01:29:11 +08:00
6b658dab76
* feat: switch visible to open for Tooltip & Popover & Popconfirm * fix lint * fix: merge state * chore: Update ts part * test: add legacy test * test: fix test case Co-authored-by: 二货机器人 <smith3816@gmail.com>
70 lines
1.4 KiB
Markdown
70 lines
1.4 KiB
Markdown
---
|
|
order: 5
|
|
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.
|
|
|
|
```tsx
|
|
import { Button, Popover } from 'antd';
|
|
import React, { useState } from 'react';
|
|
|
|
const App: React.FC = () => {
|
|
const [clicked, setClicked] = useState(false);
|
|
const [hovered, setHovered] = useState(false);
|
|
|
|
const hide = () => {
|
|
setClicked(false);
|
|
setHovered(false);
|
|
};
|
|
|
|
const handleHoverChange = (open: boolean) => {
|
|
setHovered(open);
|
|
setClicked(false);
|
|
};
|
|
|
|
const handleClickChange = (open: boolean) => {
|
|
setHovered(false);
|
|
setClicked(open);
|
|
};
|
|
|
|
const hoverContent = <div>This is hover content.</div>;
|
|
const clickContent = <div>This is click content.</div>;
|
|
return (
|
|
<Popover
|
|
style={{ width: 500 }}
|
|
content={hoverContent}
|
|
title="Hover title"
|
|
trigger="hover"
|
|
open={hovered}
|
|
onOpenChange={handleHoverChange}
|
|
>
|
|
<Popover
|
|
content={
|
|
<div>
|
|
{clickContent}
|
|
<a onClick={hide}>Close</a>
|
|
</div>
|
|
}
|
|
title="Click title"
|
|
trigger="click"
|
|
open={clicked}
|
|
onOpenChange={handleClickChange}
|
|
>
|
|
<Button>Hover and click / 悬停并单击</Button>
|
|
</Popover>
|
|
</Popover>
|
|
);
|
|
};
|
|
|
|
export default App;
|
|
```
|