Files
upstream-mirror 1416db152c
All checks were successful
Release / Create Version PR or Publish Stable Release (push) Has been skipped
Release / Publish Prerelease to NPM (push) Has been skipped
Monitor Registries / Monitor registry health (push) Has been skipped
snapshot of https://github.com/shadcn-ui/ui.git (main, 2026-09-15; blobs > 131072B omitted)
2026-09-15 22:44:43 +05:00

137 lines
2.5 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: Hover Card
description: A popover that appears on hover, focus, or long press to preview content available behind a link.
base: aria
component: true
links:
doc: https://react-aria.adobe.com/PreviewTrigger
api: https://react-aria.adobe.com/PreviewTrigger#api
---
<ComponentPreview
styleName="aria-nova"
name="hover-card-demo"
previewClassName="h-80"
/>
## Installation
<CodeTabs>
<TabsList>
<TabsTrigger value="cli">Command</TabsTrigger>
<TabsTrigger value="manual">Manual</TabsTrigger>
</TabsList>
<TabsContent value="cli">
```bash
npx shadcn@latest add hover-card
```
</TabsContent>
<TabsContent value="manual">
<Steps className="mb-0 pt-2">
<Step>Install the following dependencies:</Step>
```bash
npm install react-aria-components
```
<Step>Copy and paste the following code into your project.</Step>
<ComponentSource
name="hover-card"
title="components/ui/hover-card.tsx"
styleName="aria-nova"
/>
<Step>Update the import paths to match your project setup.</Step>
</Steps>
</TabsContent>
</CodeTabs>
## Usage
```tsx showLineNumbers
import { HoverCard, HoverCardTrigger } from "@/components/ui/hover-card"
```
```tsx showLineNumbers
<HoverCardTrigger>
<Button variant="link">Hover</Button>
<HoverCard>
The React Framework – created and maintained by @vercel.
</HoverCard>
</HoverCardTrigger>
```
## Composition
Use the following composition to build a `HoverCard`:
```text
HoverCardTrigger
├── Button
└── HoverCard
```
## Trigger Delays
Use `delay` and `closeDelay` on the `HoverCardTrigger` to control when the card
opens and closes.
```tsx showLineNumbers
<HoverCardTrigger delay={100} closeDelay={200}>
<Button variant="link">Hover</Button>
<HoverCard>Content</HoverCard>
</HoverCardTrigger>
```
## Positioning
Use the `placement` prop on `HoverCard` to control placement.
```tsx showLineNumbers
<HoverCardTrigger>
<Button variant="link">Hover</Button>
<HoverCard placement="top">Content</HoverCard>
</HoverCardTrigger>
```
## Basic
<ComponentPreview
styleName="aria-nova"
name="hover-card-demo"
previewClassName="h-80"
/>
## Sides
<ComponentPreview
styleName="aria-nova"
name="hover-card-sides"
previewClassName="h-[22rem]"
/>
## RTL
To enable RTL support in shadcn/ui, see the [RTL configuration guide](/docs/rtl).
<ComponentPreview
styleName="aria-nova"
name="hover-card-rtl"
direction="rtl"
previewClassName="h-80"
/>
## API Reference
See the [React Aria](https://react-aria.adobe.com/PreviewTrigger#api) documentation for more information.