Hover Card
A card that opens when the user points at a link, with a preview of what it leads to.
Lever UI
Accessible components for SolidJS apps, styled with plain CSS.
2.5M downloads
Usage
import { HoverCard } from '@leverui/components';
<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.
<HoverCard.Arrow>
<HoverCard.ArrowTip />
</HoverCard.Arrow>
Shorter, if you keep the default tip:
<HoverCard.Arrow />
Examples
Controlled
Use the open and onOpenChange to control the visibility of the hover card.
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.
Placement
Use the positioning.placement prop to configure the underlying floating-ui positioning logic.
Disabled
Use the disabled prop to prevent opening the hover card on interaction.
Lever UI
Accessible components for SolidJS apps, styled with plain CSS.
Open From Dialog
To use the HoverCard within a Dialog, you need to avoid portalling the
HoverCard.Positioner to the document's body.
-<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
| Prop | Default | Type | Description |
|---|---|---|---|
closeDelay | 300 | number | Milliseconds before closing after the mouse leaves the trigger or content. |
openDelay | 600 | number | Milliseconds before opening after the mouse enters the trigger. |
size | 'md' | 'xs' | 'sm' | 'md' | 'lg' | Hover card size. |
unstyled | — | boolean | Turn off the default styles. Behavior stays. |
defaultOpen | — | boolean | Open on first render. |
defaultTriggerValue | — | string | Trigger value on first render. |
disabled | — | boolean | Disable the hover card. |
id | — | string | Unique id. |
ids | — | Element ID map | Ids for the hover card's parts. |
immediate | — | boolean | Apply present changes right away, not next frame. |
lazyMount | false | boolean | Wait for the first open to render content. |
onExitComplete | — | () => void | Called when the closing animation ends. |
onFocusOutside | — | (event: FocusOutsideEvent) => void | Called when focus moves outside. |
onInteractOutside | — | (event: InteractOutsideEvent) => void | Called on an interaction outside. |
onOpenChange | — | (details: HoverCardOpenChangeDetails) => void | Called when the hover card opens or closes. |
onPointerDownOutside | — | (event: PointerDownOutsideEvent) => void | Called on pointer down outside. |
onTriggerValueChange | — | (details: TriggerValueChangeDetails) => void | Called when the trigger value changes. |
open | — | boolean | Open state, when you control it. |
positioning | — | PositioningOptions | Positioning options. |
present | — | boolean | Content presence, when you control it. |
skipAnimationOnMount | false | boolean | Skip the animation the first time content appears. |
triggerValue | — | string | Trigger value, when you control it. |
unmountOnExit | false | boolean | Remove content from the page after close. |
Trigger
| Prop | Default | Type | Description |
|---|---|---|---|
as | button | Native HTML tag | HTML tag to render. |
asChild | — | Solid render function | Render your own element with the trigger's props. |
value | — | string | Value 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.
.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