We are trying to submit a login form on enter by using onCommit. It works but it seems that it is not a good fit because the onCommit action triggers whenever the field loses focus, so simply clicking between the email/password fields will cause the form to be submitted.
Here is a playground showing the issue:
Here is a playground showing the issue:
Code Block import SwiftUI import PlaygroundSupport struct LoginView: View { @State public var email: String @State public var password: String var body: some View { TextField("Email", text: $email) SecureField("Password", text: $password, onCommit: onLoginAction) Button("Login", action: onLoginAction) } } func onLoginAction() { print("submitting login") } PlaygroundPage.current.setLiveView(LoginView(email: "a@b.cc", password: "secret"))