Hover card
Shows a preview of a link or a person when the pointer rests on it or focus reaches it, and leaves the link working.
import { Avatar } from '@slotted/react/avatar';import { HoverCard, HoverCardContent, HoverCardTrigger } from '@slotted/react/hover-card';import { Inline } from '@slotted/react/inline';import { PopoverBody } from '@slotted/react/popover';import { Stack } from '@slotted/react/stack';import { Text } from '@slotted/react/typography';export default function HoverCardBasic() { return ( <Text> The pricing table is ready for review. Ask{' '} <HoverCard> <HoverCardTrigger href="/people/nancy.davolio">@nancy.davolio</HoverCardTrigger> <HoverCardContent> <PopoverBody> <Inline align="center" gap={3}> <Avatar name="Nancy Davolio" /> <Stack gap={1}> <Text weight="semibold">Nancy Davolio</Text> <Text size="sm" tone="muted"> Sales Representative, Seattle </Text> </Stack> </Inline> </PopoverBody> </HoverCardContent> </HoverCard>{' '} about the carrier rates. </Text> );}Installation
The packages are a 0.x beta on npm, and their public API changes between beta releases without deprecation. One line installs the binding and the default theme.
pnpm add @slotted/react @slotted/theme @slotted/themesimport { HoverCard, HoverCardTrigger, HoverCardContent, HoverCardDefaultsProvider } from '@slotted/react/hover-card';import { PopoverBody, PopoverTitle, PopoverFooter } from '@slotted/react/popover';Previewing a link
The trigger is a native a element, so Enter follows it, a middle click opens it in a new tab and a screen reader announces a link. The card opens after the pointer has rested on the trigger for openDelay, which is 600 ms by default, and opens at once when keyboard focus arrives. A press that focuses the link does not open it. The card stays while the pointer moves onto it, including along the diagonal path from the trigger, and closes closeDelay after the pointer has left both, which is 300 ms by default. The card never takes focus, and Escape closes it. Title and description come from the popover parts, which the card uses unchanged.
import { HoverCard, HoverCardContent, HoverCardTrigger } from '@slotted/react/hover-card';import { PopoverBody, PopoverDescription, PopoverHeader, PopoverTitle,} from '@slotted/react/popover';import { Text } from '@slotted/react/typography';export default function HoverCardLinkPreview() { return ( <Text> Freight for October follows the{' '} <HoverCard> <HoverCardTrigger href="/documents/q4-carrier-rate-card"> Q4 carrier rate card </HoverCardTrigger> <HoverCardContent> <PopoverHeader> <PopoverTitle>Q4 carrier rate card</PopoverTitle> <PopoverDescription>Spreadsheet, updated 2 hours ago</PopoverDescription> </PopoverHeader> <PopoverBody> <Text size="sm"> Freight rates by carrier and zone for October through December, with the fuel surcharge from Oct 1. </Text> </PopoverBody> </HoverCardContent> </HoverCard> , which Federal Shipping has already signed. </Text> );}Navigable cards
A card with a control inside is declared with navigable. The panel then becomes a dialog named by its title, the trigger sets aria-haspopup, aria-expanded and aria-controls, and Tab on the open trigger moves focus into the card. Tabbing past either end of the card closes it and returns focus to the trigger, which does not reopen until focus has left it once. Without navigable, the panel has the presentation role, the keyboard cannot reach it and the trigger announces nothing. Put information in a card that is not navigable, and put anything a reader must act on in the destination.
import { Button } from '@slotted/react/button';import { HoverCard, HoverCardContent, HoverCardTrigger } from '@slotted/react/hover-card';import { PopoverBody, PopoverDescription, PopoverFooter, PopoverHeader, PopoverTitle,} from '@slotted/react/popover';import { Text } from '@slotted/react/typography';export default function HoverCardNavigable() { return ( <Text> The credit limit for Around the Horn is waiting on{' '} <HoverCard navigable> <HoverCardTrigger href="/people/andrew.fuller">@andrew.fuller</HoverCardTrigger> <HoverCardContent> <PopoverHeader> <PopoverTitle>Andrew Fuller</PopoverTitle> <PopoverDescription>Vice President, Sales</PopoverDescription> </PopoverHeader> <PopoverBody> <Text size="sm">Approves credit limits above $25,000.</Text> </PopoverBody> <PopoverFooter> <Button size="sm">Send message</Button> </PopoverFooter> </HoverCardContent> </HoverCard> . </Text> );}Delays
openDelay and closeDelay are milliseconds, set per card. Use a short open delay where the preview is the purpose of the page, and a longer close delay where the card holds text a reader needs time to move onto. Focus ignores openDelay.
import { HoverCard, HoverCardContent, HoverCardTrigger } from '@slotted/react/hover-card';import { PopoverBody } from '@slotted/react/popover';import { Stack } from '@slotted/react/stack';import { Text } from '@slotted/react/typography';export default function HoverCardDelays() { return ( <Stack gap={4}> <Text> Default delays, 600 ms to open and 300 ms to close:{' '} <HoverCard> <HoverCardTrigger href="/orders/10248">Order 10248</HoverCardTrigger> <HoverCardContent> <PopoverBody> <Text size="sm">Vins et alcools Chevalier, $440.00, shipped Jul 16.</Text> </PopoverBody> </HoverCardContent> </HoverCard> </Text> <Text> Immediate open, closes after 1 second:{' '} <HoverCard openDelay={0} closeDelay={1000}> <HoverCardTrigger href="/orders/10249">Order 10249</HoverCardTrigger> <HoverCardContent> <PopoverBody> <Text size="sm">Toms Spezialitäten, $1,863.40, shipped Jul 10.</Text> </PopoverBody> </HoverCardContent> </HoverCard> </Text> </Stack> );}Disabled
disabled stops the card from opening on hover, focus and tap. The link keeps its href, navigates as usual and shows no disabled styling. Use it for a record whose preview no longer exists.
import { HoverCard, HoverCardContent, HoverCardTrigger } from '@slotted/react/hover-card';import { PopoverBody } from '@slotted/react/popover';import { Text } from '@slotted/react/typography';export default function HoverCardDisabled() { return ( <Text> Territory handoff from{' '} <HoverCard> <HoverCardTrigger href="/people/nancy.davolio">@nancy.davolio</HoverCardTrigger> <HoverCardContent> <PopoverBody> <Text size="sm">Nancy Davolio, Sales Representative, Seattle.</Text> </PopoverBody> </HoverCardContent> </HoverCard>{' '} to{' '} <HoverCard disabled> <HoverCardTrigger href="/people/robert.king">@robert.king</HoverCardTrigger> <HoverCardContent> <PopoverBody> <Text size="sm">Robert King, Sales Representative, London.</Text> </PopoverBody> </HoverCardContent> </HoverCard> , whose profile is archived. </Text> );}Placement
The card is the popover family behind a hover trigger, so side, align, size, width and the other popover options go on the card. The card prefers the side it is given and flips when the viewport has no room. sideOffset defaults to 4 so the arrow stays clear of the trigger’s highlight.
import { HoverCard, HoverCardContent, HoverCardTrigger } from '@slotted/react/hover-card';import { PopoverBody } from '@slotted/react/popover';import { Text } from '@slotted/react/typography';export default function HoverCardPlacement() { return ( <Text> Reorder{' '} <HoverCard side="top" align="center"> <HoverCardTrigger href="/products/1001">Chai</HoverCardTrigger> <HoverCardContent> <PopoverBody> <Text size="sm">NW-1001, 39 units on hand.</Text> </PopoverBody> </HoverCardContent> </HoverCard> ,{' '} <HoverCard> <HoverCardTrigger href="/products/1002">Chang</HoverCardTrigger> <HoverCardContent> <PopoverBody> <Text size="sm">NW-1002, 17 units on hand.</Text> </PopoverBody> </HoverCardContent> </HoverCard>{' '} and{' '} <HoverCard side="inline-end" align="center"> <HoverCardTrigger href="/products/1003">Aniseed Syrup</HoverCardTrigger> <HoverCardContent> <PopoverBody> <Text size="sm">NW-1003, 13 units on hand.</Text> </PopoverBody> </HoverCardContent> </HoverCard>{' '} before Friday. </Text> );}Controlled
Pass open to own the state. React calls onOpenChange(open, request) and Angular emits openChangeRequest, with the request’s reason: pointer, keyboard, escape, outsidePress, blur, dismiss or programmatic. request.cancel() refuses the change. In Angular, [(open)] binds the state in both directions. Here the line under the text reports the state and the last reason; rest the pointer on the link, press Tab onto it and press Escape to read each reason.
import { useState } from 'react';import { HoverCard, HoverCardContent, HoverCardTrigger } from '@slotted/react/hover-card';import type { HoverCardChangeRequest } from '@slotted/react/hover-card';import { PopoverBody, PopoverDescription, PopoverHeader, PopoverTitle,} from '@slotted/react/popover';import { Stack } from '@slotted/react/stack';import { Text } from '@slotted/react/typography';export default function HoverCardControlled() { const [open, setOpen] = useState(false); const [reason, setReason] = useState('none'); function handleOpenChange(next: boolean, request: HoverCardChangeRequest) { setOpen(next); setReason(request.reason); } return ( <Stack gap={3}> <Text> Stock for order 10251 ships from the{' '} <HoverCard open={open} onOpenChange={handleOpenChange}> <HoverCardTrigger href="/warehouses/seattle">Seattle warehouse</HoverCardTrigger> <HoverCardContent> <PopoverHeader> <PopoverTitle>Seattle warehouse</PopoverTitle> <PopoverDescription>400 Pine Street, Dock 3</PopoverDescription> </PopoverHeader> <PopoverBody> <Text size="sm">Pickups close at 4:30 PM, Monday to Friday.</Text> </PopoverBody> </HoverCardContent> </HoverCard> . </Text> <Text size="sm" tone="muted"> Card {open ? 'open' : 'closed'}. Last request: {reason}. </Text> </Stack> );}One card for several triggers
Several triggers inside one card share it, so a long thread does not mount one card per mention. The trigger that starts an opening becomes the anchor, and the request’s source is the event that started it. Its target is the trigger or an element inside it, so target.closest() finds the trigger, and the card reads the trigger’s data attributes and fills from one piece of state. React puts all triggers inside one HoverCard; Angular puts them inside one slHoverCard container.
import { useState } from 'react';import { HoverCard, HoverCardContent, HoverCardTrigger } from '@slotted/react/hover-card';import type { HoverCardChangeRequest } from '@slotted/react/hover-card';import { PopoverBody, PopoverDescription, PopoverHeader, PopoverTitle,} from '@slotted/react/popover';import { Text } from '@slotted/react/typography';interface Person { handle: string; name: string; role: string;}const nancy: Person = { handle: 'nancy.davolio', name: 'Nancy Davolio', role: 'Sales Representative, Seattle',};const andrew: Person = { handle: 'andrew.fuller', name: 'Andrew Fuller', role: 'Vice President, Sales',};const janet: Person = { handle: 'janet.leverling', name: 'Janet Leverling', role: 'Sales Representative, Kirkland',};const people = [nancy, andrew, janet];export default function HoverCardShared() { const [person, setPerson] = useState(nancy); function handleOpenChange(open: boolean, request: HoverCardChangeRequest) { const target = request.source instanceof Event ? request.source.target : null; const trigger = target instanceof Element ? target.closest<HTMLElement>('[data-handle]') : null; if (!open || trigger === null) return; const next = people.find((candidate) => candidate.handle === trigger.dataset['handle']); if (next !== undefined) setPerson(next); } return ( <HoverCard onOpenChange={handleOpenChange}> <Text> The pricing table was drafted by{' '} <HoverCardTrigger data-handle={nancy.handle} href="/people/nancy.davolio"> @nancy.davolio </HoverCardTrigger> , approved by{' '} <HoverCardTrigger data-handle={andrew.handle} href="/people/andrew.fuller"> @andrew.fuller </HoverCardTrigger>{' '} and handed to{' '} <HoverCardTrigger data-handle={janet.handle} href="/people/janet.leverling"> @janet.leverling </HoverCardTrigger>{' '} for the carrier terms. </Text> <HoverCardContent> <PopoverHeader> <PopoverTitle>{person.name}</PopoverTitle> <PopoverDescription>{person.role}</PopoverDescription> </PopoverHeader> <PopoverBody> <Text size="sm">@{person.handle}</Text> </PopoverBody> </HoverCardContent> </HoverCard> );}Defaults for an application
HoverCardDefaultsProvider in React and provideHoverCardDefaults in Angular set openDelay, closeDelay and navigable once for everything beneath them. React’s provider also sets disabled. A card that states a value of its own keeps it, as the second mention does with closeDelay.
import { HoverCard, HoverCardContent, HoverCardDefaultsProvider, HoverCardTrigger,} from '@slotted/react/hover-card';import { PopoverBody } from '@slotted/react/popover';import { Text } from '@slotted/react/typography';export default function HoverCardDefaults() { return ( <HoverCardDefaultsProvider openDelay={200} closeDelay={200}> <Text> Escalate to{' '} <HoverCard> <HoverCardTrigger href="/people/steven.buchanan">@steven.buchanan</HoverCardTrigger> <HoverCardContent> <PopoverBody> <Text size="sm">Steven Buchanan, Sales Manager, London.</Text> </PopoverBody> </HoverCardContent> </HoverCard>{' '} or, for returns, to{' '} <HoverCard closeDelay={1000}> <HoverCardTrigger href="/people/margaret.peacock">@margaret.peacock</HoverCardTrigger> <HoverCardContent> <PopoverBody> <Text size="sm">Margaret Peacock, Sales Representative, Redmond.</Text> </PopoverBody> </HoverCardContent> </HoverCard> . </Text> </HoverCardDefaultsProvider> );}Touch
A touch screen has no hover. The first tap on the trigger opens the card and does not follow the link, and a tap on the trigger while its card is open follows the link. Navigation costs one extra tap, and the preview stays available. Put a PopoverClose in the header of a card on touch-first pages, since there is no Escape key.
Accessibility
| Key | Effect | Focus |
|---|---|---|
| Tab | on the open trigger with navigable, moves into the card's first tabbable; otherwise moves on, and the card closes with blur | the card's first tabbable, or the next element in the page |
| Shift+Tab | moves back; a card opened by focus closes with blur | the previous element in the page |
| Escape | closes the card | unchanged when on the trigger; back to the trigger when inside the card |
| Enter | follows the link, which is the trigger's own | the destination |
- The platform supplies the link: it is a native anchor, so Enter follows it, a middle click opens it in a tab and a screen reader hears a link. The card never takes focus when it opens — autoFocus is forced off on the popover it holds — so the reader’s focus stays on the word under the pointer.
- The hover card answers WCAG 2.2 SC 1.4.13 item by item: the card is dismissible with Escape and no pointer movement, hoverable because the pointer may move onto it and the grace area keeps it open on the way, and persistent because it stays until hover and focus have left both link and card.
- A popup that assistive technology cannot reach is not announced: a card the keyboard cannot enter is role="presentation", and the link says nothing about it. A navigable card is the APG’s non-modal dialog, named by its title, with aria-haspopup="dialog", aria-expanded and aria-controls on the link, and Tab from the link enters it.
- Focus that the hover card itself puts back on the link — after Escape inside the card, after a focus guard — does not reopen the card; the link holds the reopening back until focus has left it once. Without that rule a guard would close the card, focus the link, and open the card again.
API
HoverCard
Props
openboolean | undefined- Whether the card shows. Present at all puts the card in controlled mode: it asks and waits.
defaultOpenboolean- The value an uncontrolled card starts from, read once.
onOpenChange(open, request) => void- Asked before the card opens or closes, with the reason and the originating event, and refusable.
openDelaynumberDefault600- Milliseconds the pointer rests on the trigger before the card opens. Focus never waits.
closeDelaynumberDefault300- Milliseconds after the pointer has left trigger and card before it closes; a pointer on its way to the card is not counted as gone.
navigablebooleanDefaultfalse- Whether the card holds controls a keyboard reader can reach. On, the panel is a dialog, the link announces it and Tab enters it; off, the panel is presentation.
disabledbooleanDefaultfalse- The card never opens. The link keeps working, and carries no disabled state.
sideOffsetnumberDefault4- The popover’s own axis, with the hover card’s default: the halo the open mark draws plus the same again of air, so the arrow’s tip stands off the word.
side, align, size, width, arrow, mount, …PopoverProps- Every prop of Popover except autoFocus, which the hover card forces off, reaches the popover it renders.
render(props) => ReactNode- On HoverCardTriggerRenders the consumer's own element as the trigger — a Link, an avatar button — with the identity, the state and the listeners on it.
Events
| Name | Payload | When |
|---|---|---|
onOpenChange | (open: boolean, request: HoverCardChangeRequest) | Before the card opens or closes. The request carries pointer (hover in, hover out, a tap), keyboard (focus arriving, a focus guard), escape, outsidePress, blur (focus leaving the trigger), dismiss (the Close part) or programmatic, the originating event, and cancel(). |
Composition
HoverCardDefaultsProvidercomponent- On ApplicationSets openDelay, closeDelay, navigable and disabled once for a subtree. A card that states one itself still wins. The panel reads PopoverDefaultsProvider.
PopoverHeader, PopoverTitle, PopoverBody, PopoverFooter, PopoverClose, …components- On Inside HoverCardContentThe card is the popover family unchanged, and nothing is re-exported: its title names a navigable card, its Close is the touch reader’s Escape.
HoverCardContentcomponent- On Inside a HoverCardThe popover’s layer and panel in one, with the hover card’s pointer handlers on the layer and the panel’s role decided by navigable. Its props reach the panel; the arrow is rendered under the popover’s arrow axis.
refprop- A PopoverHandle carrying open(), close() and reposition().
native propsattributes- On HoverCardTriggerAnything an anchor takes — href, rel, target — reaches the link, and a consumer's own onPointerEnter or onFocus runs before the hover card's own; preventDefault from it stops the hover card's handler.
Parts
| Part | Element | Required | Purpose |
|---|---|---|---|
root | a, or the element render returns | Yes | The trigger: the link the card is about. It carries data-ui="hover-card", data-open while its card shows, and — only when the card is navigable — aria-haspopup="dialog", aria-expanded and aria-controls. The card itself is the popover family unchanged, data-ui="popover", so the hover card declares no other part. |
Theming
Each token is a CSS custom property: set it in a theme, or on any element to retune every hover card inside it.
Hover card tokens
| Token | Default |
|---|---|
--slotted-hover-card-color | var(--slotted-tone-accent-text, LinkText) |
--slotted-hover-card-halo | var(--slotted-space-1, 0.125rem) |
--slotted-hover-card-radius | var(--slotted-radius-xs, 2px) |
--slotted-hover-card-tint | color-mix( in oklab, var(--_text) calc(var(--slotted-highlight-tint-opacity, 0.075) * 100%), transparent ) |
--slotted-hover-card-underline-color | color-mix(in oklab, var(--_text) 40%, transparent) |
Theme tokens it reads
| Token | Default |
|---|---|
--slotted-border-width-thick | 2px |
--slotted-duration-short | 120ms |
--slotted-easing-standard | cubic-bezier(0.2, 0, 0, 1) |
--slotted-focus-ring-color | Set per scheme by the theme |
--slotted-focus-ring-offset | var(--slotted-border-width-thick) |
--slotted-focus-ring-width | var(--slotted-border-width-thick) |
--slotted-highlight-tint-opacity | 0.075 |
--slotted-radius-xs | 2px |
--slotted-space-1 | 0.125rem |
--slotted-tone-accent-text | Set per scheme by the theme |