Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Fix tooltip CTA buttons that do nothing after the trigger is clicked (#4731)

Rafi24e6930e0a05
diff --git a/packages/ui/src/tooltip.tsx b/packages/ui/src/tooltip.tsx
index d7b3a327b9..8120a8803f 100644
--- a/packages/ui/src/tooltip.tsx
+++ b/packages/ui/src/tooltip.tsx
@@ -85,6 +85,7 @@ export function Tooltip({
...rest
}: TooltipProps) {
const [open, setOpen] = useState(false);
+ const contentRef = useRef<HTMLDivElement>(null);
return (
<TooltipPrimitive.Root
@@ -98,7 +99,16 @@ export function Tooltip({
onClick={() => {
setOpen(true);
}}
- onBlur={() => {
+ onBlur={(e) => {
+ // Keep the tooltip open when focus moves into its content (e.g. a CTA button).
+ // preventDefault also skips Radix's own close-on-blur handler.
+ if (
+ e.relatedTarget instanceof Node &&
+ contentRef.current?.contains(e.relatedTarget)
+ ) {
+ e.preventDefault();
+ return;
+ }
setOpen(false);
}}
>
@@ -106,6 +116,7 @@ export function Tooltip({
</TooltipPrimitive.Trigger>
<TooltipPrimitive.Portal>
<TooltipPrimitive.Content
+ ref={contentRef}
sideOffset={8}
side={side}
className="animate-slide-up-fade border-border-default bg-bg-default pointer-events-auto z-[99] items-center overflow-hidden rounded-xl border shadow-sm"