Skip to content

Commit

Permalink
Merge pull request #151 from abusix/pla-1402-hailstorm-remove-wrappin…
Browse files Browse the repository at this point in the history
…g-div-for-tooltip-component

fix: render passed children in tooltip parent
  • Loading branch information
mnlfischer authored Sep 25, 2024
2 parents 2ddbb78 + 55f96d6 commit 84cf284
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 84cf284

Please sign in to comment.