ToolbarItemGroup(placement: .keyboard) is not showed with Sheet

struct ContentView: View {
  @State var isPresented = false

  var body: some View {
    Button {
      isPresented.toggle()
    } label: {
      Text("Button")
    }
    .sheet(isPresented: $isPresented) {
      SubView()
    }
  }
}

struct SubView: View {
  @State var text = ""

  var body: some View {
    NavigationStack {
      TextEditor(text: $text)
        .toolbar {
          ToolbarItemGroup(placement: .bottomBar) {
            Button("Click") {
            }
          }
          ToolbarItemGroup(placement: .keyboard) {
            Button("Click") {
            }
          }
        }
    }
  }
}

Accepted Reply

This bug is fixed in iOS 16 beta 5.

  • I'm seeing a similar issue with iOS 17.0.3 where the bar sometimes shows if you kind of quit the app while the keyboard is there (like while taking a screen shot to fill a bug report) then when you come back to the app the bar suddenly appears.

Add a Comment

Replies

I'm seeing this exact same issue. I haven't had success getting this to run at all. And its in a NavigationStack/View which has always been the "you need to do this first" thing that everyone responds to on stack overflow.

Its broken as far as I can tell

Is this bug or problem?

This bug is fixed in iOS 16 beta 5.

  • I'm seeing a similar issue with iOS 17.0.3 where the bar sometimes shows if you kind of quit the app while the keyboard is there (like while taking a screen shot to fill a bug report) then when you come back to the app the bar suddenly appears.

Add a Comment

Looks like the bug is back in iOS17. See the code below. When you start the app and show the fullScreenCover, it works as expected. However if you show the sheet, the keyboard button does not show anymore. And it will not show even in fullScreenCover until you restart the app.

struct ContentView: View {
    
    @State var isSheetPresented = false
    @State var isCoverPresented = false
    
    var body: some View {
        VStack {
            Button("Show sheet (not working)") { isSheetPresented = true }
            Button("Show cover (working)") { isCoverPresented = true }
        }
        .sheet(isPresented: $isSheetPresented) { SubView(isPresented: $isSheetPresented) }
        .fullScreenCover(isPresented: $isCoverPresented) { SubView(isPresented: $isCoverPresented) }
    }
}

struct SubView: View {
    
    @State var text = ""
    @Binding var isPresented: Bool
    
    var body: some View {
        NavigationView {
            TextField("Text here...", text: $text)
                .toolbar {
                    ToolbarItemGroup(placement: .topBarTrailing) {
                        Button("Dismiss") {
                            isPresented = false
                        }
                    }
                    ToolbarItemGroup(placement: .keyboard) {
                        Button("Keyboard button") {
                            print("keyboard button pressed")
                        }
                    }
                }
        }
    }
}
  • @mihai-moldovan , some other people have reported the same issue recently on the forums as well, thanks for bringing it to attention. If you can file a bug report at https://feedbackassistant.apple.com and post the FB number here, that would help a lot!

  • I'm having the same issue as @mihai-moldovan, I'm also interested by a fix !

  • Seems like a fix is on the road : just tested the above example with the latest iOS 17.1 Beta 3 (public), and now the bug is reversed : -> it works with the "sheet" case -> it doesn't work with the "fullSheetCover" case… At least we're making (some) progress… Do you confirm ?

Add a Comment

hi,

i'm getting something similar in behavior related to toolbar items for the keyboard, although it's not exactly the same. (i am using Xcode 15 official release, not a beta or the RC.)

in my case, i have a view that can be shown either by navigating to it, or opening it in a sheet (wrapped inside a navigationStack).

  • when the view is navigated to, the button i place on the keyboard (to dismiss the keyboard) works as expected.
  • when the view is opened in a sheet (view is wrapped inside a navigationStack), the button does indeed appear, but it is disabled.

i'll try to put together a minimal example to file a feedback, but i'll be curious to see if there are more reports.

DMG

  • looks like my minimal example actually now has exactly the issue above: works fine when navigated to, but doesn't show the button when presented in a sheet. tried to file a feedback, but Feedback Assistant crashed (really!). not a good day so far.

Add a Comment

Same here with ToolbarItem(placement: .keyboard). It does not work anymore since iOS 17

Seems to work on device not on simulator (xcode 15.0.1) iOS 17.0.1

Xcode Version 15.2 (15C500b)

Here's the weird thing, it ONLY works if the sheet or parent view that opens the sheet is within a NavigationStack.

For example, this code fails to show the Keyboard button UNLESS you comment out one of those NavigationStacks:

struct ContentView: View {
    @State var isPresented = false
    
    var body: some View {
//        NavigationStack { // Works
            Button {
                isPresented.toggle()
            } label: {
                Text("Button")
            }
            .sheet(isPresented: $isPresented) {
                SubView()
        }
//        }
    }
}

struct SubView: View {
    @State var text = ""
    
    var body: some View {
//        NavigationStack { // Works
            TextEditor(text: $text)
                .toolbar {
                    ToolbarItemGroup(placement: .bottomBar) {
                        Button("Bottom Bar") {
                        }
                    }
                    ToolbarItemGroup(placement: .keyboard) {
                        NavigationStack {
                            Button("Keyboard") {
                            }
                        }
                    }
                }
//        }
    }
}

FB13532834 Keyboard toolbar button does not display within sheet

It's back on Xcode 15.4