Skip to content

Commit c6cdae4

Browse files
committed
fix: custom anchor ref
1 parent 79d1fcc commit c6cdae4

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/components/HoverPopup/HoverPopup.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ import './HoverPopup.scss';
99

1010
const b = cn('hover-popup');
1111

12+
const DEBOUNCE_TIMEOUT = 100;
13+
1214
interface HoverPopupProps {
1315
children: React.ReactNode;
1416
popupContent: React.ReactNode;
1517
showPopup?: boolean;
1618
offset?: [number, number];
19+
anchorRef?: React.RefObject<HTMLElement>;
1720
onShowPopup?: VoidFunction;
1821
onHidePopup?: VoidFunction;
1922
}
@@ -23,14 +26,13 @@ export const HoverPopup = ({
2326
popupContent,
2427
showPopup,
2528
offset,
29+
anchorRef,
2630
onShowPopup,
2731
onHidePopup,
2832
}: HoverPopupProps) => {
2933
const [isPopupVisible, setIsPopupVisible] = React.useState(false);
3034
const anchor = React.useRef<HTMLDivElement>(null);
3135

32-
const DEBOUNCE_TIMEOUT = 100;
33-
3436
const debouncedHandleShowPopup = React.useMemo(
3537
() =>
3638
debounce(() => {
@@ -91,7 +93,7 @@ export const HoverPopup = ({
9193
</div>
9294
<Popup
9395
contentClassName={b()}
94-
anchorRef={anchor}
96+
anchorRef={anchorRef || anchor}
9597
open={open}
9698
onMouseEnter={onPopupMouseEnter}
9799
onMouseLeave={onPopupMouseLeave}

src/containers/Storage/PDisk/PDisk.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import React from 'react';
2+
13
import {DiskStateProgressBar} from '../../../components/DiskStateProgressBar/DiskStateProgressBar';
24
import {HoverPopup} from '../../../components/HoverPopup/HoverPopup';
35
import {InternalLink} from '../../../components/InternalLink';
@@ -38,6 +40,8 @@ export const PDisk = ({
3840
const {NodeId, PDiskId} = data;
3941
const pDiskIdsDefined = valueIsDefined(NodeId) && valueIsDefined(PDiskId);
4042

43+
const anchorRef = React.useRef<HTMLDivElement>(null);
44+
4145
const renderVDisks = () => {
4246
if (!vDisks?.length) {
4347
return null;
@@ -69,14 +73,14 @@ export const PDisk = ({
6973
}
7074

7175
return (
72-
<div className={b(null, className)}>
76+
<div className={b(null, className)} ref={anchorRef}>
7377
{renderVDisks()}
7478
<HoverPopup
7579
showPopup={showPopup}
80+
anchorRef={anchorRef}
7681
onShowPopup={onShowPopup}
7782
onHidePopup={onHidePopup}
7883
popupContent={<PDiskPopup data={data} />}
79-
offset={vDisks?.length ? [0, 28] : undefined}
8084
>
8185
<InternalLink to={pDiskPath} className={b('content')}>
8286
<DiskStateProgressBar

0 commit comments

Comments
 (0)