Skip to content

Commit

Permalink
fix: render passed children in tooltip parent
Browse files Browse the repository at this point in the history
  • Loading branch information
mnlfischer committed Sep 25, 2024
1 parent dc626b1 commit 55f96d6
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/components/tooltip/tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { classNames } from "../../util/class-names";
import { TooltipPortal } from "./tooltip-portal";

interface TooltipProps {
children: React.ReactNode;
children: React.ReactElement;
title: React.ReactNode;
position?: Placement;
className?: string;
Expand Down Expand Up @@ -34,6 +34,12 @@ export const Tooltip = ({
modifiers: [{ name: "offset", options: { offset: [0, 8] } }],
});

const childrenWithRef = React.cloneElement(children, {
ref: (el: HTMLDivElement) => setReferenceElement(el),
onMouseEnter: () => !isControlled && setShow(true),
onMouseLeave: () => !isControlled && setShow(false),
});

useEffect(() => {
if (open !== undefined) {
setIsControlled(true);
Expand Down Expand Up @@ -67,13 +73,7 @@ export const Tooltip = ({

return (
<>
<div
ref={(el) => el && setReferenceElement(el)}
onMouseEnter={() => !isControlled && setShow(true)}
onMouseLeave={() => !isControlled && setShow(false)}
>
{children}
</div>
{childrenWithRef}
{strategy === "portal" ? (
<TooltipPortal>{renderTooltipContent()}</TooltipPortal>
) : (
Expand Down

0 comments on commit 55f96d6

Please sign in to comment.