Overlays
HoverCard
Free14.0 KB gzippedAccessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · Keys: Tab, Escape · Full report
Import
import { HoverCard } from "@vjdesigns/vjdesigns-ui";
Importing only HoverCard adds about 14.0 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.
Examples
Basic
A preview that opens while the pointer rests on the link, or while it has keyboard focus. Move the pointer onto the card and it stays; Escape closes it. Touch screens have no hover, so a tap just follows the link: keep everything in the card reachable from the page it links to.
Tonight's starter is Jordan Reyes, back from a sprained ankle.
import {
Avatar,
Flex,
HoverCard,
Link,
Stack,
Text,
} from "@vjdesigns/vjdesigns-ui";
export function Basic() {
return (
<Text>
Tonight's starter is{" "}
<HoverCard>
<HoverCard.Trigger>
<Link href="#example-basic">Jordan Reyes</Link>
</HoverCard.Trigger>
<HoverCard.Content>
<Flex gap={3} align="center">
<Avatar name="Jordan Reyes" colorFromName />
<Stack gap={1}>
<Text weight="semibold">Jordan Reyes</Text>
<Text size="sm" tone="muted">
Point guard · 18.4 points per game
</Text>
</Stack>
</Flex>
</HoverCard.Content>
</HoverCard>
, back from a sprained ankle.
</Text>
);
}
Right to left
The first example again, inside a right-to-left LocaleProvider (Arabic). Layout, spacing and arrow icons mirror, and the components' built-in text is translated. The example's own text stays in English.
Basic
Tonight's starter is Jordan Reyes, back from a sprained ankle.
import { LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";
// Basic is the "Basic" example above.
<LocaleProvider locale="ar" messages={ar}>
<Basic />
</LocaleProvider>
API reference
HoverCard
New in 1.5.0| Prop | Type | Default |
|---|---|---|
children
| ReactNode | — |
openControlled open state. | boolean | — |
defaultOpenInitial open state when uncontrolled. | boolean | false |
onOpenChangeCalled with the next open state. | (open: boolean) => void | — |
openDelayDelay before opening on hover or keyboard focus, in ms. | number | 500 |
closeDelayDelay before closing after the pointer leaves the trigger or the card, in ms. Gives the pointer time to cross the gap onto the card. | number | 300 |
HoverCard.Trigger
New in 1.5.0| Prop | Type | Default |
|---|---|---|
childrenRequiredExactly one focusable element, usually a | ReactElement | — |
HoverCard.Content
New in 1.5.0| Prop | Type | Default |
|---|---|---|
placementPreferred side and alignment. Flips to the other side when there isn't room. | "top""top-start""top-end""bottom""bottom-start""bottom-end""left""left-start""left-end""right""right-start""right-end" | "bottom" |
offsetGap between the trigger and the card, in px. | number | 8 |
sizeMaximum width and padding: | "sm""md""lg" | "md" |
showArrowShow an arrow pointing at the trigger. | boolean | false |
containerElement to portal into. | HTMLElement | null | document.body |
Also accepts native <div> attributes, plus className, style and ref.
See what changed in each version in the Changelog.
Accessibility report
HoverCard targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.
axe-core audit (live)
Checking the examples above…
Lighthouse audit
Light mode
Score 10035 passed · 0 failed · 30 not applicable · 10 to check by hand
Dark mode
Score 10035 passed · 0 failed · 30 not applicable · 10 to check by hand
Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.
Built-in behavior
Keyboard
| Key | Action |
|---|---|
| Tab | Focusing the trigger opens the card; Tab moves into its links and buttons, and past the last one continues after the trigger. |
| Escape | Closes the card. |
Meets WCAG 1.4.13: the pointer can move onto the card, it stays open while hovered or focused, and Escape dismisses it. It never opens from a tap, so its content must also be reachable from the page the trigger leads to.
Roles and states
| Element | Role | States and properties |
|---|---|---|
| Trigger | Its own (link or button) | Left untouched: the card is a preview, not part of its name |
| Card | none (generic) | Rendered after the trigger in focus order |
Manual checks
Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.
| Check | What to test | WCAG 2.2 |
|---|---|---|
| Keyboard | Every action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck. | 2.1.1 (A), 2.1.2 (A) |
| Focus | Focus moves in a logical order, is always visible, and isn't hidden behind sticky headers. | 2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA) |
| Screen readers | Names, roles and states are announced correctly, and status changes are announced without moving focus. | 1.3.1 (A), 4.1.2 (A), 4.1.3 (AA) |
| Color | Meaning never depends on color alone; your own colors meet contrast in both modes. | 1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA) |
| Zoom and reflow | At 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed. | 1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA) |
| Pointer targets | Click and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap. | 2.5.8 (AA), 2.5.5 (AAA) |
| Motion | Animations respect the reduced-motion setting. | 2.3.3 (AAA) |