A preview that opens when the pointer rests on a link or focus lands on it. It stays open while you move into it. On a touch screen the first tap shows the card and the second follows the link.
Used for
- Agent profile preview
- Run link preview
- Mention details
- Model info on hover
Examples
Installation
npx knowns-ui@latest add hover-cardFor Claude Code, Cursor or Codex: installs it and wires the props to your own data.
Paste this into your coding agent (Claude Code, Cursor, Codex). It checks your project, sets up the registry, runs the install and verifies it.
Install prompt
Install Hover card from Knowns UI into this project. Work step by step, show me each change, and ask before you edit files outside this project.
Context: Knowns UI (https://ui.knowns.dev) is a shadcn registry. Items land in the project as source files. Docs: https://ui.knowns.dev/docs/hover-card
1. Check the project first. Stop and tell me if any of these is missing:
- React 19 and Tailwind CSS v4.
- A components.json at the project root. If there is none, ask me before running `npx knowns-ui@latest init --no-key` (it runs shadcn init when needed, then adds the registries).
2. Run:
```bash
npx knowns-ui@latest add hover-card
```
It writes these files:
- lib/knowns/run.ts
- lib/knowns/json.tsx
- lib/knowns/status.ts
- lib/knowns/tone.ts
- lib/knowns/types.ts
- lib/knowns/use-abortable.ts
- lib/knowns/utils.ts
- lib/knowns/motion.tsx
- lib/knowns/motion-utils.ts
- components/ui/knowns/use-floating.ts
- components/ui/knowns/hover-card.tsx
and installs these npm packages: clsx@^2.1.1, tailwind-merge@^3.7.0.
3. While it runs:
- It also adds a few @keyframes (all named kn-*) to the global CSS file (globals.css or the file components.json points at). Let it: they only add animations.
- If it asks to overwrite files under lib/knowns/: these are shared by every Knowns UI item. List them, say whether I changed them (check git), and ask me before you answer.
- If it asks to overwrite any other file, show me the diff and ask me.
4. Verify:
- Every file in the list above exists.
- The project type-checks (for example `npx tsc --noEmit`) and the dev build has no new errors.
5. Use it: follow the examples and props on https://ui.knowns.dev/docs/hover-card, and ask me if anything about my data is unclear.
If the Knowns UI MCP server is connected (https://ui.knowns.dev/docs/ai-and-mcp), use get_component({ name: "hover-card" }) or search_docs for details.
Finish with a short summary: the files you added or changed, the packages you installed, and anything I still need to do.Props
- trigger
ReactElement- One element, usually a link. It gets aria-describedby while the card is open.
- children
ReactNode- The card. Without `interactive` it cannot be reached with Tab, so keep it informational: nothing here may be the only way to something.
- interactive
boolean- Default
false - The card holds buttons or links. Tab from the focused trigger moves into the card; Tab past its last control or Shift+Tab from its first returns to the page order and closes it. No focus trap. The trigger gets aria-haspopup="dialog" and aria-controls instead of aria-describedby, and the card is a labelled, non-modal dialog.
- label
string- Accessible name of an interactive card. Default: the trigger's own text.
- openDelay / closeDelay
number (ms)- Default
500 / 200 - Rest time before opening. Time to cross the gap into the card before it closes. Focus opens it at once.
- side / align
"top"|"bottom"|"left"|"right" / "start"|"center"|"end"- Default
"bottom" / "center" - Placement; it flips when there is no room.
- open / onOpenChange
boolean / (open) => void- Optional control.
- width
number- Default
288 - Card width in px, never wider than the screen.
- touch
behaviour- No hover on touch: the first tap opens the card and holds the link back, a tap while open follows it, a tap outside closes it.
- keys
Escape / Tab / Shift+Tab- Escape closes the card and, from inside an interactive card, returns focus to the trigger. Tab and Shift+Tab move through an interactive card as above.
| Prop | Type | Default | Description |
|---|---|---|---|
| trigger | ReactElement | - | One element, usually a link. It gets aria-describedby while the card is open. |
| children | ReactNode | - | The card. Without `interactive` it cannot be reached with Tab, so keep it informational: nothing here may be the only way to something. |
| interactive | boolean | false | The card holds buttons or links. Tab from the focused trigger moves into the card; Tab past its last control or Shift+Tab from its first returns to the page order and closes it. No focus trap. The trigger gets aria-haspopup="dialog" and aria-controls instead of aria-describedby, and the card is a labelled, non-modal dialog. |
| label | string | - | Accessible name of an interactive card. Default: the trigger's own text. |
| openDelay / closeDelay | number (ms) | 500 / 200 | Rest time before opening. Time to cross the gap into the card before it closes. Focus opens it at once. |
| side / align | "top" | "bottom" | "left" | "right" / "start" | "center" | "end" | "bottom" / "center" | Placement; it flips when there is no room. |
| open / onOpenChange | boolean / (open) => void | - | Optional control. |
| width | number | 288 | Card width in px, never wider than the screen. |
| touch | behaviour | - | No hover on touch: the first tap opens the card and holds the link back, a tap while open follows it, a tap outside closes it. |
| keys | Escape / Tab / Shift+Tab | - | Escape closes the card and, from inside an interactive card, returns focus to the trigger. Tab and Shift+Tab move through an interactive card as above. |
What it handles
- 01Opens a preview card after the pointer rests on the trigger for openDelay, half a second by default, and opens at once on keyboard focus.
- 02Stays open while the pointer is over the trigger or the card, and closes closeDelay after it leaves, a fifth of a second by default.
- 03Closes on Escape or a press outside. Read-only, the trigger is described by the card while it is open; interactive, it announces a labelled non-modal dialog (aria-haspopup, aria-controls).
- 04With interactive, Tab from the trigger enters the card, and Tab past its last control or Shift+Tab from its first leaves it and closes it, with no focus trap.
- 05Treats the first touch tap as the open, so a link trigger does not navigate until the second tap.
- 06Renders in a portal with side, align and a width in pixels, and flips when the card would run off screen.
States
- First render
- Nothing. The card is not mounted until it opens
- none
- Pointer rests
- After the open delay the card fades in
- 120ms, opacity only
- Pointer leaves
- After the close delay the card fades out a little quicker
- 120ms, opacity only
- Keyboard focus
- The card opens at once with the same fade
- 120ms, opacity only
- Tab into the card
- Interactive only: focus moves to its first control, nothing animates
- none
- Reduced motion
- It appears and unmounts at once
- 0ms
| State | What moves | Timing |
|---|---|---|
| First render | Nothing. The card is not mounted until it opens | none |
| Pointer rests | After the open delay the card fades in | 120ms, opacity only |
| Pointer leaves | After the close delay the card fades out a little quicker | 120ms, opacity only |
| Keyboard focus | The card opens at once with the same fade | 120ms, opacity only |
| Tab into the card | Interactive only: focus moves to its first control, nothing animates | none |
| Reduced motion | It appears and unmounts at once | 0ms |
Works with
When to use
Using with AI
Use Copy page for AI above to give your assistant this page, Copy prompt under the install command to have it installed and wired to your data, or connect the Knowns UI MCP server and just ask:
- Add the Knowns UI Hover Card to my app and wire it to my own data.
- I need a preview of the thing a link points to: a profile, a run, a repository, shown when the pointer rests on it. Set that up with the Knowns UI Hover Card.
- Which Hover Card props do I need for a minimal setup? Show me a short example.
With the server connected, your assistant calls get_component({ name: "hover-card" }) and search_docs({ query: "hover card" }).