This component should not be confused with ComboBox which provides a selectable list of options within a form.
OUI exports 5 menu-related components:
react-aria-components
.react-aria-components
.Menu items can be disabled using the disabledKeys
prop to the Menu
component.
Note: It's important to have a unique key for each item, otherwise the disabled keys will not work.
You can use the onAction prop to get the key of the selected item.
You can also add icons to the menu items using the startContent
/ endContent
props.
You can use the MenuSection
component to group menu items.
You can use any component as a trigger for the menu, just wrap it in the MenuTrigger
component.
You can also nest submenus inside a a menu using the SubmenuTrigger
and Menu
components.
The <MenuItem>
component works with frameworks and client side routers like Next.js and React Router. See the Routing guide to learn how to set this up.
Menu has multiple components with slots; the Menu
, MenuItem
, and MenuSection
components.
The slots extend from ListboxItem
slots, but not all slots are used. Below are the slots used by MenuItem
.