ARTICLE AD BOX
I'm building a Mac Catalyst app using SwiftUI. I have a .keyboardShortcut modifier on a Button inside a Sheet. The shortcut works fine in most cases, but fails silently when the sheet is presented from a view that is wrapped in any container (ZStack, VStack, etc.) inside the detail column of a NavigationSplitView.
@main struct TestApp: App { @State private var page: Int = 0 var body: some Scene { WindowGroup { NavigationSplitView { List { Button("Settings") { page = 0 } } } detail: { //PageA() // ✅ Shortcut works PageB() // ❌ Shortcut does NOT work //PageC() // ❌ Shortcut does NOT work } } } } struct PageA: View { var body: some View { ShortcutView() // Direct child — works } } struct PageB: View { var body: some View { ZStack { ShortcutView() // Wrapped in ZStack — broken } } } struct PageC: View { var body: some View { VStack { ShortcutView() // Wrapped in VStack — broken } } } struct ShortcutView: View { @State private var isPresented = false var body: some View { Button("Present") { isPresented.toggle() } .sheet(isPresented: $isPresented) { Button("Do something") { print("pressed") } .keyboardShortcut("s", modifiers: .command) .interactiveDismissDisabled() } } }Why does adding a single ZStack or VStack wrapper in the NavigationSplitView detail break .keyboardShortcut inside a presented sheet?
Is there a reliable way to register keyboard shortcuts in a SwiftUI sheet on Mac Catalyst that works regardless of the presenter's view hierarchy depth and regardless of which view inside the sheet is currently first responder?
19.1k25 gold badges113 silver badges268 bronze badges
2
Explore related questions
See similar questions with these tags.
