Peter Lapisu
Peter Lapisu

Reputation: 21005

CHanging @FocusState on searchable doesn't make it focused

When the search becomes active i get a callback with .onChange(of: isFocused

but setting isFocused to false doesn't make the search inactive

struct MainSearchable: ViewModifier {
    
    @State var searchText: String = ""
    
    @FocusState private var isFocused: Bool
    
    func body(content: Content) -> some View {
        content
            .searchable(text: $searchText, placement: .toolbar)
            .searchSuggestions {
               ...
            }
            .onChange(of: isFocused, perform: { newValue in
                print("FOCUSED")
            })
            .onSubmit(of: .search) {
                ...
            }
            .focused($isFocused)
    }
}

Upvotes: 1

Views: 464

Answers (0)

Related Questions