Skip to content
Focsd homeFocsd homeFocsd
Forms

Hover card

A rich preview (a profile, a link) that opens on hover or keyboard focus.

  • Tag: focsd-hover-card
  • Pattern: Non-modal popover on hover/focus, hoverable and dismissible (1.4.13)
  • Category: Overlays

Example

Reviewed by Ada Lovelace Mathematician, Analytical Engine notes. Follow

HTML
<p>
Reviewed by
<focsd-hover-card>
<a slot="trigger" href="#">Ada Lovelace</a>
<focsd-avatar name="Ada Lovelace"></focsd-avatar>
<span>Mathematician, Analytical Engine notes.</span>
<focsd-button variant="action">Follow</focsd-button>
</focsd-hover-card>
</p>

Usage

Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.

<script type="module">
import '@focsd-dev/components/focsd-hover-card.js';
</script>
<focsd-hover-card>…</focsd-hover-card>

API

Attributes

AttributePropertyTypeDefault
placementplacement'top' | 'bottom'bottom
open-delayopenDelaynumber600
close-delaycloseDelaynumber300
openopenbooleanfalse

Methods

MethodDescription
show()Open the card now, skipping open-delay.
hide()Close the card now, skipping close-delay.

Events

EventDescription
closeFired when the card closes.

Slots

SlotDescription
triggerThe link or button the card previews.
(default)The card content.

CSS parts

Style the inside of the component with ::part(), for example focsd-hover-card::part(card).

PartDescription
cardThe card.

Accessibility

  • Opens on hover after a delay and on keyboard focus; stays open while the pointer or focus is on the trigger or the card; Escape closes it without moving focus (WCAG 1.4.13).
  • The card follows the trigger in focus order, so Tab moves into it, and leaving with Tab closes it.
  • The trigger is described by the card text and reports aria-expanded.
  • On touch, a tap follows the link and a long press opens the card.
  • Never put the only way to reach something in a hover card: keep the same content reachable elsewhere.

Keyboard

KeyAction
TabFocus the trigger (opens), then move into the card
EscapeClose the card, keep focus