onTapGesture in Menu or not working

Hi, after update to Swift6 and iOS 18 my code is not working anymore. This is code from documentation with onTapGesture (instead of primaryAction) and it's not working. OnTapGesture is not starting when user click.

            Menu {
                Button(action: {}) {
                    Label("Add to Reading List", systemImage: "eyeglasses")
                }
                Button(action: {}) {
                    Label("Add Bookmarks for All Tabs", systemImage: "book")
                }
                Button(action: {}) {
                    Label("Show All Bookmarks", systemImage: "books.vertical")
                }
            } label: {
                Label("Add Bookmark", systemImage: "book")
            } onTapGesture: {
                print(" Print on tap gesture")
            }

primaryAction isn't working either. I mean, primary action works but menu is not showing inside buttons.

            Menu {
                Button(action: {}) {
                    Label("Add to Reading List", systemImage: "eyeglasses")
                }
                Button(action: {}) {
                    Label("Add Bookmarks for All Tabs", systemImage: "book")
                }
                Button(action: {}) {
                    Label("Show All Bookmarks", systemImage: "books.vertical")
                }
            } label: {
                Label("Add Bookmark", systemImage: "book")
            } primaryAction: {
                print("")
            }

I also tried to overlay the menu, no effect.

ZStack {
                Menu {
                    Button(action: {}) {
                        Label("Add to Reading List", systemImage: "eyeglasses")
                    }
                    Button(action: {}) {
                        Label("Add Bookmarks for All Tabs", systemImage: "book")
                    }
                    Button(action: {}) {
                        Label("Show All Bookmarks", systemImage: "books.vertical")
                    }
                } label: {
                    Label("Add Bookmark", systemImage: "book")
                }
                Color.clear
                    .contentShape(Rectangle())
                    .onTapGesture {
                        print("Tap gesture recognized")
                    }
            }

Please help. How to start action when user is clicking on menu?

Answered by DTS Engineer in 805228022

You said:

primaryAction isn't working either. I mean, primary action works but menu is not showing inside buttons.

Could you please elaborate on this? did you long press on the menu to trigger the menu presentation ?

While using Menu(content🏷️ primaryAction:) API, the primary action gets performed when the user taps or clicks on the body of the control, and the menu presentation happens on a secondary gesture, such as on long press.

You said:

primaryAction isn't working either. I mean, primary action works but menu is not showing inside buttons.

Could you please elaborate on this? did you long press on the menu to trigger the menu presentation ?

While using Menu(content🏷️ primaryAction:) API, the primary action gets performed when the user taps or clicks on the body of the control, and the menu presentation happens on a secondary gesture, such as on long press.

Seeing the same issue here.

Sample code:

Menu {
    Button(action: {}, label: {
        Image(systemName: "book")
    })
} label: {
    Image(systemName: "book")
}
.onTapGesture {
    print("Tapped")
}

Expected output: "Tapped" gets printed when the menu is tapped.

Actual output: On iOS 18, "Tapped" does not get printed. on iOS 17 "Tapped" does get printed.

I find this to be a pretty major regression.

onTapGesture in Menu or not working
 
 
Q