-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DropdownMenu v2: Render in the default Popover.Slot #51046
Conversation
SlotFill
ad7d8a8
to
551f91b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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! ✨
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works well and the code looks great 👍 🙌
<DropdownMenuStyled.Content | ||
side={ side } | ||
align={ align } | ||
sideOffset={ sideOffset } | ||
alignOffset={ alignOffset } | ||
loop={ true } | ||
> | ||
{ children } | ||
<DropdownMenuPrivateContext.Provider | ||
value={ { portalContainer } } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why we memoize the context value in #51097 but not here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* 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.Slot
slot (thus behaving the same way as the legacyDropdownMenu
component).Why?
This is to integrate the new component better with how the editor expects its popover-based components to function.
How?
useSlot
hook to get the reference to the actual DOM elementPopover
's default slot nameFurther considerations
We purposefully decided not to expose any new prop on
DropdownMenu
for now:slotName
prop (thus keeping the integration withSlotFill
an implementation detail of the component), or aportalContainer
prop (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.