In following code example:
struct ContentView: View {
@State var text: String = "sample text"
var body: some View {
VStack {
TextField("", text: $text)
Button(action: { print("action performed!") }) {
Text("Click me")
}
.keyboardShortcut(.defaultAction)
}
.padding(40)
}
}
.keyboardShortcut(.defaultAction)
that is attached to Button perfectly works on macOs Big Sur(11.6) and I see "action performed!" in Xcode console when tap Enter key on keyboard.
Unfortunately, same example doesn't work on macOs Monterey(12.0.1) and Xcode 13.1. So nothing happens(I don't see any logs) when I tap Enter key on keyboard. Also I noticed that it happens only when focus is set in TextField.
I checked that onSubmit can solve this issue. Unfortunately, I can't use since it's available in macOs 12 or newer but my App has deployment target is macOs 11.
So any workarounds are welcomed.