[BUG] - Tooltip positioning breaks when Tooltip.Content contains interactive elements (e.g Button, Link)
HeroUI Version
3.0.2
Describe the bug
When Tooltip.Content contains any interactive element (e.g. Button or Link), the Tooltip renders at the top-left corner of the viewport instead of being anchored to its trigger. Removing the interactive element from the content makes positioning work correctly.
Your Example Website or App
No response
Steps to Reproduce the Bug or Issue
'use client';
import { Button, Tooltip } from '@heroui/react';
export default function Repro() {
return (
<Tooltip delay={0}>
<Tooltip.Trigger>
<span>HOVER ME</span>
</Tooltip.Trigger>
<Tooltip.Content>
<div>test <Button>click here</Button></div>
</Tooltip.Content>
</Tooltip>
);
}
Same issue occurs with Link instead of Button.
Workaround Replace the HeroUI Button/Link inside Tooltip.Content with a plain
Expected behavior
Tooltip renders next to the trigger element, regardless of content.
Screenshots or Videos
No response
Operating System Version
Windows 11
Browser
Chrome
Hello @J4v4Scr1pt 👋
I tracked down the issue.
HeroUI's Tooltip shares core logic with react-aria-components. Tooltip(which is TooltipTrigger in react-aria-component) wraps all of its children — including the overlay — with a FocusableProvider, which injects the trigger's ref into FocusableContext. Because React portals inherit the context tree, that context is still accessible inside Tooltip.Content even though it's rendered in a portal.
When a HeroUI Button or Link (both built on ButtonPrimitive from react-aria-components) mounts inside the overlay, it calls useFocusable → useSyncRef internally, which writes its own DOM ref to context.ref and ends up overwriting the original triggerRef.
A plain <button> or <a> doesn't cause this issue because native elements don't use useFocusable and therefore don't interact with FocusableContext.
Also, from what I understand, placing interactive elements like Button or Link inside a Tooltip isn't generally considered a standard pattern. Tooltips are typically meant for short, non-interactive text shown on hover or focus, and this pattern can also introduce accessibility concerns.
Could you share a bit more about your intended use case? That would help me think of a more appropriate solution.
Hello @J4v4Scr1pt 👋
I tracked down the issue.
HeroUI's Tooltip shares core logic with react-aria-components. Tooltip(which is TooltipTrigger in react-aria-component) wraps all of its children — including the overlay — with a FocusableProvider, which injects the trigger's ref into FocusableContext. Because React portals inherit the context tree, that context is still accessible inside Tooltip.Content even though it's rendered in a portal.
When a HeroUI Button or Link (both built on ButtonPrimitive from react-aria-components) mounts inside the overlay, it calls useFocusable → useSyncRef internally, which writes its own DOM ref to context.ref and ends up overwriting the original triggerRef.
A plain
<button>or<a>doesn't cause this issue because native elements don't use useFocusable and therefore don't interact with FocusableContext.Also, from what I understand, placing interactive elements like Button or Link inside a Tooltip isn't generally considered a standard pattern. Tooltips are typically meant for short, non-interactive text shown on hover or focus, and this pattern can also introduce accessibility concerns.
Could you share a bit more about your intended use case? That would help me think of a more appropriate solution.
Thanks for the quick response!
I'm responsible for the whole migration of V2 -> V3 in our product (I'm FE-Lead). During the migration I stumbled upon this use-case. After my post I also talked about this with our UX in charge and as you are touching upon we don't want this behavior in our tooltips and are changing some things by moving interactive content outside and some we switch to Popover.
If you are interested about the use-case it was a card with some bars in different colors etc. and below we had a "Trend/Accuracy-Icon" when hovering this we showed a rich tooltip that explained it all. To get more understanding there was a Link in the bottom to open our help center in a new tab"
For my case you can could close this as I understand that this is not intended use of the tooltip.
I ran into the same problem after migrating to v3. Instead of using <a> and <button>, I applied a ref to Tooltip.Content and a div inside Tooltip.Trigger. Maybe it will make someone's life easier.
'use client';
import { Button, Chip, Tooltip } from '@heroui/react';
import Link from 'next/link';
import { useRef } from 'react';
export default function Test() {
const chipRef = useRef<HTMLDivElement>(null);
return (
<Tooltip delay={0}>
<Tooltip.Trigger>
<div ref={chipRef}>
<Chip>Some text</Chip>
</div>
</Tooltip.Trigger>
<Tooltip.Content triggerRef={chipRef}>
<Link href='some-href'>Some URL</Link>
<Button>Copy URL</Button>
</Tooltip.Content>
</Tooltip>
);
}