The Menu component in Scripting is a user interface control that presents a list of actions or nested submenus. It functions as a container for contextual actions and supports both text-based and custom visual labels. Inspired by SwiftUI’s Menu, this component is especially useful in toolbars, context menus, and compact UI layouts.
Use Menu to group multiple related actions under a single interaction point. A menu can include Button components and even other nested Menu components for hierarchical command structures.
| Property | Type | Description |
|---|---|---|
primaryAction |
() => void (optional) |
An action that executes when the menu is tapped directly, without expanding it. Useful for a default behavior. |
children |
VirtualNode | VirtualNode[] |
The menu’s content—usually a list of Button components or nested Menu components. |
You must specify either a text-based title or a custom label.
title with optional system image| Property | Type | Description |
|---|---|---|
title |
string |
A text string describing the menu’s purpose. |
systemImage |
string (optional) |
The name of a system SF Symbol image to display with the title. |
label (custom view)| Property | Type | Description |
|---|---|---|
label |
VirtualNode |
A custom view node (e.g., Text, Image, HStack) to use as the menu’s label. |
In this example:
A top-level menu labeled "Actions" contains:
primaryAction and systemImageprimaryAction is executed.This example uses a custom label combining an icon and text.
toolbar, contextMenu, or as part of compact user interfaces.primaryAction for lightweight actions that don't require expansion.