NSToolbar doesn't restore displayMode when NSWindow.titleVisibility = .hidden

Apparently when setting a window to hide its title, the toolbar's displayMode is not restored when relaunching the app. For example, by default my app sets to show toolbar icons only, but when right-clicking it, selecting "Icon and Text" and relaunching the app, it's again "Icon Only".

Is there a workaround? I've filed FB17144212.

class ViewController: NSViewController, NSToolbarDelegate {

    override func viewDidAppear() {
        let toolbar = NSToolbar(identifier: "toolbar")
        toolbar.delegate = self
        toolbar.autosavesConfiguration = true
        toolbar.displayMode = .iconOnly
        view.window?.titleVisibility = .hidden
        view.window?.toolbar = toolbar
        view.window?.toolbarStyle = .unified
    }
    
    func toolbarAllowedItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
        return [.init(rawValue: "item")]
    }
    
    func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
        return [.init(rawValue: "item")]
    }
    
    func toolbar(_ toolbar: NSToolbar, itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier, willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem? {
        let item = NSToolbarItem(itemIdentifier: itemIdentifier)
        item.image = NSImage(named: NSImage.addTemplateName)!
        item.label = "item"
        return item
    }

}
Answered by Nickkk in 852790022

This has been fixed in macOS 26 Beta 2.

Thanks for filling the bug report. The engineering teams is investigating this issue and would let you know via the Feedback report if there's a supported workaround

Accepted Answer

This has been fixed in macOS 26 Beta 2.

NSToolbar doesn't restore displayMode when NSWindow.titleVisibility = .hidden
 
 
Q