<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/TableRowContent/contextMenu(menuItems:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI15TableRowContentPAAE11contextMenu9menuItemsAA08ModifiedE0VyxAA08_ContextgcD8ModifierVyqd__GGqd__yXE_tAA4ViewRd__lF"
  },
  "title" : "contextMenu(menuItems:)"
}
-->

# contextMenu(menuItems:)

Adds a context menu to a table row.

```
@MainActor @preconcurrency func contextMenu<M>(@ContentBuilder menuItems: () -> M) -> ModifiedContent<Self, _ContextMenuTableRowModifier<M>> where M : View
```

## Parameters

`menuItems`

A closure that produces the menu’s contents. You
can deactivate the context menu by returning nothing from the closure.

## Return Value

A row that can display a context menu.

## Discussion

Use this modifier to add a context menu to a table row. Compose
the menu by returning controls like [`Button`](/documentation/SwiftUI/Button), [`Toggle`](/documentation/SwiftUI/Toggle), and
[`Picker`](/documentation/SwiftUI/Picker) from the `menuItems` closure. You can also use [`Menu`](/documentation/SwiftUI/Menu)
to define submenus, or [`Section`](/documentation/SwiftUI/Section) to group items.

The following example adds a context menu to each row in a table
that people can use to send an email to the person represented by
that row:

```
Table(of: Person.self) {
    TableColumn("Given Name", value: \.givenName)
    TableColumn("Family Name", value: \.familyName)
} rows: {
    ForEach(people) { person in
        TableRow(person)
            .contextMenu {
                Button("Send Email...") { }
            }
    }
}
```

If you want to display a preview beside the context menu, use
[`contextMenu(menuItems:preview:)`](/documentation/SwiftUI/TableRowContent/contextMenu(menuItems:preview:)). If you want
to display a context menu that’s based on the current selection,
use [`contextMenu(forSelectionType:menu:primaryAction:)`](/documentation/SwiftUI/View/contextMenu(forSelectionType:menu:primaryAction:)). To add
context menus to other kinds of views, use [`contextMenu(menuItems:)`](/documentation/SwiftUI/View/contextMenu(menuItems:)).

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)