---
title: "Hover Card"
description: "Preview related content on hover or keyboard focus."
---

# Hover Card

Preview related content on hover or keyboard focus.

## Installation

Install the shared package once in your Exact app. This version is a beta.

```sh
bun add --exact @rightui/ui@0.4.0-beta.4
```

Or choose another package manager:

```sh
npm install --save-exact @rightui/ui@0.4.0-beta.4
pnpm add --save-exact @rightui/ui@0.4.0-beta.4
yarn add --exact @rightui/ui@0.4.0-beta.4
```

Exact compilation uses Bun 1.4.2. Register Geist and Newsreader, declare the font marker and add the root provider using [Installation](/docs/installation).

### Manual source setup

Install an editable copy of the complete package:

```sh
mkdir -p vendor/rightui vendor/rightui-ui
npm pack @rightui/ui@0.4.0-beta.4 --pack-destination vendor/rightui
tar -xzf ./vendor/rightui/rightui-ui-0.4.0-beta.4.tgz -C vendor/rightui-ui --strip-components=1
bun add file:./vendor/rightui-ui
```

Keep package.json, the Contract files, ui.tamber, assets and licenses together.

### Import

```contract
use HoverCard from "@rightui/ui"
```

## Usage

Compose HoverCard with shared components such as AvatarFrame. Keep essential information available outside the hover preview.

## Example

```contract
use FontWeights from "@rightui/ui"
use uiFontFamily, HoverCard, AvatarFrame from "@rightui/ui"

component Demo
  props
    width: number
    reduced: bool
  inject
    uiWeights: FontWeights
    uiFont: string
  view
    column gap="ui.space-16" min-width=0 max-width="100%"
      HoverCard(id="controls-hover", label="@ccheever")
        row gap="ui.space-12" align-items="center"
          AvatarFrame(id="controls-hover-avatar", name="@ccheever", src="assets/avatars/user-blue.png", fallback="CC", size="lg")
          column gap="ui.space-4" flex=1 min-width="0px"
            text "@ccheever" font-size="ui.text-sm" font-weight=uiWeights.semibold font-family=uiFontFamily(uiFont) data-rightui-font="body"
            text "Explore Exact and its native UI tools." font-size="ui.text-sm" color="ui.muted-foreground" font-family=uiFontFamily(uiFont) data-rightui-font="body"
        link id="controls-hover-profile" testId="controls-hover-profile" href="https://github.com/expo/exact" color="ui.foreground" font-size="ui.text-sm"
          text "Explore Exact" font-family=uiFontFamily(uiFont) data-rightui-font="body"

```

## Keyboard

Tab focuses the trigger. Enter or Space toggles the preview; Escape closes it.

## API Reference

| Property | Type |
| --- | --- |
| HoverCard.id | string |
| HoverCard.label | string |

## Source

File: packages/ui/hover-card.contract

```contract
use FontWeights from "./typography-context.contract"
use uiFontFamily from "./typography-context.contract"
use Control from "./styles.contract"
component HoverCardFrame
  props
    id: string
    label: string
    variant: string
    size: string
    ai: bool
  inject
    uiWeights: FontWeights
    uiFont: string
  slot
  state expanded = false
  state focused = false
  action show
    expanded = true
    showPopover(id + "-content", source=id)
  action hide
    expanded = false
    hidePopover(id + "-content")
  action hover(inside: bool)
    if inside
      show()
    else if not focused
      hide()
  action enter
    focused = true
    show()
  action leave(e: FocusEvent)
    match e.relatedTarget
      case some(target)
        if not target.startsWith(id)
          focused = false
          hide()
      case none
        focused = false
        hide()
  action toggle
    if expanded
      hide()
    else
      show()
  action changed(e: ToggleEvent)
    expanded = e.newState == "open"
  action keys(k: string)
    if k == "Escape"
      preventDefault()
      hide()
  view
    row position="relative" align-items="center" hover=hover focusin=enter focusout=leave key=keys
      button id=id testId=id class=Control press=toggle aria-expanded=expanded aria-controls=(id + "-content")
        display="flex" align-items="center" height=(size == "xs" ? "ui.space-24" : "ui.space-28") min-height=(size == "xs" ? "ui.space-24" : "ui.space-28") padding=(size == "xs" ? "0px ui.space-8" : "0px ui.space-12") border-width=(variant == "outline" ? "ui.border-width" : "0px") border-style="solid" border-color="ui.input" border-radius=(ai ? "ui.ai-radius-control" : "ui.radius-control") background-color=(variant == "secondary" ? "ui.muted" : "ui.surface") color="ui.foreground" font-size=(size == "xs" ? "ui.text-xs" : "ui.text-sm") font-weight=uiWeights.medium text-decoration=(variant == "link" ? "underline" : "none")
        text label font-family=uiFontFamily(uiFont) data-rightui-font="body"
      column id=(id + "-content") testId=(id + "-content") role="region" aria-label=label popover="auto" toggle=changed position-area="bottom span-right" position-try-fallbacks="flip-block, flip-inline" margin="0px" gap="ui.space-12" padding="ui.space-16" box-sizing="border-box" min-width="0px" align-items="stretch" width=(ai ? "16rem" : "20rem") max-width="calc(100vw - ui.space-32)"
        border-width="ui.border-width" border-style="solid" border-color="ui.border" border-radius=(ai ? "ui.ai-radius-popover" : "ui.radius-popover") background-color="ui.surface" color="ui.foreground" box-shadow="ui.shadow-menu"
        children

component HoverCard
  props
    id: string
    label: string
  slot
  view
    HoverCardFrame(id=id, label=label, variant="link", size="sm", ai=false)
      children

component HoverCardStyled
  props
    id: string
    label: string
    variant: string
    size: string
  slot
  view
    HoverCardFrame(id=id, label=label, variant=variant, size=size, ai=true)
      children

```
