Class Menu
A container for menu items organized in a vertical list.
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class Menu : BaseVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder
Remarks
The Menu component is a container that displays a vertical list of menu items, sections, and dividers. It provides a structured way to present actions, navigation options, or selectable items to users.
Menus are commonly used in context menus, dropdown menus, navigation sidebars, and command palettes. They support keyboard navigation, nested sub-menus, and scrolling for long lists of items.
The Menu component automatically handles focus management and keyboard navigation (Up/Down arrows) between menu items, making it fully keyboard accessible.
Note: Menu has picking mode set to ignore by default, but is focusable to support keyboard navigation.
Examples
Basic Menu Structure — Creating a simple file menu with items and a divider.
<ui:Menu>
<ui:MenuItem label="New File" icon="file" />
<ui:MenuItem label="Open" icon="folder-open" shortcut="Ctrl+O" />
<ui:MenuItem label="Save" icon="save" shortcut="Ctrl+S" />
<ui:MenuDivider />
<ui:MenuItem label="Exit" icon="exit" />
</ui:Menu>
Menu with Sections — Organizing menu items into titled sections.
<ui:Menu>
<ui:MenuSection title="Edit">
<ui:MenuItem label="Undo" shortcut="Ctrl+Z" />
<ui:MenuItem label="Redo" shortcut="Ctrl+Y" />
</ui:MenuSection>
<ui:MenuDivider />
<ui:MenuSection title="Selection">
<ui:MenuItem label="Select All" shortcut="Ctrl+A" />
<ui:MenuItem label="Deselect" />
</ui:MenuSection>
</ui:Menu>
Creating a Menu programmatically — Building a menu with code and managing sub-menus.
var menu = new Menu();
// Add regular items
menu.Add(new MenuItem { label = "Cut", icon = "scissors", shortcut = "Ctrl+X" });
menu.Add(new MenuItem { label = "Copy", icon = "copy", shortcut = "Ctrl+C" });
menu.Add(new MenuItem { label = "Paste", icon = "clipboard", shortcut = "Ctrl+V" });
// Add a divider
menu.Add(new MenuDivider());
// Add a selectable item
var item = new MenuItem { label = "Show Grid", selectable = true, value = true };
menu.Add(item);
// Close all sub-menus when needed
menu.CloseSubMenus();
Constructors
Menu()
Default constructor.
Declaration
public Menu()
Fields
containerUssClassName
The Menu container styling class.
Declaration
public const string containerUssClassName = "appui-menu__container"
Field Value
| Type | Description |
|---|---|
| string |
selectableUssClassName
The Menu selectable mode styling class.
Declaration
public const string selectableUssClassName = "appui-menu--selectable"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The Menu main styling class.
Declaration
public const string ussClassName = "appui-menu"
Field Value
| Type | Description |
|---|---|
| string |
Properties
contentContainer
The content container of the Menu.
Declaration
public override VisualElement contentContainer { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
Overrides
parentItem
The parent MenuItem of this Menu (if this Menu is a sub-menu).
Declaration
public MenuItem parentItem { get; }
Property Value
| Type | Description |
|---|---|
| MenuItem |
Methods
CloseSubMenus()
Close all sub-menus.
Declaration
public void CloseSubMenus()
GetMenuItems()
Get all the MenuItems of this Menu (including sub-menus).
Declaration
public IEnumerable<MenuItem> GetMenuItems()
Returns
| Type | Description |
|---|---|
| IEnumerable<MenuItem> | The list of MenuItems. |