DropdownMenuItem and ContextMenuItem VS just MenuItem #992
-
I'm building a component library based on Radix Primitives and come across a design question: Why there are Expected API: <>
<DropdownMenu>
<DropdownMenuTrigger />
<MenuContent>
<MenuItem />
<MenuSeparator />
<MenuCheckboxItem />
</MenuContent>
</DropdownMenu>
<ContextMenu>
<ContextMenuTrigger />
<MenuContent>
<MenuItem />
<MenuSeparator />
<MenuCheckboxItem />
</MenuContent>
</ContextMenu>
{/* a more aggressive one */}
<Menu>
<DropdownMenuTrigger />
<MenuContent>...</MenuContent>
</Menu>
</> The only difference between It seems that the implementations of |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
hi @buffaybu, We do this by design for a few reasons:
In the case of I hope this helps you understand our decisions to go this direction. Additionally, we are always keen to understand use-cases and figure out where people hit barriers so with that in mind, can I ask what situation prompted your question? Where is the friction day to day with this? Is it when trying to share the styles for both? Thanks! 🙏 |
Beta Was this translation helpful? Give feedback.
-
Just to clarify,
Those last two points ensure we are able to keep bundle size small for Furthermore, the scoping is a very important piece.... if you opened a <Menu>
<DropdownMenuTrigger />
<MenuContent>
<Menu>
<ContextMenuTrigger />
<MenuTriggerItem />
{/* Is this a submenu or a context menu? */}
<MenuContent>...</MenuContent>
</Menu>
</MenuContent>
</Menu> Things may look the same but that does not mean they are the same in terms of functionality or keyboard and/or screen reader accessibility. |
Beta Was this translation helpful? Give feedback.
hi @buffaybu,
We do this by design for a few reasons:
In the case of
DropdownMenuItem
andContextMenuItem
, you are correct that they are mostly equivalent and extend our internalMenuItem
. In fact, before the introduction of context scoping (#906) they were the same. That…