SwiftUI - CustomSearchBar - Event for clicking on the circle with the X in the text field

Hello everybody,

i have an application with a CustomSearchBar to search in my list entries.

To generally hide the keyboard (click outside the text field to search), I use this code.
Code Block
// Dismiss the keyboard
self.endEditing(true)
...
// Import for dissmissing Keyboard
extension View {
func endEditing(_ force: Bool) {
UIApplication.shared.windows.forEach { $0.endEditing(force)}
}
}


That works great. Now I would like to hide the keyboard, too, if I click on the x on the very right of the text field.

Which event do I have to intercept then? I do not really know what I have to look for.

Thanks in advance.
Sven

Hi, nobody can help me? Please.
You can use this method to dismiss a keyboard.
Code Block Swift
extension View {
func dismissKeyboard() {
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
}
}

The x in the search bar generally means clear the text, not end editing.
You could add an onTapGesture if you’re building the search bar in SwiftUI.

It would be helpful to see the code you use to make this CustomSearchBar.
SwiftUI - CustomSearchBar - Event for clicking on the circle with the X in the text field
 
 
Q