Using NSMenuItem's delegate method menu(_ menu: NSMenu, willHighlight item: NSMenuItem?)
should return a nil item when the mouse location is moved out of the NSMenu window or if any of the items should not be highlighted. As per Apple Developer website:
Only one item per menu can be highlighted at a time. If item is nil, it means that all items in the menu are about to be unhighlighted.
But, on macOS Sonoma, when moving the mouse over a .sectionHeader and/or a Separator item, willHighlight
won't be called, which makes it not return any item (neither nil, nor the section header).
This behavior makes it impossible to use willHighlight
method to determine whether custom views should be highlighted or not.
Is this a bug or expected behavior?