Keep Menu Open on SwiftUI?

Is there a way to keep the menu open after tapping on a button or toggle inside it instead of automatically minimizing it on every tap?

This isn't a feature that's going to production ever, by the way.

My code is something like this:

struct MyView: View {
    @State var toggleA = true
    @State var toggleB = true
    @State var toggleC = true

    var body: some View {
        NavigationView {
            SwiftUI.Form {
                Text("Hello")
            }
            .navigationTitle("My View")
            .navigationBarTitleDisplayMode(.inline)
            .navigationBarItems(trailing: {
                Menu {
                    Toggle("A", isOn: $toggleA)
                    Toggle("B", isOn: $toggleB)
                    Toggle("C", isOn: $toggleC)
                } label: {
                    Image(systemName: "ellipsis.circle")
                }
            }())
        }
    }
}

struct Preview: PreviewProvider {
    static var previews: some View {
        MyView()
    }
}
Answered by GyratoryCircus in 776110022

API supporting this was added in iOS 16.4 (docs)

Menu {
    ...
}
.menuActionDismissBehavior(.disabled)

Did you find a solution for this?

I am keen to know whether someone figured this out.

Accepted Answer

API supporting this was added in iOS 16.4 (docs)

Menu {
    ...
}
.menuActionDismissBehavior(.disabled)
Keep Menu Open on SwiftUI?
 
 
Q