Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI ContextMenu with Submenu

Tags:

macos

swiftui

I am developing a macOS app in SwiftUI. I am using .contextMenu modifier inside my List. It all works fine, however I am trying to make a submenu.

Usually I am just using buttons, I am not trying to make a hierarchy / or a submenu. It is possible and being used in many Apple default apps. I just not sure how to create that menu. That's the code I am currently using

.contextMenu {
    Button(action: {
    })
    {
        Text("Button")
    }
}
   

Here is a picture of the default Calendar app, with a sub menu.

like image 695
davidev Avatar asked Oct 01 '20 13:10

davidev


Video Answer


1 Answers

You can use Menu for nested menu hierarchies:

.contextMenu {
    Menu("Nested Root") {
        Button("Nested #1") {}
        Button("Nested #2") {}
        Button("Nested #3") {}
    }
    Button("Not Nested") { }
}

like image 94
Kirsteins Avatar answered Sep 22 '22 19:09

Kirsteins