Hover card
A rich preview (a profile, a link) that opens on hover or keyboard focus.
Example
Reviewed by
<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>import { HoverCard } from '@focsd-dev/react';
export function Example() { return <HoverCard onClose={(e) => console.log(e.target)}>…</HoverCard>;}<script setup>import '@focsd-dev/components/focsd-hover-card.js';</script>
<template> <focsd-hover-card @close="onChange">…</focsd-hover-card></template>// Add CUSTOM_ELEMENTS_SCHEMA to the component's schemas, then:import '@focsd-dev/components/focsd-hover-card.js';
// template<focsd-hover-card (close)="onChange($event)">…</focsd-hover-card><script> import '@focsd-dev/components/focsd-hover-card.js';</script>
<focsd-hover-card onclose={(e) => console.log(e.target)}>…</focsd-hover-card>API
Attributes
| Attribute | Property | Type | Default |
|---|---|---|---|
placement | placement | 'top' | 'bottom' | bottom |
open-delay | openDelay | number | 600 |
close-delay | closeDelay | number | 300 |
open | open | boolean | false |
Methods
| Method | Description |
|---|---|
show() | Open the card now, skipping open-delay. |
hide() | Close the card now, skipping close-delay. |
Events
| Event | Description |
|---|---|
close | Fired when the card closes. |
Slots
| Slot | Description |
|---|---|
trigger | The 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).
| Part | Description |
|---|---|
card | The 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
| Key | Action |
|---|---|
| Tab | Focus the trigger (opens), then move into the card |
| Escape | Close the card, keep focus |
Ask the docs
Hi, what are you building?
Ask about any component, theming, forms or frameworks. I answer with the right component, a snippet and a link to its docs.