Hide toolbar command not working

View > Hide Toolbar command selected in a context me

I’ve been trying to fix the “Hide Toolbar” command in my SwiftUI macOS project. Hide Toolbar is one of my favourite keyboard shortcuts and I use it regularly to use screen space more effectively. Naturally, I want this macOS feature to work in my app. The keyboard shortcut didn’t work in my project. If you facing the same issue, check these two tips.

First, assign id to the toolbar view modifier and every child item. Example below.

.toolbar(id: "editor-toolbar") {
	ToolbarItem(id: "new-note") {
		Button {
			// do something
		}
		.help("New note")
	}
}

Second, remove Divider() from your toolbar’s view.

These two tips fix the hide command but also make the toolbar customisable.

Strangely, activating the command with the mouse was working. With the keyboard shortcut, the menu gets highlighted but it didn’t work. Searching the web for a solution gave me no results. I want to share this with the internet because there has to be someone facing similar roadblocks.

I have found a a working code example in one of my other projects. At that project I experienced a a different issue, this time it greyed out the “Customize Toolbar…” command. By finding a solution for the command, I have fixed the hide command as well.

This post wouldn’t be possible without the work which went into LinkEdit. It describes one of the many features and improvements included in recent 1.3 major update.