Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug]: [v4] Tooltip Arrow Overlaps Tooltip Content #6933

Open
2 tasks done
paaskus opened this issue Mar 14, 2025 · 0 comments · May be fixed by #6934
Open
2 tasks done

[bug]: [v4] Tooltip Arrow Overlaps Tooltip Content #6933

paaskus opened this issue Mar 14, 2025 · 0 comments · May be fixed by #6934
Labels
bug Something isn't working

Comments

@paaskus
Copy link

paaskus commented Mar 14, 2025

Describe the bug

The Tooltip component's arrow element can overlap with the tooltip content in certain scenarios. This happens because the arrow (which is implemented as a rotated square) has a z-index that places it above the content, potentially obscuring parts of the text.

Image

Affected component/components

Tooltip [v4]

How to reproduce

  1. Install the latest v4 version of the Shadcn Tooltip component (new-york style, slate theme if it matters).
  2. Render the following tooltip (note the p-0 on the <TooltipContent> to highlight the issue:
<Tooltip open>
  <TooltipTrigger asChild>
    <Button variant="destructive">Current</Button>
  </TooltipTrigger>
  <TooltipContent className="p-0">
    <p>Text inside tooltip</p>
  </TooltipContent>
</Tooltip>

To be clear, this issue appeared in a more special case without setting p-0 on the <TooltipContent>.

Here's a snapshot of the exact implementation of the Tooltip component that causes the issue:

"use client"

import * as React from "react"
import * as TooltipPrimitive from "@radix-ui/react-tooltip"

import { cn } from "@/lib/utils"

function TooltipProvider({
  delayDuration = 0,
  ...props
}: React.ComponentProps<typeof TooltipPrimitive.Provider>) {
  return (
    <TooltipPrimitive.Provider
      data-slot="tooltip-provider"
      delayDuration={delayDuration}
      {...props}
    />
  )
}

function Tooltip({
  ...props
}: React.ComponentProps<typeof TooltipPrimitive.Root>) {
  return (
    <TooltipProvider>
      <TooltipPrimitive.Root data-slot="tooltip" {...props} />
    </TooltipProvider>
  )
}

function TooltipTrigger({
  ...props
}: React.ComponentProps<typeof TooltipPrimitive.Trigger>) {
  return <TooltipPrimitive.Trigger data-slot="tooltip-trigger" {...props} />
}

function TooltipContent({
  className,
  sideOffset = 0,
  children,
  ...props
}: React.ComponentProps<typeof TooltipPrimitive.Content>) {
  return (
    <TooltipPrimitive.Portal>
      <TooltipPrimitive.Content
        data-slot="tooltip-content"
        sideOffset={sideOffset}
        className={cn(
          "bg-primary text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit rounded-md px-3 py-1.5 text-xs text-balance",
          className
        )}
        {...props}
      >
        {children}
        <TooltipPrimitive.Arrow className="bg-primary fill-primary z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]" />
      </TooltipPrimitive.Content>
    </TooltipPrimitive.Portal>
  )
}

export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider }

Codesandbox/StackBlitz link

https://codesandbox.io/p/devbox/shadcn-tooltip-arrow-issue-8xdqwl

Logs

System Info

React: v19.0.0
Vite: v6.2.1
@radix-ui/react-tooltip: v1.1.8
Browser: Google Chrome Version 133.0.6943.127 (Official Build) (arm64)
OS: macOS Ventura

Before submitting

  • I've made research efforts and searched the documentation
  • I've searched for existing issues
@paaskus paaskus added the bug Something isn't working label Mar 14, 2025
@paaskus paaskus linked a pull request Mar 15, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant