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.
A selectable item reports its state with the glyph named by indicator: a checkmark for an independent on/off row, or a bullet for one row of a mutually exclusive set. Put the latter inside a MenuRadioGroup, which sets the indicator and enforces the exclusivity for you.
variant tints the whole row, label, icon and indicator, with the semantic destructive colour. Use it for actions with irreversible consequences such as deleting data.
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>
Radio and Destructive Items — A mutually exclusive set, and an irreversible action.
<ui:Menu>
<ui:MenuSection title="Density">
<ui:MenuRadioGroup value="normal">
<ui:MenuItem key="compact" label="Compact" />
<ui:MenuItem key="normal" label="Normal" />
<ui:MenuItem key="comfort" label="Comfort" />
</ui:MenuRadioGroup>
</ui:MenuSection>
<ui:MenuDivider />
<ui:MenuItem label="Delete" icon="trash" shortcut="Del" variant="Destructive" />
</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 |
indicatorUssClassName
The MenuItem indicator styling class prefix.
Declaration
public const string indicatorUssClassName = "appui-menuitem--indicator-"
Field Value
| Type | Description |
|---|---|
| string |
labelUssClassName
The MenuItem label styling class.
Declaration
public const string labelUssClassName = "appui-menuitem__label"
Field Value
| Type | Description |
|---|---|
| string |
radioUssClassName
The MenuItem radio bullet styling class.
Declaration
public const string radioUssClassName = "appui-menuitem__radio"
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 |
variantUssClassName
The MenuItem variant styling class prefix.
Declaration
public const string variantUssClassName = "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 |
indicator
The glyph shown for the item's selection state. Defaults to Checkmark.
Declaration
[CreateProperty]
[UxmlAttribute]
public MenuItemIndicator indicator { get; set; }
Property Value
| Type | Description |
|---|---|
| MenuItemIndicator |
Remarks
Only visible while the item is selectable.
key
A stable identifier for this item inside a MenuRadioGroup.
Declaration
[CreateProperty]
[UxmlAttribute]
public string key { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Remarks
Mirrors key: the group's value is the key of its selected row, so the selection survives the rows being rebuilt or reordered. Ignored outside a group.
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.
variant
The visual variant of the item. Defaults to Default.
Declaration
[CreateProperty]
[UxmlAttribute]
public MenuItemVariant variant { get; set; }
Property Value
| Type | Description |
|---|---|
| MenuItemVariant |
Methods
GetIndicatorUssClassName(MenuItemIndicator)
Declaration
public static string GetIndicatorUssClassName(MenuItemIndicator enumValue)
Parameters
| Type | Name | Description |
|---|---|---|
| MenuItemIndicator | enumValue |
Returns
| Type | Description |
|---|---|
| string |
GetVariantUssClassName(MenuItemVariant)
Declaration
public static string GetVariantUssClassName(MenuItemVariant enumValue)
Parameters
| Type | Name | Description |
|---|---|---|
| MenuItemVariant | enumValue |
Returns
| Type | Description |
|---|---|
| string |
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 |