FUNSTACK UI

HomeWhyGetting startedConceptsComponentsRoadmap
GitHub

FUNSTACK UI is in beta. Part of the FUNSTACK family with FUNSTACK Router and FUNSTACK Static, which build this site.

Introduction

  • Why FUNSTACK UI
  • Overview
  • Getting started

Concepts

  • Action props
  • Pending & optimistic state
  • Transitions & ViewTransition
  • Suspense
  • Browser-owned state
  • Server Components

Guides

  • Replacing the element (render)
  • Direction and locales
  • Experimental features
  • Next.js App Router
  • React Router framework mode
  • Content Security Policy
  • Using with AI agents

Components

  • Buttons
    • Button
    • Toggle
    • ToggleGroup
    • Toolbar
  • Disclosure
    • Tabs
    • Accordion
    • Collapsible
    • NavigationMenu
  • Overlays
    • Tooltip
    • HoverCard
    • Popover
    • Dialog
    • AlertDialog
    • Drawer
    • Menu
    • Context menu (Menu)
    • Menubar (Menu)
    • Toast
  • Forms
    • Field and Form
    • Checkbox
    • CheckboxGroup
    • RadioGroup
    • Switch
    • Select
    • Combobox
    • MultiSelect
    • Slider
    • NumberField
    • OTPField
    • TextField
  • Output
    • Progress
    • Meter
    • Avatar
  • Layout
    • Separator
    • Scroll areas (recipe)

Resources

  • Roadmap & changelog
  • GitHub ↗

HoverCard

A preview card for a link: the pointer rests on it, or keyboard focus does, and after a delay a card appears next to it. Unlike a Tooltip the card may hold links and buttons and is not the link's name or description; unlike a Popover nothing is clicked to open it, and opening never moves focus. Showing interest starts a transition: openChangeAction(true) is awaited, the content mounts inside it and may suspend, and the link is data-pending meanwhile. If the user moves on before the data arrives, the open is cancelled and the card never appears. Fifty mentions on a page render fifty empty popovers and fetch nothing until one is hovered.

Thanks @ada for the review, and @babbage for the original design.

Show code
HoverCardMentions.tsx
"use client";
import { use } from "react";
import { HoverCard } from "@funstack/ui/hover-card";
import { sleep } from "./fake-api.js";

interface User {
  readonly name: string;
  readonly bio: string;
  readonly repos: number;
}

const users: Record<string, User> = {
  ada: { name: "Ada Lovelace", bio: "Notes on the Analytical Engine.", repos: 12 },
  babbage: { name: "Charles Babbage", bio: "Difference engines, mostly.", repos: 3 },
};

// A pretend user API with a cache: one promise per login, read with `use()`. The first hover of
// a mention fetches (900 ms); later ones open at once.
const cache = new Map<string, Promise<User>>();
function fetchUser(login: string): Promise<User> {
  let promise = cache.get(login);
  if (promise === undefined) {
    promise = sleep(900).then(() => users[login] ?? { name: login, bio: "", repos: 0 });
    cache.set(login, promise);
  }
  return promise;
}

// Suspends until the user has loaded. The Popup has no Suspense boundary of its own, so the card
// appears complete; meanwhile the mention is `data-pending` (a dotted underline here).
function UserPreview({ login }: { login: string }) {
  const user = use(fetchUser(login));
  return (
    <>
      <strong className="demo-card-name">{user.name}</strong>
      <span className="demo-card-bio">{user.bio}</span>
      <span className="demo-card-row">
        <a href={`https://example.com/u/${login}?tab=repositories`}>{user.repos} repositories</a>
        <button type="button" className="demo-button">
          Follow
        </button>
      </span>
    </>
  );
}

// A mention inside running text: the Popup is a <span> (a <div> cannot follow the link inside a
// <p>) and holds phrasing content only, laid out with CSS. Loading starts on pointerenter and
// focus, while the 600 ms delay runs.
function Mention({ login }: { login: string }) {
  return (
    <HoverCard.Root>
      <HoverCard.Trigger
        href={`https://example.com/u/${login}`}
        className="demo-mention"
        onPointerEnter={() => void fetchUser(login)}
        onFocus={() => void fetchUser(login)}
        onClick={(event) => event.preventDefault()}
      >
        @{login}
      </HoverCard.Trigger>
      <HoverCard.Popup render={<span />} className="demo-card" align="start">
        <UserPreview login={login} />
      </HoverCard.Popup>
    </HoverCard.Root>
  );
}

