Skip to content

Commit

Permalink
fix: ensure referenceElement don't flash in the wrong position on m…
Browse files Browse the repository at this point in the history
…ount
  • Loading branch information
stipsan committed Dec 10, 2024
1 parent 9ecda33 commit c95c1c0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/core/primitives/popover/popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,11 @@ export const Popover = memo(
middleware,
placement: placementProp,
whileElementsMounted: autoUpdate,
elements: referenceElement
? {
reference: referenceElement,
}
: undefined,
})

const referenceHidden = middlewareData.hide?.referenceHidden
Expand Down Expand Up @@ -383,10 +388,6 @@ export const Popover = memo(
}
}, [update, updateRef])

useEffect(() => {
if (referenceElement) refs.setReference(referenceElement)
}, [referenceElement, refs])

if (disabled) {
return childProp || <></>
}
Expand Down
4 changes: 1 addition & 3 deletions src/core/primitives/tooltip/tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export const Tooltip = forwardRef(function Tooltip(
middleware,
placement: placementProp,
whileElementsMounted: autoUpdate,
elements: {reference: referenceElement},
})

const arrowX = middlewareData.arrow?.x
Expand Down Expand Up @@ -273,9 +274,6 @@ export const Tooltip = forwardRef(function Tooltip(
if (!content && showTooltip) handleIsOpenChange(false)
}, [content, handleIsOpenChange, showTooltip])

// Update reference
useEffect(() => refs.setReference(referenceElement), [referenceElement, refs])

useEffect(() => {
// If the user clicks on escape key, close the tooltip.
if (!showTooltip) return
Expand Down

0 comments on commit c95c1c0

Please sign in to comment.