Class MenuItem
An interactive item within a menu that triggers actions or displays sub-menus.
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class MenuItem : BaseVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder, INotifyValueChanged<bool>, IPressable
Remarks
MenuItem is an interactive element designed to be used within Menu components. Each item can display a label, icon, keyboard shortcut, and optional checkmark for selection state.
Menu items can be configured in several ways: as standard action items that trigger events when clicked, as selectable items with checkmarks to indicate state, or as parent items that open sub-menus when activated.
The component supports full keyboard navigation with Up/Down arrow keys to move between items, and Left/Right arrow keys to navigate into or out of sub-menus (respecting text direction).
When a MenuItem has a sub-menu attached, a small caret icon appears automatically as a visual indicator. The sub-menu opens on click or hover, and can be navigated with keyboard controls.
Examples
Basic Menu Items — Standard menu items with labels, icons, and shortcuts.
<ui:Menu>
<ui:MenuItem label="New" icon="file" shortcut="Ctrl+N" />
<ui:MenuItem label="Open" icon="folder-open" shortcut="Ctrl+O" />
<ui:MenuItem label="Recent Files" icon="clock" />
</ui:Menu>
Selectable Menu Items — Toggle menu items for editor preferences.
<ui:Menu>
<ui:MenuItem label="Word Wrap" selectable="true" value="true" />
<ui:MenuItem label="Show Line Numbers" selectable="true" value="false" />
<ui:MenuItem label="Show Minimap" selectable="true" value="true" />
</ui:Menu>
Menu with Sub-menus — Creating nested menus for hierarchical actions.
var menu = new Menu();
// Create a parent item with sub-menu
var viewItem = new MenuItem { label = "View", icon = "eye" };
var viewSubMenu = new Menu();
viewSubMenu.Add(new MenuItem { label = "Zoom In", shortcut = "Ctrl++" });
viewSubMenu.Add(new MenuItem { label = "Zoom Out", shortcut = "Ctrl+-" });
viewSubMenu.Add(new MenuDivider());
viewSubMenu.Add(new MenuItem { label = "Reset Zoom", shortcut = "Ctrl+0" });
viewItem.subMenu = viewSubMenu;
menu.Add(viewItem);
Handling Menu Item Actions — Responding to menu item interactions and state changes.
var menu = new Menu();
// Create item and handle selection
var saveItem = new MenuItem { label = "Save", icon = "save", shortcut = "Ctrl+S" };
saveItem.RegisterCallback<ActionTriggeredEvent>(evt => {
SaveDocument();
Debug.Log("Document saved");
});
// Create toggleable item and handle state changes
var gridItem = new MenuItem { label = "Show Grid", selectable = true };
gridItem.RegisterValueChangedCallback(evt => {
SetGridVisible(evt.newValue);
Debug.Log($"Grid visibility: ");
});
menu.Add(saveItem);
menu.Add(gridItem);
Constructors
MenuItem()
Default constructor.
Declaration
public MenuItem()
Fields
activeUssClassname
The MenuItem active styling class.
Declaration
public const string activeUssClassname = "appui-menuitem--active"
Field Value
| Type | Description |
|---|---|
| string |
checkmarkUssClassName
The MenuItem checkmark styling class.
Declaration
public const string checkmarkUssClassName = "appui-menuitem__checkmark"
Field Value
| Type | Description |
|---|---|
| string |
iconUssClassName
The MenuItem icon styling class.
Declaration
public const string iconUssClassName = "appui-menuitem__icon"
Field Value
| Type | Description |
|---|---|
| string |
labelUssClassName
The MenuItem label styling class.
Declaration
public const string labelUssClassName = "appui-menuitem__label"
Field Value
| Type | Description |
|---|---|
| string |
selectableUssClassname
The MenuItem selectable mode styling class.
Declaration
public const string selectableUssClassname = "appui-menuitem--selectable"
Field Value
| Type | Description |
|---|---|
| string |
shortcutUssClassName
The MenuItem shortcut styling class.
Declaration
public const string shortcutUssClassName = "appui-menuitem__shortcut"
Field Value
| Type | Description |
|---|---|
| string |
subMenuIconUssClassname
The MenuItem submenu icon styling class.
Declaration
public const string subMenuIconUssClassname = "appui-menuitem__submenu-icon"
Field Value
| Type | Description |
|---|---|
| string |
subMenuItemUssClassname
The MenuItem submenu mode styling class.
Declaration
public const string subMenuItemUssClassname = "appui-menuitem--submenu"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The MenuItem main styling class.
Declaration
public const string ussClassName = "appui-menuitem"
Field Value
| Type | Description |
|---|---|
| string |
Properties
active
Enable or disable the active mode of the item.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool active { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
clickable
Clickable Manipulator for this MenuItem.
Declaration
[CreateProperty]
public Pressable clickable { get; set; }
Property Value
| Type | Description |
|---|---|
| Pressable |
contentContainer
The content container of the MenuItem.
Declaration
public override VisualElement contentContainer { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
Overrides
hasSubMenu
Whether the item has a sub menu.
Declaration
[CreateProperty(ReadOnly = true)]
public bool hasSubMenu { get; }
Property Value
| Type | Description |
|---|---|
| bool |
icon
The icon to display next to the label.
Declaration
[CreateProperty]
[UxmlAttribute]
public string icon { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
label
The label text value.
Declaration
[CreateProperty]
[UxmlAttribute]
public string label { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
selectable
Enable or disable the selectable mode of the item.
A selectable item is an item with a small checkmark as leading UI element.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool selectable { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
shortcut
The shortcut text value.
Declaration
[CreateProperty]
[UxmlAttribute]
public string shortcut { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
subMenu
Sub Menu linked to this item.
An item with a submenu mode enabled has a small caret as trailing UI element which defines that a sub menu will appear if you trigger the item's action.
Declaration
[CreateProperty]
public Menu subMenu { get; set; }
Property Value
| Type | Description |
|---|---|
| Menu |
value
The selected state of the item.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool value { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
You should set the item as selectable first to see any result.
Methods
SetValueWithoutNotify(bool)
Set the selected state of this item.
See value and selectable properties for more info.
Declaration
public void SetValueWithoutNotify(bool newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | newValue | The new selected state. |
Events
subMenuOpened
The event raised when the item's submenu is opened.
Declaration
public event Action subMenuOpened
Event Type
| Type | Description |
|---|---|
| Action |