Skip to Content
CodeUI

HoverCard

@codeui/styles v0.3.0

A card of extra detail next to a link, in plain HTML.

Load @codeui/styles/hovercard.css, or all.css. The Solid component is documented in HoverCard.

Demo

hover-card/basic.html
<div class="cui-stack" data-gap="1" data-align="start">  <a href="#thread" class="cui-link" data-cui="hovercard-trigger" data-expanded>Fix flaky hydration test</a>  <div class="cui-hovercard-content" data-cui="hovercard-content" data-expanded>    <strong>Fix flaky hydration test</strong>    <span>Opened 2 hours ago · 3 subagents</span>  </div></div>

The demo renders the open card in normal flow, under its trigger. On a page, the card floats and your positioning code places it.

Markup

PartElementClassdata-cui
Triggera with an href. It gets a dotted underline in the hint tonenonehovercard-trigger
Contentdivcui-hovercard-contenthovercard-content
Listul with an aria-labelcui-hovercard-listhovercard-list
Entrylicui-hovercard-itemhovercard-item
State iconspan, 16px, always presentcui-hovercard-item-iconhovercard-item-icon
Identifierspancui-hovercard-item-idhovercard-item-id
Titlespan, truncatedcui-hovercard-item-titlehovercard-item-title
AttributeValuesDefault
data-expanded on the triggerPresence, while the card is open. The dotted underline takes the text colourOff
data-expanded on the contentPresenceOff
data-motion on the contentnoneNone

List of entries

hover-card/list.html
<div class="cui-hovercard-content" data-cui="hovercard-content" data-expanded data-motion="none">  <span class="cui-text" data-cui="text" data-weight="semibold">Migrate the kit to Solid 2</span>  <ul class="cui-hovercard-list" data-cui="hovercard-list" aria-label="Tasks" tabindex="0">    <li class="cui-hovercard-item" data-cui="hovercard-item">      <span class="cui-hovercard-item-icon" data-cui="hovercard-item-icon" role="img" aria-label="Running"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5"><circle cx="8" cy="8" r="5.5" /><path d="M8 2.5a5.5 5.5 0 0 1 0 11z" fill="currentColor" /></svg></span>      <span class="cui-hovercard-item-id" data-cui="hovercard-item-id">T-12</span>      <span class="cui-hovercard-item-title" data-cui="hovercard-item-title">Migrate the kit to Solid 2</span>    </li>    <li class="cui-hovercard-item" data-cui="hovercard-item" style="--cui-hovercard-item-depth: 1">      <span class="cui-hovercard-item-icon" data-cui="hovercard-item-icon" role="img" aria-label="Done"></span>      <span class="cui-hovercard-item-id" data-cui="hovercard-item-id">T-13</span>      <span class="cui-hovercard-item-title" data-cui="hovercard-item-title">Port Popover and Tooltip to the new reactivity model</span>    </li>    <li class="cui-hovercard-item" data-cui="hovercard-item" style="--cui-hovercard-item-depth: 2">      <span class="cui-hovercard-item-icon" data-cui="hovercard-item-icon" role="img" aria-label="To do"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5"><circle cx="8" cy="8" r="5.5" /></svg></span>      <span class="cui-hovercard-item-id" data-cui="hovercard-item-id">T-15</span>      <span class="cui-hovercard-item-title" data-cui="hovercard-item-title">Keep keyboard opens free of motion</span>    </li>  </ul></div>

One line per entry: state icon, identifier, then the title truncated. Set --cui-hovercard-item-depth on an entry to indent it 16px per level. The list caps at 24rem and scrolls on its own. Keep the icon span on a finished entry, empty, so the identifiers line up.

States

Open

data-expanded plays the pop-in: a fade from scale(0.96). The animation grows from --cui-popper-content-transform-origin, so set it to the side that faces the trigger. Without data-expanded, the content plays its exit animation and stays transparent. Set it on an open card even without a script.

Closing

Remove data-expanded while the card is still in the page, and remove the card when the animation ends. data-motion="none" turns off both animations. Use it when the card opens from keyboard focus. With reduced motion, the card only fades.

What you supply

  • Showing the card at once on a click or tap, and 500ms after the pointer rests on the trigger or the trigger gets focus, and hiding it 150ms after the pointer leaves the trigger and the card, on blur, and on Escape.
  • Placement beside the trigger, on the right unless there is no room, then on the left, and --cui-popper-content-transform-origin.
  • A focusable trigger. Nothing in the card may be the only way to reach an action: the card never takes focus.

Helper

import "@codeui/styles/hovercard.css";
import { hoverCardParts, hoverCardStyles } from "@codeui/styles/hovercard";

const card = document.querySelector<HTMLElement>("#thread-card")!;
card.className = hoverCardStyles.content();
card.dataset.cui = hoverCardParts.content;
// class="cui-hovercard-content" data-cui="hovercard-content"

On this page