Using .searchable on macOS causes focus to remain in the search field

I asked this on Stack Overflow,, and here,, but so far no answers.

I don't know if this is a bug on the implementation of .searchable on macOS, or it's the expected behavior, but when you add a .searchable to a NavigationView, with the expected behavior of the search field being placed at the right most part of the toolbar, a focus issue happens.

When you type the text you want to search, I can filter the list with that text, but when I place the mouse cursor on the first item on the list and try to move down the list with the arrow key, with each arrow key press, the focus goes back to the search field, making it impossible to navigate up and down the list with the keyboard. The same happens if I select each item with the mouse.

Maybe I'm not implementing it right, or maybe it doesn't work yet with macOS, either way, this is the code I'm using. This is part of a three panel view, with this one being the middle view (right next to the side bar):

struct AllNotes: View {
   @EnvironmentObject private var data: DataModel
   @State var selectedNoteId: UUID?
   @State var searchText: String = ""

   var body: some View {
      NavigationView {
            List(data.notes.filter { searchText.isEmpty ? true : $0.text.localizedCaseInsensitiveContains(searchText) }) { note in
                NavigationLink(
                    destination: NoteView(note: note),
                    tag: note.id,
                    selection: $selectedNoteId
                ) {
                    VStack(alignment: .leading) {
                        Text(getFirstLine(noteText: note.text)).font(.body).fontWeight(.bold)
                    }
                }
            }
            .listStyle(InsetListStyle())
            .toolbar {
                // a few other buttons
            }
      }
      .searchable(
          text: $searchText,
          placement: .toolbar,
          prompt: "Search..."
      )
 
   }
}

Having the exact same problem right here. Adding an item from a filtered list to its selection by clicking on it, either with the mouse or using the keyboard to navigate to it, focuses on the search bar, but only if the search bar is not empty. Very frustrating!

I'm hoping this is a bug that will get fixed in the upcoming versions of SwiftUI...

Anyone knows if it's fixed in Ventura?

I had hopes that Xcode 14, macOS Monterrey and the latest Swiftui 5.7 would fix this, but no...

This was fixed on Ventura.

Using .searchable on macOS causes focus to remain in the search field
 
 
Q