DropdownMenu v2: Render in the default Popover.Slot#51046
Conversation
SlotFillad7d8a8 to
551f91b
Compare
andrewserong
left a comment
There was a problem hiding this comment.
This is testing nicely for me, and the logic of ensuring the new DropdownMenu is rendered to the same popover slot as the legacy menu sounds good 👍
✅ Double-checked the Radix UI docs that the container passed to the portal is correct
✅ Tests nicely in Storybook with both the root dropdown menu and any sub menus, with the sub menus correctly picking up the portalContainer from context, and each of the dropdown menu levels being rendered as siblings within the popover-slot:
LGTM! ✨
tyxla
left a comment
There was a problem hiding this comment.
It works well and the code looks great 👍 🙌
| > | ||
| { children } | ||
| <DropdownMenuPrivateContext.Provider | ||
| value={ { portalContainer } } |
There was a problem hiding this comment.
Any reason why we memoize the context value in #51097 but not here?
There was a problem hiding this comment.
* Add new slotName prop * Add storybook example * Use context to use same slot for submenu portal * Use default popover slot instead of exposing a slotName prop, update Storybook * CHANGELOG

Part of #50459
What?
Tweak the new
DropdownMenu's behavior so that, instead of appending its contents in thedocument.body, it renders by default in thePopover.Slotslot (thus behaving the same way as the legacyDropdownMenucomponent).Why?
This is to integrate the new component better with how the editor expects its popover-based components to function.
How?
useSlothook to get the reference to the actual DOM elementPopover's default slot nameFurther considerations
We purposefully decided not to expose any new prop on
DropdownMenufor now:slotNameprop (thus keeping the integration withSlotFillan implementation detail of the component), or aportalContainerprop (thus making the component more generic and reusable also for consumers that don't necessarily rely onSlotFill)Testing Instructions
Open the Storybook example, and verify that the contents of the dropdown menu (including its submenus) all render inside the
<div class="popover-slot" />element.