# Tooltip

> Names an icon-only control on hover or focus.

A tooltip names an icon-only control when it is hovered or focused.

## When to use

- Use it to label icon buttons, such as download or edit.
- Keep it to a few words; put longer help in the page.
- Don't put anything people need to click in a tooltip.

_Live preview of the React and Vue versions: https://design.sosialoka.tech/components/tooltip/_

### Do and don't

- **Do:** Use a tooltip to name an icon-only button in a word or two.
- **Don't:** Don't hide instructions or policy in a tooltip.

## Anatomy

1. Tooltip on foreground
2. Icon-only trigger

A small label in inverse colors (`foreground` fill, `background` text) on `radius-md`, with an arrow toward the control.

## Variants

There is one style. It can appear on any side of the control.

## Props

| React | Vue | Flutter | Type | Default | Use |
| --- | --- | --- | --- | --- | --- |
| `TooltipProvider delay` | `TooltipProvider :delay-duration` | none | number (ms) | provider default | How long before it shows. |
| `TooltipContent side` | `TooltipContent side` | `anchor` | `top` \| `right` \| `bottom` \| `left` | `top` | Where it appears. |
| `TooltipTrigger render` | `TooltipTrigger as-child` | `child` | element | button | The control it names. |

## Code

**React**
```tsx
import { DownloadIcon } from "lucide-react"
import { Button } from "@/components/ui/button"
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"

export default function TooltipDemo() {
  return (
    <TooltipProvider delay={0}>
      <Tooltip>
        <TooltipTrigger render={<Button variant="outline" size="icon" aria-label="Unduh laporan" />}>
          <DownloadIcon />
        </TooltipTrigger>
        <TooltipContent>Unduh laporan</TooltipContent>
      </Tooltip>
    </TooltipProvider>
  )
}
```

**Vue**
```vue
<script setup lang="ts">
import { Download } from "@lucide/vue"
import { Button } from "@/components/ui/button"
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"
</script>

<template>
  <TooltipProvider :delay-duration="0">
    <Tooltip>
      <TooltipTrigger as-child>
        <Button variant="outline" size="icon" aria-label="Unduh laporan"><Download /></Button>
      </TooltipTrigger>
      <TooltipContent>Unduh laporan</TooltipContent>
    </Tooltip>
  </TooltipProvider>
</template>
```

**Flutter**
```dart
import 'package:flutter/widgets.dart';
import 'package:shadcn_ui/shadcn_ui.dart';

class TooltipDemo extends StatelessWidget {
  const TooltipDemo({super.key});

  @override
  Widget build(BuildContext context) {
    return ShadTooltip(
      builder: (context) => const Text('Unduh laporan'),
      child: ShadIconButton.outline(icon: const Icon(LucideIcons.download), onPressed: () {}),
    );
  }
}
```

## Install

**React**
```bash
npx shadcn@latest add https://design.sosialoka.tech/r/react/tooltip.json
```

**Vue**
```bash
npx shadcn-vue@latest add https://design.sosialoka.tech/r/vue/tooltip.json
```

## Accessibility

- Shows on keyboard focus as well as hover.
- The control still needs an `aria-label`; the tooltip helps sighted people, the label helps screen readers.
