Skip to main content
contextMenu(content: Component | Component[]): Component;

Parameters

content
Component | Component[]
The menu items to display in the context menu. Can be a single component or an array of components (typically buttons).

Support

Usage

Basic context menu

Text("Long press me")
    .contextMenu([
        Button("Copy", () => console.log("Copy")),
        Button("Paste", () => console.log("Paste")),
        Button("Delete", () => console.log("Delete"))
    ])

Context menu with dividers

Image({ systemName: "photo" })
    .contextMenu([
        Button("Save to Photos", () => {}),
        Button("Copy Image", () => {}),
        Divider(),
        Button("Delete", () => {})
            .foregroundStyle(Color("red"))
    ])

Nested context menu

VStack([
    Text("Item with context menu")
])
.contextMenu([
    Button("Edit", () => {}),
    Button("Duplicate", () => {}),
    Menu("More Options", [
        Button("Archive", () => {}),
        Button("Export", () => {})
    ]),
    Divider(),
    Button("Delete", () => {})
])