Skip to content

Hover card: a hoverable popover with enter/leave delays #376

Closed

Description

@samitbasu

shadcn's HoverCard (Radix): a popover that opens on hover after a delay, stays open while the pointer moves INTO it (unlike tooltips; Radix's hoverable content), and closes after a leave delay. Content can be interactive. Docs link previews and richer hints. Reuse the tooltip's timing and the overlay machinery; no parallel timer.

Placement: the widgets crate (#366); extras until the split. Design note first; looks to the user as a render round beside shadcn's. Queued in #351.

Activity

  1. added
    v0.1
    on Nov 18, 2026
  2. samitbasu commented on Nov 18, 2026

    @samitbasu
    OwnerAuthor

    Design note: Hover card (#376)

    Read against origin/main at 62fc13a. This is a note, with no code. Placement follows #351: the composite goes in crates/eggshell-ui-extras (feature hover-card), and later in the widgets crate (#366). It is built only on core's public API. The one core gap is closed with one small public primitive (§3).

    Sources: src/tooltip.rs, src/overlay.rs, src/overlay_chain.rs, src/dismiss.rs, docs/overlays.md (PR 7, §8), shadcn new-york-v4/ui/hover-card.tsx, and Radix packages/react/hover-card/src/hover-card.tsx.

    What Radix and shadcn actually do

    • Timing. openDelay = 700, closeDelay = 300. These are two plain timers: enter starts the open timer and clears the close timer, and leave does the reverse. Radix has no skip-delay for cards, unlike its tooltip.
    • Hoverable content. The content has the same onPointerEnter/onPointerLeave handlers as the trigger. Crossing the gap is covered by closeDelay alone. There is no safe triangle. That polygon is Radix Tooltip's disableHoverableContent machinery, which HoverCard does not use.
    • Focus. The trigger's onFocus opens the card after the same openDelay, and onBlur closes it after closeDelay. A focus moving outside the content is preventDefaulted, so it does not dismiss.
    • Dismissal. DismissableLayer dismisses on Esc and on a pointer-down outside the content. It does not block outside pointer events.
    • Touch. excludeTouch drops pointer enter and leave from touch, and onTouchStart calls preventDefault so a tap does not focus the trigger. Touch never opens a card. A tap just activates the trigger (a link).
    • Selection. A pointer-down in the content, or a text selection made in it, holds the card open until release.
    • Keyboard reach. Every tabbable element in the content gets tabindex=-1. The docs say it is "intended for sighted users only, the content will be inaccessible to keyboard users". The content has no role and no ARIA link to the trigger.
    • shadcn's look. w-64 rounded-md border bg-popover p-4 text-popover-foreground shadow-md, align="center", sideOffset={4}, Radix's default side="bottom", and no arrow. The animation is fade-in-0 zoom-in-95 slide-in-from-*-2, which is our Entrance::Pop (the same as shadcn's popover).

    1. API

    use eggshell_ui_extras::hover_card::HoverCardExt;
    
    b.hover_card("author")
        .placement(Placement::below().align(Align::Center))   // optional; style default
        .open_delay(Duration::from_millis(200))               // optional; style token
        .trigger(tw().inline_flex(), |t| {
            t.button("handle", "@nextjs").link();             // any content; the wrapper is the trigger
        })
        .content(|c| {                                         // c: &mut Builder<'_, '_, App>
            c.text(tw().font_semibold(), "@nextjs");
            c.text(tw(), app.bio.as_str());                    // may capture &app
            c.button("follow", "Follow").on_click(|app: &mut App| app.follow());
        });
    • The trigger is a wrapper node (div_id(key, classes, ..)), and it is a whole-control trigger (A control's tooltip is one trigger on the whole control #312/Segmented: the track padding beside a cell shows the control's tooltip, not the cell's #338): the pointer anywhere over it, or keyboard focus on anything inside it, counts. It is the same rule and the same code as register_whole.
    • The content is built over the app type A. Tooltips build theirs over () (tooltip_with, A built tooltip (tooltip_with) inside a mount shows nothing #297), and the difference is structural.
      • Tooltips: the content is stored: Arc<dyn Fn(&mut Builder<()>) + Send + Sync> in Kept::tooltips. tooltip::declare builds it later, after the app's view, possibly in another builder (a mount). That is why it must ask nothing of A (the BuildBuilt fn-pointer trick). It also takes no input, because a tooltip overlay never senses (Band::Tooltip, pointer_events_none).
      • Hover cards: the card's overlay is declared inline at the call site, like any b.overlay(..), every frame with shown. Its content is a plain FnOnce(&mut Builder<'_, '_, A>), called immediately while the card is open or leaving. So it needs no Arc, no Send + Sync and no 'static. It may borrow &app and register on_clicks, and it nests under whatever overlay the trigger is in, so dismissal treats it as nested.
    • Delays are Duration tokens on the extras style: HoverCardStyle { open_delay, close_delay, .. }. The chain overrides them per card (open_delay / close_delay), because Radix exposes them per instance and shadcn users set them. The neutral default and the shadcn preset are both Radix's 700 ms / 300 ms. egui has no analogue to derive from.
    • Placement is core's Placement, unchanged. The default is Placement::below().align(Align::Center).gap(style.offset) with Flip::ToOpposite. I propose no new placement types.
    • Open state is the library's (hover intent, like a tooltip), not the app's. A controlled mode (Radix open/onOpenChange) is not in v1 (Q8).

    2. Behaviour

    • Opening. The pointer resting on the trigger opens the card after open_delay. There is no skip-delay grace between cards, as in Radix: a card is large, and sweeping across a list of handles should show nothing.
    • Trigger to content. The card's box, and any overlay nested in it (say a select opened inside the card), counts as hovering the trigger. Crossing the gap from trigger to box is covered by close_delay. With a 4 pt offset the gap is crossed in one or two frames, well inside 300 ms.
      • No safe triangle in v1 (Q5). Radix's card has none either. docs/overlays.md already lists a submenu safe triangle as post-0.1. If a consumer needs one later, it should be one geometry helper shared by submenus and cards.
    • Leaving. When neither the trigger nor the box is hovered (and focus is not within), the card closes close_delay later. Re-entering either one before then cancels the close.
    • Holding open. A press that started inside the box, such as a drag-select of text or a slider drag, holds the card open until release (Radix's isPointerDownOnContent).
    • Keyboard.
      • Focus on or within the trigger opens the card, after open_delay as Radix does (Q2). It does not open at once as our tooltips do: Tab through a list of links should stay quiet.
      • Focus does not move into the card (Focus::None).
      • Tab away from the trigger closes it: this is the overlay's existing focus-leaving rule. The trigger counts as "inside" for FocusAt, so focus resting on the trigger keeps the card.
      • Esc closes it. It is the topmost overlay that takes Esc (dismiss.rs rule 3). Like a tooltip's interruption, Esc latches the card closed until the trigger is left, or focus leaves it.
    • Press outside. A press outside the box, the trigger included, closes the card and latches it (Radix: pointer-down outside the content). The press passes through (Outside::PassThrough), so the trigger's own click still happens. The window losing focus also closes it.
    • The trigger's tooltip. The card replaces it.
      • The card trigger takes the tooltip slot of its subtree: in tooltip resolution it is a quiet trigger (no content), so it wins by depth over an enclosing control's tooltip. Tooltips on nodes inside it are dropped by ancestry, not by geometry.
      • Their text still describes their nodes to assistive technology.
      • Tooltips inside the card's content work normally, and the card stays open while they show.
    • Touch. Touch never opens a card, as in Radix: pointer causes from a touch are ignored, and a tap activates the trigger as usual. Tooltips are unchanged (Q7). This needs a per-viewport "the last pointer input was a touch" fact in core, the sibling of overlay_input::keyboard_was_last. It is internal and adds no public surface.
    • Trigger gone or scrolled away. This is the existing machinery. A trigger that is no longer drawn forgets its intent, as Tooltips::forget does. An anchor scrolled out of view hides the overlay without changing its state.
    • Nesting. A card trigger inside a card's content is not supported in v1 (Q6). It is reported through report, with no panic, and opens nothing.

    3. Reuse, and the core primitive

    No second timer. The machine in tooltip.rs (Tooltips::tick: pure, unit-tested, Duration throughout, returning the wait so the draw can request_repaint_after) is generalised. It does not get a sibling.

    • The machine. Tooltips becomes a hover-intent machine, Intent, parametrised by a Timing { open, close, grace, focus }:

      • close is new. It is zero for tooltips, so tooltips close at once as today.
      • focus says whether focus waits for open. Tooltips: at once. Cards: the delay.
      • grace is the existing skip-delay. It is zero for cards.
      • The latch, Interruption, focus restore, the deepest-wins wanted, and the "not the trigger around the last" grace rule are kept as they are.
    • Two instances. Kept holds two instances of the one type, tooltips and hover_cards. One shared instance cannot work: the one-open-at-a-time rule would close the card when a tooltip inside the card opens.

    • Hoverable box. Hoverability is not a new mechanism. The open card's box (and the overlays nested in it) registers as a pointer trigger with the card's id, so to the machine, "over the box" is "over the trigger".

    • The overlay. It is an ordinary anchored overlay:

      • Band::Popup, because it senses: Band::Tooltip's doc line "Tooltips and hover cards. Never sensing." gets corrected.
      • Anchor::Node(trigger), Focus::None, DismissOn::Default, Outside::PassThrough.
      • shown comes from the intent, so the card's motion and exit come from the existing presence machinery, with the popover motion kind (shadcn: Pop, 150 ms).
      • Dismissals from dismiss.rs (Esc, press outside, focus leaving, blur) are fed back to the card's machine as an Interruption. The rules stay in their one place.
    • The public primitive (core, one PR):

      /// On an Unplaced overlay chain: the overlay is anchored to `trigger`, and
      /// opens and closes by hover intent (whole-control trigger, the box counts
      /// as the trigger, dismissal latches it). Supplies `shown`.
      pub fn hover_anchored(self, trigger: Id, intent: HoverIntent)
          -> OverlayChain<'b, 'f, A, Floating, Animated>;
      
      #[non_exhaustive]
      pub struct HoverIntent { pub open: Duration, pub close: Duration }
      • Name: a placeholder (Q10).
      • Anchor type: taking an Id rather than an Anchor makes a non-node anchor unrepresentable.
      • Behaviour it brings with it: the trigger's tooltip yields, content focusables are skipped by Tab, touch exclusion, and the press-held rule. These are core-internal consequences of the primitive, not extra public surface.
      • What extras then needs: nothing else. It needs div_id for the trigger, id_of, the overlay chain, and Look::classes for the box.

    4. Accessibility

    • What Radix does. It announces nothing, and makes the content unreachable by keyboard.
    • What we can do better, cheaply:
      • The trigger is announced as whatever it is (a link or a button), with the card's text as its accesskit description. This reuses the built-tooltip path exactly: while accesskit is on, Builder::text_of builds the content where nothing shows it and takes its text. Content is over A here, but text_of is already generic over A. Nothing built there is drawn, so no handler can fire. It costs one extra build of the content per frame, only while accesskit is on.
      • The card box gets no role and no name. Focus never enters it and it is not modal. While it is open its widgets are in the accesskit tree, so a screen reader's virtual cursor can reach them.
    • Is "screen readers ignore it" acceptable? For v1, yes, on the rule shadcn and Radix rely on: a hover card is a supplement. Whatever it holds that matters (the profile, the Follow button) must also be reachable some other way. The rustdoc says so. With the description, a screen-reader user hears the summary, which is better than Radix. Making the content keyboard-reachable is Q3.

    5. Looks, PR split and questions

    The render round (looks are the user's). Candidates are rendered at 1x and 2x, light and dark, and set beside shadcn's own demo (@nextjs, avatar, bio, "Joined December 2021"), beside the tooltip and a popover in the same frame:

    1. Box: shadcn's (bg-popover, border, rounded-md, shadow-md, p-4) against the popover look we already have, if they differ.
    2. Width: fixed 256 pt (w-64, shadcn) or content-sized up to a max.
    3. Side and offset: below with 4 pt (shadcn), or below with 8 pt, or above (like our tooltips).
    4. Align: center (shadcn) or start.
    5. Arrow: none (shadcn) or the tooltip's arrow (Radix has a HoverCard.Arrow).
    6. Motion: Pop 150 ms (shadcn, our popover's), Zoom, or instant. This is shown as a motion strip.
    7. Delays: 700/300 (Radix), or a quicker open such as 300/300 to match our tooltip decision of 2026-11-13. These are tried by hand, not rendered.

    PR split.

    • A. core, behaviour-preserving. Generalise Tooltips into the Intent machine (close, focus, the box-as-trigger). Every existing test passes unchanged. New unit tests cover the close delay, re-entering within it, and press-held.
    • B. core, the public primitive.
      • Contents: hover_anchored + HoverIntent; the hover_cards instance; dismissal fed back as interruption; the tooltip-yields rule; the touch fact; Tab-skip; the Band doc fix; doctests.
      • Tests through the full path: trigger to gap to box with no close, leave then close at close_delay, focus opens and Tab away closes, Esc latches, an enclosing tooltip does not show, a tooltip inside the box shows, touch opens nothing. Each test asserts its geometric preconditions.
      • Listed behaviour change: none for tooltips (if Q7 is "cards only").
    • C. extras hover-card.
      • Contents: HoverCardExt, the chain, HoverCardStyle (neutral and of(ctx)), shadcn values behind the shadcn crate's extras feature, an example, and the render-round snapshot test.
      • Process: it lands after the user picks from the render round, and the user tries it by hand before approval. The docs/overlays.md "As built" prose is the user's to write. Agents scaffold it.

    Questions, with recommendations.

    • Q1. API shape. b.hover_card(key).trigger(classes, ..).content(..) (wrapper, whole-control), or a .hover_card(|c| ..) extension on any NodeHandle, like tooltip_with? Rec: the builder form. It needs no extra primitive, since the NodeHandle form would need core to lend out its builder.
    • Q2. Focus opening. Wait for open_delay (Radix) or open at once (our tooltips)? Rec: wait.
    • Q3. Keyboard reach into the content. Pointer only, with content skipped by Tab (Radix), or Tab from the trigger enters the card? Rec: Radix parity in v1. The content is a supplement, and the description carries its text.
    • Q4. Accessibility. The card's text as the trigger's description, or nothing (Radix)? Rec: the description, reusing text_of.
    • Q5. Safe triangle. Rec: none. close_delay covers the 4 pt gap. Revisit with the submenu triangle.
    • Q6. Nested cards. Rec: unsupported in v1, reported, and the inner trigger opens nothing.
    • Q7. Touch. Rec: cards never open on touch (Radix); tooltips unchanged. Long-press tooltips are a separate question.
    • Q8. Controlled mode (open / on_open_change). Rec: not in v1. Add it when a consumer needs it.
    • Q9. Delay overrides. Rec: style tokens plus per-card chain overrides. The tokens alone are not enough, because shadcn users routinely set openDelay.
    • Q10. The primitive's name. hover_anchored, opened_by_hover or hover_intent? Rec: hover_anchored, since it replaces both anchor and shown. The pick is yours.
    • Q11. Skip-delay between cards. Rec: none (Radix). Cards always wait.
  3. samitbasu commented on Nov 18, 2026

    @samitbasu
    OwnerAuthor

    Decisions (user, 2026-11-18):

    • Focus on the trigger opens the card after the delay, without moving focus in.
    • No keyboard entry into the content in v1; the card's text is the trigger's description.
    • The rest of the note is accepted:
      • b.hover_card(key).trigger(..).content(..) in extras, with interactive content;
      • 700/300 ms tokens with per-card overrides;
      • no safe triangle;
      • the card replaces the trigger's tooltip;
      • no nested cards in v1 (reported);
      • never opens on touch;
      • no controlled state;
      • the core primitive (name to confirm: hover_anchored);
      • no skip-delay.
    • PRs: A, the hover-intent generalisation; B, the primitive; C, the widget (after the render round and a trial).
  4. added 2 commits that reference this issue on Nov 19, 2026
  5. added a commit that references this issue on Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    v0.1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions