mirror of
https://github.com/kkebo/DNSecure.git
synced 2026-03-11 08:54:36 +00:00
Add a clear button on the right side of LazyTextField
This commit is contained in:
parent
e28358acfe
commit
78d4cd0b09
1 changed files with 20 additions and 7 deletions
|
|
@ -22,16 +22,29 @@ struct LazyTextField {
|
|||
|
||||
extension LazyTextField: View {
|
||||
var body: some View {
|
||||
TextField(self.title, text: self.$localText)
|
||||
.focused(self.$isFocused)
|
||||
.onChange(of: self.isFocused) { isFocused in
|
||||
if !isFocused {
|
||||
self.text = self.localText
|
||||
HStack {
|
||||
TextField(self.title, text: self.$localText)
|
||||
.focused(self.$isFocused)
|
||||
if self.isFocused && !self.localText.isEmpty {
|
||||
Button {
|
||||
self.text.removeAll()
|
||||
} label: {
|
||||
Image(systemName: "xmark.circle.fill")
|
||||
.foregroundColor(.primary)
|
||||
.opacity(0.2)
|
||||
}
|
||||
.buttonStyle(.borderless)
|
||||
.hoverEffect()
|
||||
}
|
||||
.onChange(of: self.text) { text in
|
||||
self.localText = text
|
||||
}
|
||||
.onChange(of: self.isFocused) { isFocused in
|
||||
if !isFocused {
|
||||
self.text = self.localText
|
||||
}
|
||||
}
|
||||
.onChange(of: self.text) { text in
|
||||
self.localText = text
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue