Skip to content

Commit 5308a5c

Browse files
gabrieljablonskidanielbarion
authored andcommitted
only update active anchor if ref changed
1 parent 38ca7f2 commit 5308a5c

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/components/Tooltip/Tooltip.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ const Tooltip = ({
7777
} else {
7878
handleShow(true)
7979
}
80-
setActiveAnchor({ current: e.target as HTMLElement })
80+
setActiveAnchor((anchor) =>
81+
anchor.current === e.target ? anchor : { current: e.target as HTMLElement },
82+
)
8183
setProviderActiveAnchor({ current: e.target as HTMLElement })
8284

8385
if (tooltipHideDelayTimerRef.current) {

src/components/TooltipProvider/TooltipProvider.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ const TooltipProvider: React.FC<PropsWithChildren> = ({ children }) => {
6565

6666
const setActiveAnchor = (tooltipId: string, ref: React.RefObject<HTMLElement>) => {
6767
setActiveAnchorMap((oldMap) => {
68+
if (oldMap[tooltipId]?.current === ref.current) {
69+
return oldMap
70+
}
6871
// create new object to trigger re-render
6972
return { ...oldMap, [tooltipId]: ref }
7073
})

0 commit comments

Comments
 (0)