Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stop double clicking a NavigationLink opening a second window view?

Tags:

macos

swiftui

Writing a Macos app. The following code just puts up a simple navigation list. Everything is fine with single clicking the Row links and displaying the Detail row. If you double click the NavigationLink, another window opens with only the Text view on it. During my testing, there was a button to dismiss the view on the detail window, and if clicked, the original window would close leaving this stripped down view open.

I have to assume that no one else is seeing this since I cannot see anything from other people. Does anyone have any ideas what would cause this to happen?

import SwiftUI

struct ContentView: View {

    var body: some View {
        HStack {
            NavigationView {
                List(0..<100) { row in
                    NavigationLink(destination: Text("Detail \(row)")) {
                        Text("Row \(row)")
                    }
                }
            }
        }
    }
}
like image 333
BrianQ Avatar asked Oct 21 '25 12:10

BrianQ


1 Answers

Just use sidebar list style explicitly

List(0..<100) { row in

   // ... content here

}
.listStyle(SidebarListStyle())     // << here !1

Tested with Xcode 13.2 / macOS 12.1

like image 76
Asperi Avatar answered Oct 24 '25 04:10

Asperi