Skip to main content

Mantle Native Floats Migration Guide

@ngrok/mantle's Popover, Tooltip, and HoverCard no longer use Radix. Each content part is a native popover in the browser's top layer, and CSS anchor positioning places it next to its trigger. Where the browser has no anchor positioning, a small script places it. The Radix positioning props, Popover.Root's modal prop, HoverCard.Portal, and the --radix-popover-* CSS variables are gone. Popover.Content and HoverCard.Content no longer take asChild, and Tooltip.Content no longer takes id. The part names and the other props stay the same.

TL;DR: Delete collisionPadding, collisionBoundary, sticky, avoidCollisions, alignOffset, hideWhenDetached, forceMount, updatePositionStrategy, and arrowPadding from Popover.Content, Tooltip.Content, and HoverCard.Content. Delete modal from Popover.Root. Unwrap HoverCard.Portal. Replace --radix-popover-trigger-width with --anchor-width and --radix-popover-content-available-height with --available-height. TooltipProvider is now optional.

Codemod

From a mantle checkout:

pnpm -w run migrate 0020 <path>

In a project that installs @ngrok/mantle:

npx --yes --package=@ast-grep/cli@0.51.3 ast-grep scan --rule node_modules/@ngrok/mantle/dist/migrations/0020-native-floats.yml --update-all <path>

The rules apply steps 2 to 5. They delete the Radix positioning props from the three content parts, delete modal from Popover.Root, replace HoverCard.Portal with a fragment, and rename the two CSS variables in each string of a file that imports @ngrok/mantle/popover. The rules read a part through its import from @ngrok/mantle/<subpath>, under its own name or an alias. A function that binds the part's name to a parameter or a local shadows the import, so the rules leave that function alone. A variable in a file that does not import Popover, such as a shared class constant or a stylesheet, stays manual. Steps 6 and 7 stay manual, because they are choices for each call site and test queries, not syntax. The codemod is safe to run again. Pass --dry-run to print the rewrites first, and run your formatter after the rewrite.


You are an agent migrating a codebase. Do this:

  1. Find every Popover, Tooltip, and HoverCard part from @ngrok/mantle. Search for Popover., Tooltip., and HoverCard., and for a renamed import of the same parts (import { Popover as MantlePopover }).
  2. On Popover.Content, Tooltip.Content, and HoverCard.Content, delete collisionPadding, collisionBoundary, sticky, avoidCollisions, alignOffset, hideWhenDetached, forceMount, updatePositionStrategy, and arrowPadding. Keep side, align, and sideOffset. The content flips to the opposite side when only that side fits, and shifts to stay 8px inside the viewport.
  3. On Popover.Root, delete modal. When the popover must block the page, trap focus, and lock scroll, use Dialog instead.
  4. Replace <HoverCard.Portal>…</HoverCard.Portal> with its children. HoverCard.Content portals by itself, into the content of the open overlay or popover that holds it, else into document.body.
  5. Replace --radix-popover-trigger-width with --anchor-width, and --radix-popover-content-available-height with --available-height, in class strings and stylesheets. Popover.Content sets both variables. The codemod changes only the props of Popover.Content itself; change shared strings, cva variants, and stylesheets by hand, and leave the variables of a Radix Popover that you import yourself.
  6. Remove asChild from Popover.Content and HoverCard.Content. Move the child element's props, such as className, onto the content, and render the child's own content as children.
  7. Remove id from Tooltip.Content. The trigger's aria-describedby points at the id that Tooltip.Root owns. Select the tooltip with [data-slot="tooltip-content"] instead.
  8. Delete a TooltipProvider that you mounted only because Tooltip.Root threw without one. Keep a provider that sets delayDuration, skipDelayDuration, or disableHoverableContent.
  9. Update tests that read the old shape:
    • A float no longer carries z-50 in browsers with the popover API. Assert popover on the content instead.
    • A float inside a Popover portals into Popover.Content, not next to it.
    • Tooltip.Trigger asChild and HoverCard.Trigger asChild join tooltip-trigger or hover-card-trigger ahead of the child's data-slot, as Popover.Trigger does.
    • A closed float stays in the DOM for its 150ms exit transition. Wait for it to go.
  10. After editing, run the project's formatter, linter, type checker, and tests.

Why native popovers? The top layer paints a float above every z-index with no stacking rules to learn, and CSS anchor positioning lets the browser keep it next to its trigger. The three components ship less JavaScript and no Radix dependency. A browser with no popover API (Safari before 17, Chrome before 114, Firefox before 125) shows the float as a fixed box at z-50, as before.


Before → after

Radix positioning props

// BEFORE<Popover.Content align="start" collisionPadding={16} sticky="always">	<ModelList /></Popover.Content>
// AFTER: the browser flips and shifts the content<Popover.Content align="start">	<ModelList /></Popover.Content>

A modal popover

// BEFORE<Popover.Root modal>…</Popover.Root>
// AFTER: a popover never blocks the page; use Dialog when it must<Popover.Root>…</Popover.Root>

HoverCard.Portal

// BEFORE<HoverCard.Portal>	<HoverCard.Content>Card</HoverCard.Content></HoverCard.Portal>
// AFTER<>	<HoverCard.Content>Card</HoverCard.Content></>

The Radix CSS variables

// BEFORE<Popover.Content className="max-h-(--radix-popover-content-available-height) w-(--radix-popover-trigger-width)" />
// AFTER<Popover.Content className="max-h-(--available-height) w-(--anchor-width)" />

Edge cases & gotchas

  • A float does not show while an overlay that does not hold it is open, because the top layer would paint it over that overlay. A tooltip or hover card closes. A popover hides, and shows again when the overlay closes.
  • Popover.Content is a layer container. A Select, DropdownMenu, or other float inside it portals into it, so it paints above the popover.
  • A press or a focus move outside a popover closes it and leaves focus where the user put it. onPointerDownOutside, onFocusOutside, and onInteractOutside still get a cancelable event with event.detail.originalEvent.
  • A DropdownMenu is still a Radix menu, and a modal one keeps focus inside the menu. A popover opened from a menu item takes clicks but not keyboard focus. Set modal={false} on that DropdownMenu.Root.
  • A float in the top layer paints above toasts, which stay at z-index: 999999999 in the page. Do not open a popover over the toast corner.
  • HoverCard.Trigger renders an <a>. It opens on hover and on keyboard focus, and not on touch.

How to verify

rg -n "collisionPadding|avoidCollisions|alignOffset|hideWhenDetached|updatePositionStrategy|HoverCard.Portal|--radix-popover" <path>

The search finds nothing in code that uses the three components. Run the type checker, which flags each removed prop the codemod could not reach, then the tests.