Hover Card

new

Sneak peek, no commitment. A preview card for links, shown on hover or focus.

Demo

Installation

Usage

<script setup lang="ts">
import { Button } from '@/components/ui/button'
import { HoverCard, HoverCardContent, HoverCardTrigger } from '@/components/ui/hover-card'
</script>

<template>
  <HoverCard>
    <HoverCardTrigger as-child>
      <Button variant="link">@kappa-ui</Button>
    </HoverCardTrigger>
    <HoverCardContent>A preview of what the link leads to.</HoverCardContent>
  </HoverCard>
</template>

On desktop, it opens when the pointer rests on the trigger or the trigger gets keyboard focus, and closes shortly after both are left.

It's for previews people can skip. Screen readers don't announce it, so keep anything important out of it.

On touch:

  • Links open the card on a long press, and a tap still follows the link.
  • Buttons and other elements open it on a tap and close it on the next one.

Once open, it stays while you scroll and closes on a tap outside or Escape. Want a long press everywhere? Set touch="long-press". No touch at all? Use touch="off".

update:open tells you why it opened or closed: trigger-hover, trigger-focus, trigger-press, outside-press, escape-key, scroll or disabled.

Examples

Delays

openDelay and closeDelay set how long to wait, in milliseconds, before the card opens and closes: 700 and 300 by default.

Delay

API Reference

HoverCardContent takes a class that merges with its own.

Data attributes

data-slotAttributesDescription
hover-card-triggerdata-stateThe trigger, a link by default.
hover-card-contentdata-state, data-side, data-alignThe card.

Changelog

  1. core 0.7.0

    b9b2829 — HoverCard roots share one window scroll listener instead of registering one each for their whole lifetime.

  2. registry 0.6.0

    6ea2d24 — @kappa-ui/core/hover-card drives the hover card: on touch, auto opens a link on a long press and anything else on a tap, the card stays open while the page scrolls and closes on a tap outside, on Escape or on disabled; on a desktop the pointer has to rest for openDelay, focus opens only when visible, and update:open reports why the card opened or closed. HoverCard loses enableTouch and gains touch, touchDelay, restThreshold and disabled. The card no longer gets stuck after a scroll on touch.

  3. core 0.5.0

    6ea2d24 — @kappa-ui/core/hover-card drives the hover card: on touch, auto opens a link on a long press and anything else on a tap, the card stays open while the page scrolls and closes on a tap outside, on Escape or on disabled; on a desktop the pointer has to rest for openDelay, focus opens only when visible, and update:open reports why the card opened or closed. HoverCard loses enableTouch and gains touch, touchDelay, restThreshold and disabled. The card no longer gets stuck after a scroll on touch.

  4. registry 0.5.0

    976b350 — Add HoverCard, from shadcn-vue, on the popover surface: a card shown on hover or focus of a link, with openDelay and closeDelay.