export function HoverCardMentions() {
  return (
    <p>
      Thanks <Mention login="ada" /> for the review, and <Mention login="babbage" /> for the
      original design.
    </p>
  );
}
hover-card.css
/* HoverCard: the Trigger is a link (`data-open` optimistic, `data-pending` while the card
   loads); the Popup is a manual popover right after it. Open state is `:popover-open`. */

.demo-mention {
  color: var(--color-link, #2563eb);
  font-weight: 600;
  text-decoration: none;
}

.demo-mention[data-open] {
  text-decoration: underline;
  text-decoration-thickness: 2px;
}

/* The card is loading: a quiet hint on the link. */
.demo-mention[data-pending] {
  cursor: progress;
  text-decoration: underline dotted;
}

.demo-card {
  /* The popover UA stylesheet sets `inset: 0; margin: auto`: reset both for anchored placement. */
  inset: auto;
  margin: 6px 0;
  /* A <span> card works too: the popover's `position: fixed` makes it a block box. */
  inline-size: 16rem;
  padding: 12px 14px;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  background: var(--color-bg);
  color: var(--color-text);
  box-shadow: 0 12px 40px rgb(0 0 0 / 0.25);
  font-size: 0.9rem;
  line-height: 1.4;
  font-weight: normal;
}

.demo-card-name,
.demo-card-bio,
.demo-card-row {
  display: block;
  margin: 0 0 6px;
}

.demo-card-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
}

.demo-skeleton {
  color: var(--color-text-secondary);
}

