# Menu An unstyled, accessible menu component with compound composition for inline and popup navigation. ## Features - Compound component API with sub-components: `Root`, `List`, `Item`, `CheckboxItem`, `RadioItemGroup`, `RadioItem`, `Sub`, `SubTrigger`, `Indicator`, `Label`, `Separator`, `Trigger`, `Portal`, `Positioner`, `Popup`, `Arrow`. Submenus reuse `Portal`/`Positioner`/`Popup` inside `Menu.Submenu`; the same components automatically detect the sub context. - Inline and portal-based popup rendering modes - Nested submenus with open/close coordination - Checkbox and radio item types with indicator matching - Built-in character search to jump to items by typing - Composite mode for complex nested menus with hover-to-open behavior ## Usage ```tsx import { Menu } from 'primereact/menu'; ``` ```tsx ``` ## Behavior ### Checkbox Items Use `Menu.CheckboxItem` to create a toggleable item managed by `useCheckbox`. Use `Menu.Indicator` with `match="checked"` to display a checkmark when the item is active. ```tsx Enable Notifications ``` ### Radio Items Wrap `Menu.RadioItem` elements inside a `Menu.RadioItemGroup`. The group is managed by `useRadioButtonGroup` and each item by `useRadioButton`. Use `Menu.Indicator` with `match="checked"` to display a dot or icon for the selected option. ```tsx Light Mode Dark Mode ``` ### Motion Animation ```tsx ``` See [Motion](/docs/primitive/components/motion) for animation phases, CSS variables, and hide strategies. ### Polymorphic Rendering Use `as` on any sub-component to change the rendered HTML element. ```tsx Dashboard ``` Default elements: `Root`=`div`, `List`=`ul`, `Item`=`li`, `CheckboxItem`=`li`, `RadioItem`=`li`, `Sub`=`li`, `SubTrigger`=`div`, `Trigger`=`button`, `Label`=`li`, `Separator`=`li`, `Indicator`=`span`, `Popup`=`div`, `Positioner`=`div`, `Arrow`=`div`, `RadioItemGroup`=`div`, `Portal`=portal. ### Render Function Children `Item` and `SubTrigger` accept a render function as children, providing access to the component instance. ```tsx {(instance) => {instance.focused ? 'Focused' : 'Idle'}} ``` ## Pass Through ## API ### MenuRoot | Attribute | Value | | ------------ | -------- | | `data-scope` | `"menu"` | | `data-part` | `"root"` | | Label | Type | Description | |:------|:------|:------| | root | MenuRootPassThroughType> | Used to pass attributes to the root's DOM element. | | list | MenuRootPassThroughType> | Used to pass attributes to the list's DOM element. | | item | MenuRootPassThroughType> | Used to pass attributes to the item's DOM element. | | label | MenuRootPassThroughType> | Used to pass attributes to the label's DOM element. | | sub | MenuRootPassThroughType> | Used to pass attributes to the submenu's DOM element. | | trigger | MenuRootPassThroughType> | Used to pass attributes to the trigger's DOM element. | | subtrigger | MenuRootPassThroughType> | Used to pass attributes to the subtrigger's DOM element. | | checkboxItemIndicator | MenuRootPassThroughType> | Used to pass attributes to the checkbox item indicator's DOM element. | | radioItemIndicator | MenuRootPassThroughType> | Used to pass attributes to the radio item indicator's DOM element. | | submenuIndicator | MenuRootPassThroughType> | Used to pass attributes to the submenu indicator's DOM element. | | separator | MenuRootPassThroughType> | Used to pass attributes to the separator's DOM element. | | popup | MenuRootPassThroughType> | Used to pass attributes to the popup's DOM element. | | arrow | MenuRootPassThroughType> | Used to pass attributes to the arrow's DOM element. | | positioner | MenuRootPassThroughType> | Used to pass attributes to the positioner's DOM element. | | subpositioner | MenuRootPassThroughType> | Used to pass attributes to the subpositioner's DOM element. | | subpopup | MenuRootPassThroughType> | Used to pass attributes to the subpopup's DOM element. | | subportal | MenuRootPassThroughType> | Used to pass attributes to the subportal's DOM element. | ### MenuTrigger | Attribute | Value | | ------------ | ------------------------- | | `data-scope` | `"menu"` | | `data-part` | `"trigger"` | | `data-open` | Present when menu is open | | Label | Type | Description | |:------|:------|:------| | root | MenuTriggerPassThroughType> | Used to pass attributes to the root's DOM element. | ### MenuList | Attribute | Value | | ------------ | -------- | | `data-scope` | `"menu"` | | `data-part` | `"list"` | | Label | Type | Description | |:------|:------|:------| | root | MenuListPassThroughType> | Used to pass attributes to the root's DOM element. | | content | MenuListPassThroughType> | Used to pass attributes to the content's DOM element. | ### MenuItem | Attribute | Value | | --------------- | ----------------------------- | | `data-scope` | `"menu"` | | `data-part` | `"item"` | | `data-value` | The item value | | `data-focused` | Present when item is focused | | `data-disabled` | Present when item is disabled | | `data-checked` | Present when item is checked | | Label | Type | Description | |:------|:------|:------| | root | MenuItemPassThroughType> | Used to pass attributes to the root's DOM element. | ### MenuSubmenu | Attribute | Value | | ------------ | ---------------------------- | | `data-scope` | `"menu"` | | `data-part` | `"sub"` | | `data-open` | Present when submenu is open | | Label | Type | Description | |:------|:------|:------| | root | MenuSubmenuPassThroughType> | Used to pass attributes to the root's DOM element. | ### MenuSubmenuTrigger | Attribute | Value | | --------------- | ----------------------------------- | | `data-scope` | `"menu"` | | `data-part` | `"subtrigger"` | | `data-value` | The subtrigger value | | `data-focused` | Present when subtrigger is focused | | `data-disabled` | Present when subtrigger is disabled | | `data-open` | Present when submenu is open | | Label | Type | Description | |:------|:------|:------| | root | MenuSubmenuTriggerPassThroughType> | Used to pass attributes to the root's DOM element. | ### MenuIndicator | Attribute | Value | | ---------------- | ------------------------------ | | `data-scope` | `"menu"` | | `data-part` | `"indicator"` | | `data-open` | Present when submenu is open | | `data-closed` | Present when submenu is closed | | `data-checked` | Present when item is checked | | `data-unchecked` | Present when item is unchecked | ### MenuLabel | Attribute | Value | | ------------ | --------- | | `data-scope` | `"menu"` | | `data-part` | `"label"` | | Label | Type | Description | |:------|:------|:------| | root | MenuLabelPassThroughType> | Used to pass attributes to the root's DOM element. | ### MenuSeparator | Attribute | Value | | ------------ | ------------- | | `data-scope` | `"menu"` | | `data-part` | `"separator"` | | Label | Type | Description | |:------|:------|:------| | root | MenuSeparatorPassThroughType> | Used to pass attributes to the root's DOM element. | ### MenuCheckboxItem | Attribute | Value | | ------------ | -------- | | `data-scope` | `"menu"` | | `data-part` | `"item"` | | Label | Type | Description | |:------|:------|:------| | root | MenuCheckboxItemPassThroughType> | Used to pass attributes to the root's DOM element. | ### MenuRadioItemGroup | Attribute | Value | | ------------ | -------------- | | `data-scope` | `"menu"` | | `data-part` | `"radiogroup"` | ### MenuRadioItem | Attribute | Value | | ------------ | -------- | | `data-scope` | `"menu"` | | `data-part` | `"item"` | | Label | Type | Description | |:------|:------|:------| | root | MenuRadioItemPassThroughType> | Used to pass attributes to the root's DOM element. | ### MenuPopup | Attribute | Value | | ------------ | --------- | | `data-scope` | `"menu"` | | `data-part` | `"popup"` | | Label | Type | Description | |:------|:------|:------| | root | MenuPopupPassThroughType> | Used to pass attributes to the root's DOM element. | ### MenuPositioner | Attribute | Value | | ------------ | -------------- | | `data-scope` | `"menu"` | | `data-part` | `"positioner"` | **CSS Custom Properties** The positioner element exposes CSS custom properties for layout and transform control. | CSS Variable | Description | | ------------------------------ | ---------------------------------------- | | `--px-available-height` | Available vertical space in pixels | | `--px-available-width` | Available horizontal space in pixels | | `--px-transform-origin` | Computed transform origin for animations | | `--px-positioner-anchor-width` | Width of the anchor/trigger element | | Label | Type | Description | |:------|:------|:------| | root | MenuPositionerPassThroughType> | Used to pass attributes to the root's DOM element. | ### MenuArrow | Attribute | Value | | ------------ | --------- | | `data-scope` | `"menu"` | | `data-part` | `"arrow"` | **CSS Custom Properties** The arrow element exposes CSS custom properties for dynamic positioning: | CSS Variable | Description | | ------------------------ | ------------------------------ | | `--px-placer-arrow-x` | Horizontal offset of arrow | | `--px-placer-arrow-y` | Vertical offset of arrow | | `--px-placer-arrow-left` | Left position of arrow element | | `--px-placer-arrow-top` | Top position of arrow element | | Label | Type | Description | |:------|:------|:------| | root | MenuArrowPassThroughType> | Used to pass attributes to the root's DOM element. | ### MenuPortal | Label | Type | Description | |:------|:------|:------| | root | MenuPortalPassThroughType> | Used to pass attributes to the root's DOM element. | ### MenuCheckboxItem | Label | Type | Description | |:------|:------|:------| | root | MenuCheckboxItemPassThroughType> | Used to pass attributes to the root's DOM element. | ### MenuRadioItem | Label | Type | Description | |:------|:------|:------| | root | MenuRadioItemPassThroughType> | Used to pass attributes to the root's DOM element. | ### MenuIcon ### MenuCheckboxIcon ### MenuRadioIcon ## Accessibility ### Screen Reader Menu component uses the `menu` role and the value to describe the menu can either be provided with `aria-labelledby` or `aria-label` props. Each list item has a `menuitem` role with `aria-label` referring to the label of the item and `aria-disabled` defined if the item is disabled. Checkbox items use `menuitemcheckbox` and radio items use `menuitemradio` roles with `aria-checked` to indicate selection state. In popup mode, the component implicitly manages the `aria-expanded`, `aria-haspopup` and `aria-controls` attributes of the target element to define the relation between the target and the popup. ### Keyboard Support | Key | Function | | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `tab` | Add focus to the first item if focus moves in to the menu. If the focus is already within the menu, focus moves to the next focusable item in the page tab sequence. | | `shift + tab` | Add focus to the first item if focus moves in to the menu. If the focus is already within the menu, focus moves to the previous focusable item in the page tab sequence. | | `enter` | Activates the focused menuitem. If menu is in overlay mode, popup gets closes and focus moves to target. | | `space` | Activates the focused menuitem. If menu is in overlay mode, popup gets closes and focus moves to target. | | `escape` | If menu is in overlay mode, popup gets closes and focus moves to target. | | `down arrow` | Moves focus to the next menuitem. | | `up arrow` | Moves focus to the previous menuitem. | | `right arrow` | Opens submenu if focused item has one. Moves focus to the first item of the submenu. | | `left arrow` | Closes current submenu and moves focus to parent submenu trigger. | | `alt + up arrow` | If menu is in overlay mode, popup gets closes and focus moves to the target. | | `home` | Moves focus to the first menuitem. | | `end` | Moves focus to the last menuitem. |