Skip to content
Design From Labs
ComponentoverlaysLabs examplesMIT

Tooltip

A short text hint for a control that opens on hover after a delay and on keyboard focus, and closes with Escape, on Radix, Base UI or React Aria.

Primitive
Direction

Install

Item tooltip-radix · registry JSON

npx shadcn@latest add https://labs.designfrom.com/r/tooltip-radix.json

Source

Comments are kept. The header lists provenance, license and install commands for people and coding assistants.

components/ui/tooltip.tsx
"use client";

import { Tooltip as TooltipPrimitive } from "radix-ui";
import type * as React from "react";

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

/**
 * @dfl-header: v1, generated by labs.designfrom.com at build time
 * Item: tooltip-radix (Tooltip: Radix)
 * What: A short text hint for a control that opens on hover after a delay
 *    and on keyboard focus, and closes with Escape, on Radix, Base UI or
 *    React Aria.
 * Status: ready. License: MIT. Author: Design From Labs
 *    <https://labs.designfrom.com>
 * Source: https://github.com/Design-from-labs/labs @ 803b92c1a30e (examples/tooltip)
 * Credits: S-003 React (MIT); S-004 shadcn/ui and its registry schema (MIT);
 *    S-008 Tailwind CSS (MIT); S-027 WAI-ARIA Authoring Practices:
 *    Tooltip pattern (W3C Software and Document License); S-032 Radix
 *    Primitives (the unified radix-ui package) (MIT); S-033 Base UI
 *    (@base-ui/react) (MIT); S-034 React Aria Components
 *    (react-aria-components) (Apache-2.0)
 * Install: npx shadcn@latest add https://labs.designfrom.com/r/tooltip-radix.json
 *   npx shadcn@latest add @designfrom/tooltip-radix
 *   npx designfrom add tooltip
 *   npm i @designfrom/react, then import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@designfrom/react/radix/tooltip";
 * Requires: radix-ui, registry: utils
 * Docs: https://labs.designfrom.com/ui/tooltip (index: https://labs.designfrom.com/llms.txt)
 */

// Wrap the app (or a section) once; it shares the open delay between
// tooltips so moving across a toolbar does not wait again.
function TooltipProvider({
  delayDuration = 300,
  ...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 <TooltipPrimitive.Root data-slot="tooltip" {...props} />;
}

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

function TooltipContent({
  className,
  sideOffset = 6,
  children,
  ...props
}: React.ComponentProps<typeof TooltipPrimitive.Content>) {
  return (
    <TooltipPrimitive.Portal>
      <TooltipPrimitive.Content
        data-slot="tooltip-content"
        sideOffset={sideOffset}
        className={cn(
          // Fades in from transparent on mount (@starting-style); opacity
          // only, so it stays on the compositor. No motion when reduced.
          "z-50 w-fit max-w-xs rounded-md bg-foreground px-3 py-1.5 text-background text-xs leading-snug shadow-md transition-opacity duration-150 starting:opacity-0 motion-reduce:transition-none",
          className,
        )}
        {...props}
      >
        {children}
        <TooltipPrimitive.Arrow className="fill-foreground" />
      </TooltipPrimitive.Content>
    </TooltipPrimitive.Portal>
  );
}

export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger };

Dependencies

Usage

<Tooltip>
  <TooltipTrigger>Share</TooltipTrigger>
  <TooltipContent>Copies a link</TooltipContent>
</Tooltip>

Props

PropTypeDefaultDescription
TooltipProvider delayDuration / delaynumber300Radix and Base UI: milliseconds of hover before a tooltip opens; shared by every tooltip inside the provider.
TooltipContent side"top" | "right" | "bottom" | "left""top"Radix and Base UI: where the hint appears relative to the trigger.
TooltipTrigger delaynumber300React Aria: milliseconds of hover before it opens.
Tooltip placement"top" | "bottom" | "start" | "end" | ..."top"React Aria: where the hint appears; start and end follow the reading direction.
classNamestringExtra classes for the hint bubble.

Accessibility

Credits

License and source

License
MIT
Author
Design From Labs <https://labs.designfrom.com>
Source
github.com/Design-from-labs/labs
Commit
803b92c1a30e
Date
2026-10-12
Origin
labs-examples