Code Block Swift private struct MyView: View { @State var text: String = "textfield value." func onEditingChanged (isEditing: Bool) -> Void { print("changed \(isEditing)") } func onCommit() -> Void { print("commited") NSApplication.shared.sendAction(#selector(NSResponder.resignFirstResponder), to:nil, from:nil) } var body: some View { HStack { TextField("x", text: $text, onEditingChanged: onEditingChanged, onCommit: onCommit) .textFieldStyle(PlainTextFieldStyle()) .disableAutocorrection(true) } } }
After I finish entering on TextField and hit return key on my keyborad,I'm expecting the textfield to lose focus. However,it won't, and instead, all text in the textfield is selected? is there some workaround ?