How to setup toolbar for sheets in SwiftUI on macOS?

I’d like to know, how I can setup a toolbar inside a sheet using SwiftUI on macOS.

I tried adding a NavigationView and used the following Code, but the top area of the sheet is always empty.

Code Block
.toolbar {
                ToolbarItem(placement: .confirmationAction) {
                    Button(action: {
//                      Do stuff
                        self.presentationMode.wrappedValue.dismiss()
                    }
                    ) {
                        Label("Done", systemImage: "checkmark.fill")
                    }
                }
                ToolbarItem(placement: .cancellationAction) {
                    Button(action: {
                        self.presentationMode.wrappedValue.dismiss()
                    }
                    ) {
                        Label("Cancel", systemImage: "checkmark.fill")
                    }
                }
            }


Post not yet marked as solved Up vote post of Apple_Kevin Down vote post of Apple_Kevin
3.5k views

Replies

I have submitted a feedback issue over this. I don't believe it's currently working as expected. The same is true when assigning toolbar items to a sheet on iOS as well. Only automatic and bottomBar seem to work there.
Adding ToolbarItems to iOS sheets actually works, if you put the content of the sheet inside a NavigationView. But shouldn't be like that.
  • This bug still persists today, though I'm glad to see that wrapping my sheet view in a NavigationView works in the mean time.

Add a Comment
The issue is resolved in 11.1
  • In Xcode 13, toolbar seems to be not be working in a sheet view with ToolbarItemGroup(placement: .keyboard) :(

Add a Comment

I'm still hitting this problem on MacOS / Xcode 14.3. More specifically, bottom bar items appear (.primaryAction, .secondaryAction, .automatic), but items such as .navigation and .principal don't.

And yes, this is all within a NavigationStack.