.demo-repo-list {
  display: flex;
  gap: 24px;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* Every close the user causes is a fact, so CSS is the animation for a HoverCard: the enter
   everywhere, the exit in Chromium (with `overlay`) and Safari. */
.demo-card {
  opacity: 0;
  transition:
    opacity 120ms,
    display 120ms allow-discrete,
    overlay 120ms allow-discrete;
}

.demo-card:popover-open {
  opacity: 1;
}

@starting-style {
  .demo-card:popover-open {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .demo-card {
    transition: none;
  }
}

Hover a mention or Tab to it: the first time, the link shows a dotted underline while the profile loads, then the card appears complete. Loading starts on pointerenter and focus, while the 600 ms delay runs, through the Trigger's own event props.

Supplementary content only

A touch user never sees the card (a tap follows the link), a screen reader user may never open it, and a keyboard user may Tab past before the delay. Whatever the card offers, its buttons included, must also be reachable where the link leads.

Async and platform behaviour: Transition types · Optimistic and pending · Suspense · Browser-owned state · Before hydration

Anatomy

import { HoverCard } from "@funstack/ui/hover-card";

<HoverCard.Root>                                          {/* no DOM: ids, state, timers */}
  <HoverCard.Trigger href="/u/ada">@ada</HoverCard.Trigger>   {/* a */}
  <HoverCard.Popup>                                       {/* div[popover=manual][role=group] */}
    <UserPreview login="ada" />                           {/* mounted on open; may suspend */}
  </HoverCard.Popup>
</HoverCard.Root>
  • Render the Popup right after the Trigger. Tab from the link then enters the open card in every engine, and Tab from the card's last control continues with what follows the link. Root renders no DOM, so the parts need not be siblings.
  • Inside running text, render a <span> card: render={<span />} with phrasing content only (img, a, button, span), laid out with CSS: a <div> cannot follow a link inside a <p>. The other valid shape puts the Popup after the paragraph; Safari then does not put the card next in the Tab order when other focusable content sits between link and card.
  • The Trigger is a link (or a router link through render), or a button whose click opens nothing of this kind. The card opens on interest only; the click is yours, and a press on the Trigger closes the card. A button that should open the same content on click is a Popover.
  • No Close, Title, Description or Arrow part, no Portal. One Trigger per Root; a card shared by many Triggers is not offered (unmounted content makes many Roots cheap).

How it works

What happensChannel`reason``details.event`
Hover (not touch) or keyboard focus (:focus-visible) held for delayopenChangeAction(true)"activate"the pointerenter or focus event (flagged path: the beforetoggle of the platform's interest show)
Lost interest, Escape or a press while the open is still pendingopenChangeAction(false)"dismiss"the pointerleave, blur, focusout, loseinterest, keydown or pointerdown
Lost interest while shown: the pointer left the link and the card, or focus left both, for closeDelayonOpenChange(false)"dismiss"the event that began the close delay (pointerup after a text selection dragged out); loseinterest on the flagged path
Escape while shownonOpenChange(false)"dismiss"the keydown
A press outside the card while shown, the link includedonOpenChange(false)"dismiss"the pointerdown
disabled became true while shownonOpenChange(false)"dismiss"undefined
Script hidePopover(); with experimental_hint, the browser's light dismiss or another hintonOpenChange(false)"dismiss"the toggle event
  • The latest event wins. Any leave starts the close delay and any enter cancels it, as in Chromium's own interest handling: a card opened by keyboard focus closes when the pointer crosses it and leaves, and a card whose button you clicked closes when the pointer leaves.
  • Every close the user causes is a fact. It is urgent: an unrelated action pending elsewhere in the app cannot keep the card over the page after the user left it. A controlled parent cannot veto it; keeping open={true} re-shows the card, without moving focus.
  • No open until fresh interest. After Escape, after a press on the link and after the library returned focus to it, nothing opens the card until the pointer leaves and comes back, or focus leaves and returns.
  • Nesting. A card never closes anything by opening (manual), and it follows its link in the DOM, so inside a modal Dialog, a Popover or a Menu it is not inert and a press in it is no light dismiss of the outer popup. A Menu, Popover or Tooltip opened from inside the card keeps it open, and so does a nested card.

Props

HoverCard.Root

PropTypeDefaultDescription
openboolean–Controlled open state. Pass onOpenChange too: every close the user causes is a fact (development warns). open with onOpenChange={() => {}} pins a card open, for styling it.
defaultOpenbooleanfalseInitial open state when uncontrolled. Shown after hydration.
openChangeActionChangeAction<boolean, HoverCardOpenChangeDetails>–Requests only. Awaited for true when the user shows interest: the card appears when it resolves and the content has rendered. Called with false only to cancel an open that has not appeared yet. Never called for the close of a shown card. Runs in the Root's transition; may be a Server Function. A rejection reaches the nearest Error Boundary above the Root, which takes the link with it: catch inside the action, or load in the content with an Error Boundary inside the Popup.
onOpenChangeUrgentChangeHandler<boolean, HoverCardOpenChangeDetails>–Facts only: the card was closed (lost interest, Escape, a press outside). Always false, with reason: "dismiss". Called synchronously, outside any transition, not awaited. In controlled mode set state directly here (onOpenChange={setOpen}), never in startTransition. May return a promise; a rejection or a throw goes to reportError. On a controlled Root with no openChangeAction, hover and focus do not open the card (a development warning says so): open it from your own state.
delaynumber600Milliseconds of interest (hover or keyboard focus) before the open is requested. Longer than Tooltip's 250 on purpose: a card loads data and, once open, puts its controls in the keyboard user's path.
closeDelaynumber300Milliseconds from losing interest to the close: the time the pointer has to cross from the link into the card.
disabledbooleanfalseInterest never opens the card, and a shown card is closed. Does not disable the link, which still navigates; a controlled open={true} still shows the card.
childrenReactNode | ((state: HoverCardRootState) => ReactNode)–The parts. The function form receives the optimistic state and must not suspend.
State
HoverCardRootState is { open, pending, disabled }; open is optimistic. HoverCardOpenChangeDetails is { reason } plus the virtual event; reason is "activate" for an open, "dismiss" for every close, "platform" for a card found open at hydration.
Owned
none: the Root renders no element (no ref, className or style).

HoverCard.Trigger

PropTypeDefaultDescription
experimental_interestForbooleanfalseChromium 142+. Writes interestfor (after hydration, through the ref) and renders interest-delay-start / -end from the Root's delays, so the browser decides when interest starts and ends, long-press on touch included. The library still owns the open, Escape and a press outside. Firefox and Safari ignore the attribute and run the JS path. See Experimental features.
classNamestring | ((state: HoverCardTriggerState) => string | undefined)–A class name, or a function of the part's state.
styleCSSProperties | ((state: HoverCardTriggerState) => CSSProperties | undefined)–Inline style, or a function of the part's state.
childrenReactNode | ((state: HoverCardTriggerState) => ReactNode)–Rendered from optimistic state; must not suspend.
renderReactElement | ((props, state: HoverCardTriggerState) => ReactNode)–Replace the default <a> (element form) or take over rendering (function form).
State
HoverCardTriggerState is { open, pending, disabled }; open is optimistic, pending is true while an open (or its cancel) is in flight: the card is loading.
Owned
data-open, data-pending, data-disabled, and interestfor with experimental_interestFor (removed while disabled). No ARIA attribute: not aria-describedby, aria-expanded, aria-haspopup or aria-details.

href and every other anchor prop pass through, and so do your onPointerEnter, onFocus and onClick: the library listens with addEventListener. The element must be focusable; a development warning fires when it is not (an <a> without href).

HoverCard.Popup

PropTypeDefaultDescription
side"top" | "bottom" | "left" | "right" | "inline-start" | "inline-end" | null"bottom"Placement relative to the Trigger through inline position-area, with position-try-fallbacks flipping it when it does not fit. null emits no inline placement and no data-side / data-align: your stylesheet owns placement.
align"start" | "center" | "end""center"Alignment along the side. Ignored when side is null.
keepMountedbooleanfalsefalse: the children are not rendered while closed; mounting them is part of the opening transition, so content that suspends holds the open. true: rendered in <Activity mode="hidden"> while closed (pre-rendered at low priority). Suits a single prominent card, not a list of them.
experimental_hintbooleanfalseRenders popover="hint" instead of "manual" (Chrome 151+, Firefox 153+; Safari 27.2 treats it as manual): opening the card closes an open Tooltip, and the browser's light dismiss applies next to the library's.
transitionViewTransitionClass–The class of the <ViewTransition> around the popup element; without it no boundary is rendered. A string animates this card's own open (and the cancel of an open that has not appeared) and its own mount and unmount (only as the top of what is inserted or removed), in all engines; nothing else (not another card, not an unrelated transition, not content that changes inside). A controlled open you change in your own transition needs a map keyed on fsui-hover-card-open / fsui-hover-card-close plus addTransitionType (recipe). A type map is React's: it names every card that has it and that a commit with its types reaches, and each plays the class; end it with default: "none" (Type maps). Closes the user causes are facts and animate with CSS only. Keep it static: changing it remounts the popup. Any value, "none" included, makes a mount of the Popup while it is open, or a second reveal of a mounted Popup by <Suspense> or <Activity>, inside a transition run the page cross-fade; a plain open does not, and neither does the mount of a closed Popup: it renders its element one commit after its mount, before paint, so its ref is still empty in the mount effects of the component that renders it (two-step mount). While a view transition runs, the popup's CSS transitions are cut for the library's own show or hide (a @keyframes animation is not, and a dismissal keeps its CSS exit).
classNamestring | ((state: HoverCardPopupState) => string | undefined)–A class name, or a function of the part's state.
styleCSSProperties | ((state: HoverCardPopupState) => CSSProperties | undefined)–Inline style, or a function of the part's state.
childrenReactNode | ((state: HoverCardPopupState) => ReactNode)–Content, or a function of the part's state. Rendered from committed state; may suspend.
renderReactElement | ((props, state: HoverCardPopupState) => ReactNode)–Replace the default <div> (element form) or take over rendering (function form). A <span> for a card inside running text (phrasing content only).
State
HoverCardPopupState is { open, side, align }; open is committed (:popover-open is the DOM truth); side / align are where the browser placed the card while it is shown, your props otherwise.
Owned
id, popover ("manual", or "hint" with the flag), data-side / data-align (unless side is null).

role="group" is a default you can override: a card with real actions may pass role="dialog" with an aria-label. onToggle and onBeforeToggle are not accepted; use a ref. Every show is a no-focus show: the card is inert for the showPopover() call, so an autofocus inside it cannot take focus on hover.

Data attributes

AttributeOnMeaning
:popover-openPopupThe card is shown (DOM truth).
data-side, data-alignPopupWhile shown: where the browser placed the card (after any flip). Otherwise the requested placement. Absent with side={null}.
data-openTriggerOptimistic open state: from the dispatch of the open.
data-pendingTriggerAn open is in flight: the card is loading.
data-disabledTriggerThe Root's disabled.

Keyboard and ARIA

KeyWhereBehaviour
Tabbefore the TriggerFocus reaches the link and the card opens after delay (keyboard focus is :focus-visible); focus stays on the link.
TabTrigger, card openFocus moves into the card, to its first focusable element; with none, to what follows.
Tabthe card's last elementFocus moves on; the card closes after closeDelay.
Shift+Tabthe card's first elementBack to the link; the card stays open.
TabTrigger, before delay has passedThe open is cancelled; focus moves on.
EscapeanywhereCloses the card (or cancels the coming one). With focus inside the card, focus returns to the link and the card does not re-open. Inside a Dialog or a toast only the card closes; a popover or tooltip open inside the card closes first. With a tooltip showing elsewhere too, the one that opened first closes. A preventDefault() on the Escape keeps the card open; stopPropagation() does not, and inside a modal Dialog it makes the dialog close on the same Escape (the browser closes it before the library can claim the key).
EnterTriggerThe link's own activation; the library does nothing.
  • Tab enters the card, the platform's model for interest targets: a keyboard user who pauses on a link longer than delay has the card's controls in the way of the next link. That is why the delay is long, why Escape is cheap and why a card with many controls is the wrong component: content the user works in belongs in a Popover that a click opens.
  • Opening never moves focus. Lost interest and a press outside never focus the link either: focus inside a card that closes goes to <body>, or where the press landed.
  • ARIA. The Trigger gets nothing: the card is not the link's description (a rich card read as one string is noise), and a link announced as "collapsed" on every mention would be worse. The card follows the link in the reading order. The Popup has role="group", HTML-AAM's minimum role for a popover, which WebKit does not apply by itself. Nothing is announced when the card appears.
  • WCAG 1.4.13. Dismissible (Escape, without moving pointer or focus), hoverable (the pointer may move into the card; closeDelay covers the gap), persistent (until interest is lost).

Transition types

Concept: Transitions & ViewTransition

fsui-hover-card plus fsui-hover-card-open for an open, and fsui-hover-card-close for the cancel of an open that has not appeared. Every close of a shown card is a fact and starts no transition. These types are public API: key a transition map on them, and add them with addTransitionType for a controlled change (Transitions). A string transition is keyed on an internal per-instance type instead, which this component's own dispatch adds.

CSS is the animation to use for a HoverCard, because every close the user causes is a fact and only CSS animates those (the exit animates in Chromium and Safari, not in Firefox). transition earns its place for a skeleton swapped for the content and for a parent that drives open itself.

.card {
  margin: 6px; inset: auto;
  opacity: 0;
  transition: opacity 120ms, display 120ms allow-discrete, overlay 120ms allow-discrete;
}
.card:popover-open { opacity: 1; }
@starting-style { .card:popover-open { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .card { transition: none; } }

Optimistic and pending

Concept: Pending & optimistic state

During delay nothing is rendered and nothing is pending. From the dispatch of the open the Trigger has data-open and data-pending; the card is hidden and its children unmounted until the action resolves and the content has rendered. Leaving meanwhile cancels the open: openChangeAction(false) supersedes it and nothing appears.

  • funstack-ui
  • funstack-router
  • funstack-static

Last: (none yet)

Show code
HoverCardRepos.tsx
"use client";
import { Suspense, startTransition, use, useState } from "react";
import { HoverCard } from "@funstack/ui/hover-card";
import type { HoverCardOpenChangeDetails } from "@funstack/ui/hover-card";
import { DemoErrorBoundary } from "./DemoErrorBoundary.js";
import { sleep } from "./fake-api.js";

const repos = ["funstack-ui", "funstack-router", "funstack-static"];

// The repository's summary, loaded in the content: the Popup has a Suspense boundary, so the
// card opens after the delay with a skeleton and the summary swaps in when it arrives.
const cache = new Map<string, Promise<string>>();
function loadSummary(repo: string): Promise<string> {
  let promise = cache.get(repo);
  if (promise === undefined) {
    promise = sleep(1200).then(() => `${repo}: ${repo.length * 7} stars, updated today.`);
    cache.set(repo, promise);
  }
  return promise;
}

function Summary({ repo }: { repo: string }) {
  return <p className="demo-card-bio">{use(loadSummary(repo))}</p>;
}

// Requests and facts side by side. `openChangeAction` hears the open (a 400 ms pretend analytics
// call: the link is pending meanwhile) and the cancel of an open that never appeared;
// `onOpenChange` hears every close of a shown card (lost interest, Escape, a press outside),
// synchronously. The readout is plain text, not a live region.
export function HoverCardRepos() {
  const [log, setLog] = useState("(none yet)");
  const request = async (open: boolean, { reason }: HoverCardOpenChangeDetails) => {
    const call = `openChangeAction(${open}, "${reason}")`;
    setLog(`${call}: running…`);
    await sleep(400);
    // After an await: wrap the update in startTransition (React limitation).
    startTransition(() => setLog(`${call}: settled`));
  };
  const fact = (open: boolean, { reason, event }: HoverCardOpenChangeDetails) => {
    setLog(`onOpenChange(${open}, "${reason}") after ${event?.type ?? "no event"}`);
  };
  return (
    <div className="demo-stack">
      <ul className="demo-repo-list">
        {repos.map((repo) => (
          <li key={repo}>
            <HoverCard.Root openChangeAction={request} onOpenChange={fact}>
              <HoverCard.Trigger
                href={`https://github.com/uhyo/${repo}`}
                className="demo-mention"
                onClick={(event) => event.preventDefault()}
              >
                {repo}
              </HoverCard.Trigger>
              <HoverCard.Popup className="demo-card">
                <strong className="demo-card-name">uhyo/{repo}</strong>
                <DemoErrorBoundary>
                  <Suspense fallback={<p className="demo-card-bio demo-skeleton">Loading…</p>}>
                    <Summary repo={repo} />
                  </Suspense>
                </DemoErrorBoundary>
                <span className="demo-card-row">
                  <button type="button" className="demo-button">
                    Star
                  </button>
                </span>
              </HoverCard.Popup>
            </HoverCard.Root>
          </li>
        ))}
      </ul>
      <p className="demo-readout">
        Last: <code>{log}</code>
      </p>
    </div>
  );
}
hover-card.css
/* HoverCard: the Trigger is a link (`data-open` optimistic, `data-pending` while the card
   loads); the Popup is a manual popover right after it. Open state is `:popover-open`. */

.demo-mention {
  color: var(--color-link, #2563eb);
  font-weight: 600;
  text-decoration: none;
}

.demo-mention[data-open] {
  text-decoration: underline;
  text-decoration-thickness: 2px;
}

/* The card is loading: a quiet hint on the link. */
.demo-mention[data-pending] {
  cursor: progress;
  text-decoration: underline dotted;
}

.demo-card {
  /* The popover UA stylesheet sets `inset: 0; margin: auto`: reset both for anchored placement. */
  inset: auto;
  margin: 6px 0;
  /* A <span> card works too: the popover's `position: fixed` makes it a block box. */
  inline-size: 16rem;
  padding: 12px 14px;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  background: var(--color-bg);
  color: var(--color-text);
  box-shadow: 0 12px 40px rgb(0 0 0 / 0.25);
  font-size: 0.9rem;
  line-height: 1.4;
  font-weight: normal;
}

.demo-card-name,
.demo-card-bio,
.demo-card-row {
  display: block;
  margin: 0 0 6px;
}

.demo-card-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
}

.demo-skeleton {
  color: var(--color-text-secondary);
}

.demo-repo-list {
  display: flex;
  gap: 24px;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* Every close the user causes is a fact, so CSS is the animation for a HoverCard: the enter
   everywhere, the exit in Chromium (with `overlay`) and Safari. */
.demo-card {
  opacity: 0;
  transition:
    opacity 120ms,
    display 120ms allow-discrete,
    overlay 120ms allow-discrete;
}

.demo-card:popover-open {
  opacity: 1;
}

@starting-style {
  .demo-card:popover-open {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .demo-card {
    transition: none;
  }
}
  1. Hover a repository: after 600 ms openChangeAction(true, "activate") runs (400 ms here) and the link is pending.
  2. It settles: the card appears with a skeleton (the Popup has a Suspense boundary of its own), and the summary swaps in when it has loaded.
  3. Leave before it settles: openChangeAction(false, "dismiss") cancels the open, and no card flashes under a pointer that has gone.
  4. Leave an open card, press Escape or click elsewhere: onOpenChange is called at once, with the event that caused it. The action is not called.

openChangeAction may see true, false, true as the user leaves and comes back; only the last dispatch commits. An action that loads data should be idempotent or cached. There is no whilePending: no part of a HoverCard runs an action of its own.

Suspense

Concept: Suspense

The children render from committed state, so they mount in the opening transition. Content that suspends holds the open (wait, then open: the default); a <Suspense> inside the Popup opens at once with a skeleton instead.

<HoverCard.Popup className="card">
  <ErrorBoundary fallback={<span>Could not load the profile.</span>}>
    <UserPreview login="ada" />   {/* use(fetchUser("ada")) */}
  </ErrorBoundary>
</HoverCard.Popup>
  • Put the Error Boundary inside the Popup. A rejection of openChangeAction reaches the boundary above the Root, which takes the link with it; a failure inside the content only replaces the card's body.
  • Start loading during the delay with the Trigger's own event props (onPointerEnter, onFocus). The library does not do this by itself: a pointer crossing a list of links would fetch for each of them.

Browser-owned state

Concept: Browser-owned state

The card is a manual popover the library shows and hides. Opening is library-owned (a request); every close the user causes is browser-shaped: the library hides the card at once and reports the fact from the toggle event. With experimental_interestFor in Chromium the browser decides when interest starts and ends; the rest is the same code.

FlagsChromiumFirefoxSafari
nonemanual + JS interest; Escape and a press outside by the librarysamesame
experimental_hinthint: opening closes an open Tooltip; native light dismiss next to the library'sas Chromiumtreated as manual
experimental_interestForthe platform's interest signal, long-press on touchignored: JS pathignored: JS path

Before hydration

Concept: Server Components

The card opens only after hydration: interest is tracked by the library, and interestfor is written after hydration so that a hover before it cannot open an empty card. The server HTML has the link and the closed, empty card.

Recipes

From a Server Component, with a Server Function

// A Server Component. `recordPreview` is a Server Function; it hears opens only.
<HoverCard.Root openChangeAction={recordPreview.bind(null, repo.id)}>
  <HoverCard.Trigger href={repo.url}>{repo.name}</HoverCard.Trigger>
  <HoverCard.Popup className="card">
    <RepoSummary repo={repo} />
  </HoverCard.Popup>
</HoverCard.Root>

Controlled

const [open, setOpen] = useState(false);

<HoverCard.Root open={open} openChangeAction={setOpen} onOpenChange={setOpen}>
  …
</HoverCard.Root>

setOpen in the action is a transition update, in the handler an urgent one. Never wrap the handler's update in startTransition.

A bridge over the gap

.card { margin: 6px; }
/* Extend the card's hit area over the gap, on the side that faces the link. */
.card[data-side="bottom"]::before { content: ""; position: absolute; inset: -6px 0 auto; height: 6px; }
.card[data-side="top"]::before { content: ""; position: absolute; inset: auto 0 -6px; height: 6px; }

Both flags

<HoverCard.Root delay={400}>
  <HoverCard.Trigger href="/u/ada" experimental_interestFor>@ada</HoverCard.Trigger>
  <HoverCard.Popup experimental_hint className="card">…</HoverCard.Popup>
</HoverCard.Root>

Not included

  • Click to pin ("hover to preview, click to keep open"): one element that opens the same rich content on interest and on activation is against HTML's author guidance for interest invokers. A card that must stay is a Popover.
  • One card shared by many Triggers, skip-delay between neighbouring cards.
  • A safe-polygon pointer corridor (the bridge recipe above covers the gap).
  • A long-press for touch on the JS path; anchoring to the hovered line of a wrapped link.
  • openOnFocus={false}: keyboard focus opens the card on both paths.