Hover Card

A card that opens when the user points at a link, with a preview of what it leads to.

@leverui

Usage

Code
import { HoverCard } from '@leverui/components';
Code
<HoverCard.Root>
  <HoverCard.Trigger />
  <HoverCard.Positioner>
    <HoverCard.Content>
      <HoverCard.Arrow>
        <HoverCard.ArrowTip />
      </HoverCard.Arrow>
    </HoverCard.Content>
  </HoverCard.Positioner>
</HoverCard.Root>

Shortcuts

Arrow

By default, HoverCard.Arrow renders HoverCard.ArrowTip inside itself.

Code
<HoverCard.Arrow>
  <HoverCard.ArrowTip />
</HoverCard.Arrow>

Shorter, if you keep the default tip:

Code
<HoverCard.Arrow />

Examples

Controlled

Use the open and onOpenChange to control the visibility of the hover card.

@leverui

Multiple Triggers

Don't mount a hover card per link. Put value on each Trigger under one Root. Hover another trigger and the same card moves to it.

Delays

Control the open and close delays using the openDelay and closeDelay props.

@leverui

Placement

Use the positioning.placement prop to configure the underlying floating-ui positioning logic.

@leverui

Disabled

Use the disabled prop to prevent opening the hover card on interaction.

@leverui

Open From Dialog

To use the HoverCard within a Dialog, you need to avoid portalling the HoverCard.Positioner to the document's body.

Code
-<Portal>
  <HoverCard.Positioner>
    <HoverCard.Content>
      {/* ... */}
    </HoverCard.Content>
  </HoverCard.Positioner>
-</Portal>

Accessibility

Extra information only. Screen readers do not announce the card as part of the trigger, so the page must make sense without it.

Opens on hover or keyboard focus. Keep the trigger focusable and give links in the card clear names. For a panel that opens on a click or key press, stays open and takes interaction, use Popover.

Props

Root

PropDefaultTypeDescription
closeDelay300numberMilliseconds before closing after the mouse leaves the trigger or content.
openDelay600numberMilliseconds before opening after the mouse enters the trigger.
size'md''xs' | 'sm' | 'md' | 'lg'Hover card size.
unstyled—booleanTurn off the default styles. Behavior stays.
defaultOpen—booleanOpen on first render.
defaultTriggerValue—stringTrigger value on first render.
disabled—booleanDisable the hover card.
id—stringUnique id.
ids—Element ID mapIds for the hover card's parts.
immediate—booleanApply present changes right away, not next frame.
lazyMountfalsebooleanWait for the first open to render content.
onExitComplete—() => voidCalled when the closing animation ends.
onFocusOutside—(event: FocusOutsideEvent) => voidCalled when focus moves outside.
onInteractOutside—(event: InteractOutsideEvent) => voidCalled on an interaction outside.
onOpenChange—(details: HoverCardOpenChangeDetails) => voidCalled when the hover card opens or closes.
onPointerDownOutside—(event: PointerDownOutsideEvent) => voidCalled on pointer down outside.
onTriggerValueChange—(details: TriggerValueChangeDetails) => voidCalled when the trigger value changes.
open—booleanOpen state, when you control it.
positioning—PositioningOptionsPositioning options.
present—booleanContent presence, when you control it.
skipAnimationOnMountfalsebooleanSkip the animation the first time content appears.
triggerValue—stringTrigger value, when you control it.
unmountOnExitfalsebooleanRemove content from the page after close.

Trigger

PropDefaultTypeDescription
asbuttonNative HTML tagHTML tag to render.
asChild—Solid render functionRender your own element with the trigger's props.
value—stringValue that identifies this trigger.

HoverCardPropsProvider sets default props for the hover cards inside it. lazyMount and unmountOnExit keep fewer hidden elements in the page.

Customize with CSS

Set class or style on a part, or override its CSS variables.

Code
.profile-preview {
  --leverui-hover-card-background: #f5f8ff;
  --leverui-hover-card-padding: 1.25rem;
}

Put class="profile-preview" on HoverCard.Content. The arrow takes the content's background. size can be responsive.

Explorer

Click a part name in the sidebar to highlight it in the preview.

Component Anatomy

Hover to highlight, click to select parts