# Delayed tooltip

> A small label that fades in above an icon after a short pause, so it only shows when you really hover.

- Category: [Overlays](https://library.aimran.es/components/overlays)
- Built with: React + Motion
- Live editor: https://library.aimran.es/blocks/delayed-tooltip
- Library: AIMRAN Library (https://library.aimran.es), free, no sign-up, by Aimran Oukham

## Where to use it

Icon buttons are compact but can be cryptic, and a tooltip says what they do. The delay is the clever part: sweeping the mouse across a toolbar no longer sets off a flicker of labels. Use this React tooltip with a hover delay on a text editor, a video player or the actions of an admin table.

Around 400 to 500 milliseconds feels natural; much longer and people think it is broken. It shows on hover, so also show it on keyboard focus if your users navigate with Tab. Keep the text to a few words.

## Code

### React (Motion)

```tsx
import { useEffect, useRef, useState } from "react";
import { AnimatePresence, motion } from "framer-motion";
import { X } from "lucide-react";

interface DelayedTooltipProps {
  text?: string;
  delay?: number;
}

export default function DelayedTooltip({
  text = "Close window",
  delay = 450,
}: DelayedTooltipProps) {
  const [show, setShow] = useState(false);
  const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);

  useEffect(() => () => clearTimeout(timer.current), []);

  return (
    <div
      className="relative text-[#1d1d1f] dark:text-[#f5f5f7]"
      onMouseEnter={() => {
        clearTimeout(timer.current);
        timer.current = setTimeout(() => setShow(true), delay);
      }}
      onMouseLeave={() => {
        clearTimeout(timer.current);
        setShow(false);
      }}
    >
      <button
        type="button"
        aria-label={text}
        className="grid h-11 w-11 place-items-center rounded-full bg-white dark:bg-[#1c1c1e] shadow-[0_1px_2px_rgba(0,0,0,0.03),0_8px_28px_rgba(0,0,0,0.05)]"
      >
        <X className="h-4 w-4" />
      </button>
      <AnimatePresence>
        {show && (
          <motion.span
            initial={{ opacity: 0, y: 5, scale: 0.96 }}
            animate={{ opacity: 1, y: 0, scale: 1 }}
            exit={{ opacity: 0, y: 4 }}
            className="absolute bottom-14 left-1/2 w-max -translate-x-1/2 rounded-full bg-[#1d1d1f] px-3 py-1.5 text-xs text-[#f5f5f7] shadow-[0_1px_2px_rgba(0,0,0,0.03),0_8px_28px_rgba(0,0,0,0.05)] dark:bg-[#f5f5f7] dark:text-black"
          >
            {text}
          </motion.span>
        )}
      </AnimatePresence>
    </div>
  );
}
```

## Prompt for AI assistants

Paste this into ChatGPT, Claude, Cursor, v0 or Lovable to adapt the block to your stack (Tailwind, Vue, Svelte…):

````text
I want to add the “Delayed tooltip” block (Overlays) from AIMRAN Library to my project.

## What it is
A small label that fades in above an icon after a short pause, so it only shows when you really hover.

## Chosen settings
- Text: "Close window"
- Delay: 450ms (from 100 to 1200ms)

## What I need
1. Add it to my project with the same look and animation as the reference code: same sizes, colours, radii, shadows, timings and easing.
2. It is built with React + TypeScript, with framer-motion for the animation and lucide-react for the icons. If my project uses something else (Vue, Svelte, Astro, plain HTML…), translate it without losing any behaviour. If I use Tailwind, turn the styles into classes; if not, keep the CSS in its own file.
3. Expose the settings above as props (or CSS variables) with those values as defaults.
4. Make it work well on phones: nothing that depends only on hover, touch targets of at least 44 px and no overflow on 320 px screens.
5. Make it look right in light and dark mode.
6. Keep it accessible: semantic HTML, roles and aria-* where needed, visible focus and keyboard support.
7. Respect prefers-reduced-motion: with reduced motion, no big animations but the same end result.

## Reference code
```tsx
import { useEffect, useRef, useState } from "react";
import { AnimatePresence, motion } from "framer-motion";
import { X } from "lucide-react";

interface DelayedTooltipProps {
  text?: string;
  delay?: number;
}

export default function DelayedTooltip({
  text = "Close window",
  delay = 450,
}: DelayedTooltipProps) {
  const [show, setShow] = useState(false);
  const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);

  useEffect(() => () => clearTimeout(timer.current), []);

  return (
    <div
      className="relative text-[#1d1d1f] dark:text-[#f5f5f7]"
      onMouseEnter={() => {
        clearTimeout(timer.current);
        timer.current = setTimeout(() => setShow(true), delay);
      }}
      onMouseLeave={() => {
        clearTimeout(timer.current);
        setShow(false);
      }}
    >
      <button
        type="button"
        aria-label={text}
        className="grid h-11 w-11 place-items-center rounded-full bg-white dark:bg-[#1c1c1e] shadow-[0_1px_2px_rgba(0,0,0,0.03),0_8px_28px_rgba(0,0,0,0.05)]"
      >
        <X className="h-4 w-4" />
      </button>
      <AnimatePresence>
        {show && (
          <motion.span
            initial={{ opacity: 0, y: 5, scale: 0.96 }}
            animate={{ opacity: 1, y: 0, scale: 1 }}
            exit={{ opacity: 0, y: 4 }}
            className="absolute bottom-14 left-1/2 w-max -translate-x-1/2 rounded-full bg-[#1d1d1f] px-3 py-1.5 text-xs text-[#f5f5f7] shadow-[0_1px_2px_rgba(0,0,0,0.03),0_8px_28px_rgba(0,0,0,0.05)] dark:bg-[#f5f5f7] dark:text-black"
          >
            {text}
          </motion.span>
        )}
      </AnimatePresence>
    </div>
  );
}
```

Give me the complete final code, ready to paste, and tell me in one line where to put it in my project.
````
