NSPopover Won't Dismiss on Click Outside in macOS 13.6 with SwiftUI
I'm testing a new approach and I'm testing a new approach and I'm experiencing an issue with an NSPopover that is supposed to display options for a user in my macOS 13.6 app built with SwiftUI. The popover correctly appears when I click a button, but it won't dismiss when I click outside of it. Instead, it remains open until I click the button again. I've implemented the popover like this: ```swift import SwiftUI import AppKit struct ContentView: View { @State private var showingPopover = false var body: some View { Button(action: { self.showingPopover.toggle() }) { Text("Show Options") } .popover(isPresented: $showingPopover, arrowEdge: .top) { PopoverContent() } } } struct PopoverContent: View { var body: some View { VStack { Text("Options") Button("Close") { // This is to demonstrate that the popover can be closed programmatically } } .frame(width: 200, height: 100) } } ``` I also tried adding a tap gesture to detect clicks outside the popover, but it seems to conflict with the popover's own dismissal logic. Hereβs what I attempted: ```swift struct ContentView: View { @State private var showingPopover = false var body: some View { ZStack { Color.clear .contentShape(Rectangle()) .onTapGesture { self.showingPopover = false } Button(action: { self.showingPopover.toggle() }) { Text("Show Options") } .popover(isPresented: $showingPopover, arrowEdge: .top) { PopoverContent() } } } } ``` Despite these modifications, the popover still does not dismiss on an outside click. I've also checked the documentation and various articles about NSPopover behavior in SwiftUI, but I haven't found a solution that works. I would appreciate any insights or workarounds that could help with this behavior, especially if there are any best practices for handling popover dismissal in a SwiftUI context. I recently upgraded to Swift 3.10. I'd love to hear your thoughts on this.