mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-06-30 16:14:13 +00:00
53 lines
1.1 KiB
Plaintext
53 lines
1.1 KiB
Plaintext
---
|
|
title: Tooltip
|
|
description: A popup that displays information related to an element when the element receives keyboard focus or the mouse hovers over it.
|
|
component: true
|
|
radix:
|
|
link: https://www.radix-ui.com/docs/primitives/components/tooltip
|
|
api: https://www.radix-ui.com/docs/primitives/components/tooltip#api-reference
|
|
---
|
|
|
|
<ComponentExample src="/components/examples/tooltip/demo.tsx">
|
|
<TooltipDemo />
|
|
</ComponentExample>
|
|
|
|
## Installation
|
|
|
|
1. Install the `@radix-ui/react-tooltip` component from radix-ui:
|
|
|
|
```bash
|
|
npm install @radix-ui/react-tooltip
|
|
```
|
|
|
|
2. Copy and paste the following code into your project.
|
|
|
|
<ComponentSource src="/components/ui/tooltip.tsx" />
|
|
|
|
<Callout>
|
|
|
|
This is the `<Tooltip />` primitive. You can place it in a file at `components/ui/tooltip.tsx`.
|
|
|
|
</Callout>
|
|
|
|
## Usage
|
|
|
|
```tsx
|
|
import {
|
|
Tooltip,
|
|
TooltipContent,
|
|
TooltipProvider,
|
|
TooltipTrigger,
|
|
} from "@/components/ui/tooltip"
|
|
```
|
|
|
|
```tsx
|
|
<TooltipProvider>
|
|
<Tooltip>
|
|
<TooltipTrigger>Hover</TooltipTrigger>
|
|
<TooltipContent>
|
|
<p>Add to library</p>
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
</TooltipProvider>
|
|
```
|