[render preview] [Feature] Remove Popper.js — port hover_card & context_menu to Floating UI (#158)

Merged
DJ
5mo ago
+448-360

Closes #158.

What & why

tippy.js (which bundles @popperjs/core) was the last dependency pulling Popper into RubyUI, and the source of the importmap install issues described in #158. The other nine positioned components already use @floating-ui/dom; this ports the final two — HoverCard and ContextMenu — and removes Popper/tippy from the gem and the docs site entirely.

Changes

Gem (gem/)

  • Rewrote hover_card_controller.js and context_menu_controller.js on @floating-ui/dom (computePosition + autoUpdate, flip/shift/offset), dropping tippy. Keyboard nav, matchWidth, hover open/close delays, right-click trigger, outside-click + Escape close are all preserved.
  • hover_card_content.rb / context_menu_content.rb now render a real hidden, absolutely-positioned div instead of a cloned <template> (Floating UI positions a live element rather than cloning markup).
  • dependencies.yml: hover_card & context_menu now map to @floating-ui/dom.
  • javascript_utils.rb: removed pin_tippy_js (the tippy + @popperjs/core CDN importmap pins).
  • package.json: removed tippy.js.

Docs (docs/)

  • Synced both Stimulus controllers.
  • Removed tippy.js from package.json + pnpm-lock.yaml.
  • Removed the tippy/popper importmap install snippet in component_setup/manual_steps.rb.

Tests

  • New assertions that content renders a hidden positioned div, not a <template>. Full suite green (239 runs, 0 failures), StandardRB clean.

Impact on apps using these components

Components are copy-and-paste, so existing installs keep working until regenerated. Apps that update HoverCard/ContextMenu must repin their importmap (drop tippy.js + @popperjs/core, add @floating-ui/dom) and recopy the controller. The Ruby/markup API is unchanged. Note: the popup now opens below the trigger by default (with flip()), where tippy defaulted to above — same content, standard RubyUI placement.

Manual test instructions

Run the docs site (or any app with these components) and verify:

Hover Card — /docs/hover_card

  1. Hover the @joeldrapper trigger → card appears (after a short delay) with avatar, bio, joined date.
  2. Move the mouse off → card hides after a short delay.
  3. Move from trigger onto the card → stays open.
  4. Scroll/resize the window while open → card stays anchored (autoUpdate).

Context Menu — /docs/context_menu

  1. Right-click "Right click here" → the custom menu opens; the native browser menu does NOT appear.
  2. "Forward" is disabled; "Show Bookmarks Bar" shows a checkmark.
  3. Click any item → menu closes.
  4. Click outside the menu → it closes. Press Escape → it closes.

Regression check: confirm no console errors, and that the other Floating UI components (Popover, Tooltip, Dropdown Menu, Select, Combobox) still behave normally.

Before/after screenshots (tippy → Floating UI) were captured during development for both components — content is identical; HoverCard now opens below the trigger and ContextMenu flips to fit the viewport.


Summary by cubic

Replaced tippy.js/@popperjs/core with @floating-ui/dom for HoverCard and ContextMenu to remove Popper and resolve importmap install issues in #158. Content now renders as a hidden, absolutely positioned div and is positioned with computePosition + autoUpdate.

  • Bug Fixes

    • HoverCard: Escape now closes; focusing into the card (focusin/focusout) keeps it open.
    • ContextMenu: Close on outside right‑click (contextmenu) as well as click.
    • Both: Set initial data-state="closed" and keep it in sync with the hidden class so enter/exit animations play correctly.
    • Rebuilt mcp/data/registry.json to reflect the Floating UI migration and satisfy the CI registry check.
  • Migration

    • No Ruby/markup API changes.
    • If updating: remove tippy.js and @popperjs/core pins, add @floating-ui/dom, and recopy the controllers. Default placement opens below the trigger (with flip), where tippy defaulted to above.