macOS is not rendering a toolbar that has only one toolbar item with the primaryAction placement. This only happens when presented as a sheet.
The toolbar renders as expected when displayed in a NavigationStack.
If I add additional buttons then the toolbar is rendered as expected when presented in a sheet.
Is this the expected behavior?
In my case I found this issue because I conditionally compile additional buttons for other platforms while macOS only had one relevant button.
Toolbar in sheet (only primaryAction)
Toolbar in sheet (two buttons with placement)
Toolbar in navigation stack (only primaryAction)
Code for the view
struct OneButtonWithPlacement: View {
@Environment(\.dismiss) var dismiss
var body: some View {
NavigationStack {
VStack {
Color.red
.frame(height: 300)
}
.toolbar {
ToolbarItem(placement: .primaryAction) {
Button {
dismiss()
}
label: {
Label("ok", systemImage: "checkmark")
}
}
}
}
}
}