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.
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
```tsx
|
2022-05-23 14:37:16 +08:00
|
|
|
import { Button, Popover } from 'antd';
|
2022-05-19 09:46:26 +08:00
|
|
|
import React, { useState } from 'react';
|
2018-07-29 07:34:49 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const App: React.FC = () => {
|
|
|
|
const [clicked, setClicked] = useState(false);
|
|
|
|
const [hovered, setHovered] = useState(false);
|
2018-07-29 07:34:49 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const hide = () => {
|
|
|
|
setClicked(false);
|
|
|
|
setHovered(false);
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2018-07-29 07:34:49 +08:00
|
|
|
|
2022-08-26 17:17:13 +08:00
|
|
|
const handleHoverChange = (open: boolean) => {
|
|
|
|
setHovered(open);
|
2022-05-19 09:46:26 +08:00
|
|
|
setClicked(false);
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2018-07-29 07:34:49 +08:00
|
|
|
|
2022-08-26 17:17:13 +08:00
|
|
|
const handleClickChange = (open: boolean) => {
|
2022-05-19 09:46:26 +08:00
|
|
|
setHovered(false);
|
2022-08-26 17:17:13 +08:00
|
|
|
setClicked(open);
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2018-07-29 07:34:49 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
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"
|
2022-08-26 17:17:13 +08:00
|
|
|
open={hovered}
|
|
|
|
onOpenChange={handleHoverChange}
|
2022-05-19 09:46:26 +08:00
|
|
|
>
|
2018-07-29 07:34:49 +08:00
|
|
|
<Popover
|
2022-05-19 09:46:26 +08:00
|
|
|
content={
|
|
|
|
<div>
|
|
|
|
{clickContent}
|
|
|
|
<a onClick={hide}>Close</a>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
title="Click title"
|
|
|
|
trigger="click"
|
2022-08-26 17:17:13 +08:00
|
|
|
open={clicked}
|
|
|
|
onOpenChange={handleClickChange}
|
2018-07-29 07:34:49 +08:00
|
|
|
>
|
2022-05-19 09:46:26 +08:00
|
|
|
<Button>Hover and click / 悬停并单击</Button>
|
2018-07-29 07:34:49 +08:00
|
|
|
</Popover>
|
2022-05-19 09:46:26 +08:00
|
|
|
</Popover>
|
|
|
|
);
|
|
|
|
};
|
2018-07-29 07:34:49 +08:00
|
|
|
|
2022-04-15 16:20:56 +08:00
|
|
|
export default App;
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|