Skip to content
VinUIComponentsHover Card

Hover Card

A preview card that opens when you rest the pointer on a link, or focus it with the keyboard. Same markup and props in every style: switch the style in the header to see it change.

Profile preview

Rest the pointer on the name, or Tab to it. In HTML, add data-vin-hover-card and include vinui.js once.

Typography by @ada, who also wrote the first program.

AL

Ada Lovelace

@ada

Mathematician. Wrote notes on the Analytical Engine, including the first published program.

Joined December 1815

hover-card-basic.html
<p class="vin-p">Typography by <a class="vin-link" href="#" data-vin-hover-card="hc-ada">@ada</a>, who also wrote the first program.</p>
<div class="vin-popover vin-hover-card" id="hc-ada" popover="manual">
  <div class="vin-hover-card__header">
    <span class="vin-avatar" role="img" aria-label="Ada Lovelace">
      <img class="vin-avatar__img" src="/ui/avatars/ada.svg" alt="">
      <span class="vin-avatar__fallback">AL</span>
    </span>
    <div>
      <p class="vin-popover__title">Ada Lovelace</p>
      <p class="vin-hover-card__meta">@ada</p>
    </div>
  </div>
  <p class="vin-popover__description">Mathematician. Wrote notes on the Analytical Engine, including the first published program.</p>
  <p class="vin-hover-card__meta"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="3" y="4.5" width="18" height="16.5" rx="2.5"/><path d="M3 9.5h18M8 2.5v4M16 2.5v4"/></svg>Joined December 1815</p>
</div>

Preview a page before opening it.

Installation

React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:

Terminal
npx @vinish/ui add hover-card
React
import { HoverCard } from "@/components/vin/hover-card";
Vue
import HoverCard from "@/components/vin/hover-card.vue";
Svelte
import HoverCard from "$lib/components/vin/hover-card.svelte";

The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.

Plain HTML: the classes come with the style's stylesheet. This component also needs vinui.js for its keyboard and pointer behaviour.

API

From spec/hover-card.json, which every framework version is tested against.

PropValuesDefaultIn HTML
trigger
The link (or button) it previews.
ReactElement—a[data-vin-hover-card="card-id"]
children
The card's content. Use the Popover title and description classes, an Avatar, and .vin-hover-card__meta for small details.
ReactNode—.vin-popover.vin-hover-card#card-id[popover=manual]
sidebottomtopleftrightbottomdata-side on the card
openDelay / closeDelay
Milliseconds before it opens on hover and before it closes after the pointer leaves.
number500 / 300—

Parts

React, Vue, SvelteHTML classes
<HoverCard>.vin-hover-card.vin-hover-card__header.vin-hover-card__meta

Accessibility

  • Opens on hover after a short pause, and straight away on keyboard focus; Esc closes it.
  • The pointer can move onto the card (to select text or follow a link in it) without it closing.
  • It shows extra detail only: anything people need must also be on the page, because touch screens can't hover.
  • Placed in the top layer, flipping to the other side when there's no room.