Skip to content
Components

Tooltip

Tooltip with thoughtful defaults, semantic styling, and editable source.

Open ↗

Make it yours.

Install the editable source and its dependencies into your React + Tailwind project.

Scroll horizontally for long lines
pnpm dlx shadcn@4.0.8 add http://localhost:3000/r/tooltip.json

Use it

Scroll horizontally for long lines
"use client";
import {Tooltip} from '@/components/jez-ui/ui/tooltip';
import {Button} from '@/components/jez-ui/ui/button';

export default function Example(){

return <><Tooltip content="Save your current work"><Button variant="outline">Hover or focus me</Button></Tooltip></>;
}

Props & types

Scroll horizontally for long lines
{
  children: React.ReactNode;
  content: React.ReactNode;
  className?: string;
}

Source

View 2 source files

registry/ui/tooltip.tsx

Scroll horizontally for long lines
"use client";
import * as React from "react";
import { cn } from "./utils";
import { Tooltip as Primitive } from "radix-ui";
export function Tooltip({
  children,
  content,
  className,
}: {
  children: React.ReactNode;
  content: React.ReactNode;
  className?: string;
}) {
  return (
    <Primitive.Provider delayDuration={250}>
      <Primitive.Root>
        <Primitive.Trigger asChild>{children}</Primitive.Trigger>
        <Primitive.Portal>
          <Primitive.Content
            sideOffset={6}
            className={cn(
              "z-50 rounded-lg bg-foreground px-3 py-2 text-xs text-background",
              className,
            )}
          >
            {content}
            <Primitive.Arrow className="fill-foreground" />
          </Primitive.Content>
        </Primitive.Portal>
      </Primitive.Root>
    </Primitive.Provider>
  );
}

registry/ui/utils.ts

Scroll horizontally for long lines
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...values: ClassValue[]) {
  return twMerge(clsx(values));
}

Dependencies

radix-ui@1.6.7 · clsx@2.1.1 · tailwind-merge@3.5.0

Accessibility & behaviour

Provide meaningful labels and preserve keyboard focus styles. Check contrast when customising theme colours.

Read the accessibility and performance guide →