Skip to main content

Hover Card

Preview content behind a link on hover or keyboard focus.

The design system grew out of the primitives that @alex.morgan published in the component library, and the team keeps refining them as the product surface grows.

Props
Slots

Anatomy#

HoverCard [component; no DOM]
├── HoverCard.Trigger [part; slot=trigger]
└── positioner [internal]
    └── HoverCard.Content [part; slot=content]

Content is portaled inside an internal positioning wrapper.

Usage#

Use HoverCard to preview the destination of a link on hover or keyboard focus. The trigger defaults to an anchor element, so compose it directly inside prose. Use Tooltip for a brief, non-interactive hint and Popover for content the user must reach and operate.

import { HoverCard } from 'moraine'

export function Example() {
  return (
    <HoverCard>
      <HoverCard.Trigger href="/u/alex.morgan">@alex.morgan</HoverCard.Trigger>
      <HoverCard.Content>Author profile preview</HoverCard.Content>
    </HoverCard>
  )
}

Delays and anchoring#

openDelay (default 600 ms) keeps the card from opening on a passing pointer, and closeDelay (default 300 ms) keeps it open while the pointer travels from the trigger into the content. The card anchors to the line the pointer entered, so it stays attached when the trigger wraps across multiple lines. placement defaults to 'bottom', and gutter defaults to 4 px.

<HoverCard openDelay={200} closeDelay={100} placement="top" align="start">
  <HoverCard.Trigger href="/releases/v2">v2 release notes</HoverCard.Trigger>
  <HoverCard.Content>Ships December 15.</HoverCard.Content>
</HoverCard>

Dismissal and accessibility#

Escape and a pointer press outside close the card; hover or keyboard focus reopens it. Control the open state with open and onOpenChange, or start open with defaultOpen. disabled keeps the card closed. forceMount keeps the content in the DOM while closed.

Hover card content is supplementary: keyboard users cannot reach it and screen readers do not announce it, so it must never be the only place the information lives. Make the same content available at the link destination.

<HoverCard>
  <HoverCard.Trigger href="/u/alex.morgan">@alex.morgan</HoverCard.Trigger>
  <HoverCard.Content>Profile summary also shown on the author page.</HoverCard.Content>
</HoverCard>

Keyboard interaction#

Moving keyboard focus to the trigger opens the card after openDelay, and blurring the trigger closes it after closeDelay. Only keyboard (focus-visible) focus opens the card, and touch hover is ignored. The card itself is not keyboard reachable; keep interactive content in a Popover instead.

Examples#

Preview a profile inside prose#

Hover or focus the link to preview the author. The trigger wraps across lines like any inline anchor, and the card anchors to the line the pointer entered.

import { Avatar, Badge, HoverCard } from 'moraine'

export function ProfilePreview() {
  return (
    <p class="text-sm text-foreground leading-6 max-w-xs">
      The component library is maintained by{' '}
      <HoverCard openDelay={200} closeDelay={120}>
        <HoverCard.Trigger href="/u/alex.morgan" class="font-medium underline underline-offset-4">
          @alex.morgan
        </HoverCard.Trigger>
        <HoverCard.Content>
          <div class="space-y-3">
            <Avatar text="AM" alt="Alex Morgan" size="lg" />
            <div>
              <div class="flex gap-1.5 items-center">
                <h4 class="text-sm font-semibold">Alex Morgan</h4>
                <Badge variant="outline" size="sm">
                  Maintainer
                </Badge>
              </div>
              <p class="text-xs text-muted-foreground font-mono">@alex.morgan</p>
            </div>
            <p class="text-xs text-foreground">
              Building accessible, high-performance UI primitives for SolidJS and web standards.
            </p>
            <div class="text-xs text-muted-foreground pt-2 border-t border-border flex gap-3">
              <span>
                <strong class="text-foreground font-semibold">1.4k</strong> followers
              </span>
              <span>
                <strong class="text-foreground font-semibold">328</strong> following
              </span>
            </div>
          </div>
        </HoverCard.Content>
      </HoverCard>{' '}
      and the wider community, with new primitives landing in each release cycle.
    </p>
  )
}

