keep search field focus when clearing search text

This commit is contained in:
Satindar Dhillon
2022-05-11 18:24:40 -07:00
parent ad567a380e
commit a199d8b3bc

View File

@ -26,26 +26,31 @@ public struct SearchBar: View {
.padding(.leading, 10)
if self.searchTerm != "" {
Button(action: {
self.searchTerm = ""
self.isFocused = false
}) {
Image(systemName: "multiply.circle.fill")
.foregroundColor(.gray)
.padding(.trailing, 8)
}
Button(
action: {
self.searchTerm = ""
},
label: {
Image(systemName: "multiply.circle.fill")
.foregroundColor(.gray)
.padding(.trailing, 8)
}
)
}
}
)
.padding(.horizontal, 10)
if isFocused {
Button(action: {
self.isFocused = false
self.searchTerm = ""
}) {
Text("Cancel")
}
Button(
action: {
self.searchTerm = ""
self.isFocused = false
},
label: {
Text("Cancel")
}
)
.padding(.trailing, 10)
.transition(.move(edge: .trailing))
}