My code:
Button(action: {
AudioServicesPlaySystemSound(1026)
isActive.toggle()
}){
HStack{
Image(systemName: "trash")
Text("delete")
}
}
.foregroundColor(.red)
.font(.body)
.keyboardShortcut("b",modifiers: [])
in this stage keyboardShortcut is working but when I add buttonStyle keyboardShortcut is not working code with buttonStyle:
Button(action: {
AudioServicesPlaySystemSound(1026)
isActive.toggle()
}){
HStack{
Image(systemName: "trash")
Text("delete")
}
}
.buttonStyle(PlainButtonStyle())
.foregroundColor(.red)
.font(.body)
.keyboardShortcut("b",modifiers: [])
works well for me on macos 12.beta, xcode 13.beta, target ios 14.7 and MacCatalyst 12. Tested on macOS 12 MacCatalyst app. What system are you using?
import SwiftUI
@main
struct TestApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
struct ContentView: View {
var body: some View {
Button(action: {
print("---> button clicked")
}) {
HStack{
Image(systemName: "trash")
Text("delete")
}
}
.buttonStyle(PlainButtonStyle())
.foregroundColor(.red)
.font(.body)
.keyboardShortcut("b",modifiers: [])
}
}