Skip to main content
.contextMenu(content: Component): Component;

Parameters

content
Component
required
The menu items to display in the context menu. Typically contains Button components that define the menu actions.

Support

Usage

Basic context menu

Text("Right-click me")
    .contextMenu(
        VStack([
            Button("Copy", () => {
                // Copy action
            }),
            Button("Paste", () => {
                // Paste action
            }),
            Button("Delete", () => {
                // Delete action
            })
        ])
    )

Context menu with icons

Image({ url: "photo.jpg" })
    .contextMenu(
        VStack([
            Button("Edit", () => {
                // Edit action
            }),
            Button("Share", () => {
                // Share action
            }),
            Button("Delete", () => {
                // Delete action
            })
        ])
    )

Examples

Complex context menu

Text("Document")
    .contextMenu(
        VStack([
            Button("Open", () => {
                console.log("Opening document");
            }),
            Button("Duplicate", () => {
                console.log("Duplicating document");
            }),
            Divider(),
            Button("Move to Trash", () => {
                console.log("Moving to trash");
            })
        ])
    )