Wednesday, November 15, 2023

Search Suggestion Menus in AppKit

John Brayton:

Even though Safari, Mail, and Finder implement search suggestion menus, there is no standard AppKit mechanism for providing them in AppKit. Popping up an NSMenu does not work because the search field cannot receive keystrokes while the menu is displayed.

Interestingly there is a good mechanism for providing search suggestion menus in SwiftUI, but incorporating that mechanism into an AppKit-based application looks much more difficult than just using an NSHostingView.

I ended up starting with a CustomMenus sample project. This 2018 project by Doug Stein is a Swift port of Apple Objective-C sample code from 2012.

2 Comments RSS · Twitter · Mastodon

I have created a pop up button with a search functionality that might be useful for Mac developers:

https://github.com/LeoNatan/LNSearchablePopUpButton

It supports filtering within a static list of results, a dynamic one (developer provides results and tells it when the search is done) or a combination of the two.

iTerm2 has a search popup on its settings pane and its source code would probably be a reference to implement a similar control.

Leave a Comment