Post

Replies

Boosts

Views

Activity

SwiftUI MacOS Return/Enter Key in TextField
So I am a little frustrated because this has to be simple and I am just missing it. I have a sheet. a couple of TextFields, a couple of buttons. Mouse click, everything works fine. Setting a defaultAction to the button I would like associated with a Return key does not work because the Return is captured by the TextField that has focus. TextField("Name: ", text: $name) TextField("Description:", text: $description) Button("Cancel") { self.isVisible.Toggle() } .keyboardShortcut(.cancelAction) Button("Ok") { self.submit() } .keyboardShortcut(.defaultAction) Manually clicking the Ok button works as expected. Pressing the Enter key never works. So... What am I missing?
1
1
3.9k
Feb ’22