Share one card across multiple triggers#

Mount one hover card instead of one per link. Put a value on each Trigger under one root and read it from the function children of HoverCard.Content: hovering another trigger moves the same card to it.

import { Avatar, HoverCard, Icon } from 'moraine'

const profiles = {
  ananya: {
    name: 'Ananya Rao',
    bio: 'Maintains the overlay primitives and the positioning layer.',
    joined: 'Joined March 2022',
  },
  jules: {
    name: 'Jules Ferreira',
    bio: 'Works on recipes, tokens, and theme compilation.',
    joined: 'Joined June 2022',
  },
  nico: {
    name: 'Nico Tanaka',
    bio: 'Keeps the docs site and the component examples current.',
    joined: 'Joined January 2023',
  },
} as const

export function MultipleTriggers() {
  return (
    <HoverCard openDelay={300}>
      <p class="text-sm text-foreground leading-6 max-w-xs">
        This release was reviewed by{' '}
        <HoverCard.Trigger value="ananya" href="/u/ananya" class="font-medium">
          @ananya
        </HoverCard.Trigger>
        {', '}
        <HoverCard.Trigger value="jules" href="/u/jules" class="font-medium">
          @jules
        </HoverCard.Trigger>
        {', and '}
        <HoverCard.Trigger value="nico" href="/u/nico" class="font-medium">
          @nico
        </HoverCard.Trigger>
        .
      </p>
      <HoverCard.Content>
        {(context) => {
          const profile = () => profiles[(context.value() ?? 'ananya') as keyof typeof profiles]
          return (
            <div class="flex gap-4">
              <Avatar text={profile().name.slice(0, 2).toUpperCase()} alt={profile().name} />
              <div class="space-y-1">
                <h4 class="text-sm font-semibold">{profile().name}</h4>
                <p class="text-sm">{profile().bio}</p>
                <div class="pt-2 flex gap-2 items-center">
                  <Icon name="i-lucide:calendar-days" class="opacity-70 size-4" />
                  <span class="text-xs text-muted-foreground">{profile().joined}</span>
                </div>
              </div>
            </div>
          )
        }}
      </HoverCard.Content>
    </HoverCard>
  )
}

Give a documentation link a small preview with the page title, a description, and the resolved URL. The link wraps across several lines, and the card anchors to the line the pointer entered.

import { HoverCard, Icon } from 'moraine'

export function LinkPreview() {
  return (
    <p class="text-sm text-foreground leading-6 max-w-xs">
      New here? Start with the{' '}
      <HoverCard placement="top" openDelay={300}>
        <HoverCard.Trigger
          href="/docs/getting-started"
          class="font-medium underline underline-offset-4"
        >
          getting started guide for new contributors to the design system
        </HoverCard.Trigger>
        <HoverCard.Content>
          <div class="space-y-2">
            <h4 class="text-sm font-semibold">Getting started</h4>
            <p class="text-xs text-foreground">
              Install the library, register the preset, and render your first component in a few
              minutes.
            </p>
            <div class="text-xs text-muted-foreground pt-1 flex gap-2 items-center">
              <Icon name="i-lucide:link" class="size-3.5" />
              <span>moraine.dev/docs/getting-started</span>
            </div>
          </div>
        </HoverCard.Content>
      </HoverCard>{' '}
      before diving into individual primitives.
    </p>
  )
}

API Reference#

Attributes#

Attributes
data-closed
Slot: hover-card-triggerhover-card-content
Description: Present when disclosure or transition content is closed.
data-disabled
Slot: hover-card-trigger
Description: Present when the component, slot, or item is disabled.
data-expanded
Slot: hover-card-triggerhover-card-content
Description: Present when the panel, accordion, or menu is expanded.
data-align
Slot: hover-card-content
Description: Stores the resolved alignment of positioned content.
data-instant-motion
Slot: hover-card-content
Description: Present when enter and exit motion should complete immediately.
data-side
Slot: hover-card-content
Description: Stores the resolved floating or drawer content side.

Props#

HoverCard#

Prop

Trigger#

Renders a <a> element by default.

Prop

Content#

Props for the HoverCard component. Renders a <div> element by default.

Prop