Mantle Native Dropdown Menu Migration Guide
@ngrok/mantle's DropdownMenu no longer uses Radix. DropdownMenu.Content and DropdownMenu.SubContent are native popover elements in the browser's top layer, and CSS anchor positioning places them. Where the browser has no anchor positioning, a small script places them. The parts, their nesting, and the other props stay the same, so no call site changes shape.
TL;DR: Delete alignOffset, avoidCollisions, collisionBoundary, collisionPadding, arrowPadding, sticky, hideWhenDetached, updatePositionStrategy, and forceMount from DropdownMenu.Content and DropdownMenu.SubContent. Replace --radix-dropdown-menu-trigger-width with --anchor-width and --radix-dropdown-menu-content-available-height with --available-height.
Codemod
From a mantle checkout:
In a project that installs @ngrok/mantle:
The rules apply steps 2 and 3. They delete the Radix positioning props from DropdownMenu.Content and DropdownMenu.SubContent, and rename the two CSS variables in the props of those parts in a file that imports @ngrok/mantle/dropdown-menu. The rules read a part through its import, 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. Shared class constants and stylesheets stay manual. 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:
- Find every
DropdownMenupart from@ngrok/mantle. Search forDropdownMenu., and for a renamed import of the same parts (import { DropdownMenu as Menu }). - On
DropdownMenu.ContentandDropdownMenu.SubContent, deletealignOffset,avoidCollisions,collisionBoundary,collisionPadding,arrowPadding,sticky,hideWhenDetached,updatePositionStrategy, andforceMount. Keepside,align, andsideOffsetonContent, andalignandsideOffsetonSubContent. The menu flips to the opposite side when only that side fits, and shifts to stay 8px inside the viewport. - Replace
--radix-dropdown-menu-trigger-widthwith--anchor-width, and--radix-dropdown-menu-content-available-heightwith--available-height, in class strings and stylesheets. The codemod changes only the props of the two parts; change shared strings,cvavariants, and stylesheets by hand. - Delete
modal={false}from aDropdownMenu.Rootthat you set only so that aPopoveropened from an item could take keyboard focus. A float that an item opens now portals into the menu and takes focus in a modal menu. - Update tests that read the old shape:
- A modal menu sets
inerton the rest of the page, notaria-hidden. Query an element outside the menu withclosest("[inert]"). - The content keeps
z-50for browsers with no popover API, but the top layer, notz-index, orders it in the others. Assertpopoveron the content to check that it is a native float. - A closed menu stays in the DOM for its 150ms exit transition. Wait for it to go.
DropdownMenu.ContenthassideOffset={8}in place of amy-2margin class.
- A modal menu sets
- After editing, run the project's formatter, linter, type checker, and tests.
Why native popovers? The top layer paints the menu above every
z-index, CSS anchor positioning keeps it next to its trigger, and the menu ships less JavaScript with no Radix dependency. A browser with no popover API (Safari before 17, Chrome before 114, Firefox before 125) shows the menu as a fixed box atz-50, as before.
Before → after
Radix positioning props
The Radix CSS variables
A popover opened from a menu item
Edge cases & gotchas
- A menu closes when an overlay that does not hold it opens, because the top layer would paint it over that overlay.
DropdownMenu.ContentandDropdownMenu.SubContentare layer containers. APopover,Select, or other float inside an item portals into the menu, so it paints above the menu and stays reachable while the page is inert.ArrowUpon the trigger opens the menu on its last item, as the WAI-ARIA menu button pattern describes.DropdownMenu.RadioGrouptakesdefaultValue, andDropdownMenu.CheckboxItemtakesdefaultChecked, for an uncontrolled menu.- A press outside the menu closes it. In a modal menu, focus returns to the trigger. With
modal={false}, or after a right click, focus stays where the user put it. The menu also closes when the window loses focus.onPointerDownOutside,onFocusOutside, andonInteractOutsidestill get a cancelable event withevent.detail.originalEvent. - A menu in the top layer paints above toasts, which stay at
z-index: 999999999in the page.
How to verify
The search finds nothing in code that uses DropdownMenu. Run the type checker, which flags each removed prop the codemod could not reach, then the tests.