I want to dismiss my Menu when click somewhere in view . Now when i click product Image it goes product detail.How can I solve this problem . Basically I want to dismiss only Menu when I click somewhere in view.
@State var selectedSort : String = ""
@State var isSelected : Bool = false
@Binding var sortClicked : Bool
@ObservedObject var productListViewModel = ProductListViewModel()
@State var sortListArray : [ProductListSortAndFilterList]
var function: () -> Void
@Binding var sortId : String
var body : some View {
HStack(alignment: .center){
Spacer()
Menu {
ForEach(sortListArray,id:\.id){ item in
if item.id == "sort" {
ForEach(item.sortList ?? [],id:\.id) { data in
Button(action: {
selectedSort = data.name ?? ""
sortId = (data.id ?? "")
self.function()
}) {
Text(data.name ?? "")
.tag(data.id)
if selectedSort == data.name {
Image(systemName: "checkmark")
}
}
}
}
}
} label: {
SortIcon()
}
