UIMenuElementAttributesKeepsMenuPresented not working when Glass Grouping changes

I'm working on a UIBarButtonItem that is supposed to be a filter button - it shows a menu in which the user can (un)check menu items. Using the UIMenuElementAttributesKeepsMenuPresented attribute on the UIActions prevents the menu to hide after the user clicks an item.

The button is put alongside another button as the leftBarButtonItems of my navigation item. In iOS 26 they are grouped into a single glass container automatically.

Now when the user starts filtering, I want to highlight the UIBarButton item to signal to the user that the filter is active (similar to what Apple does in the Mail app). I do that by setting the UIBarButtonItemStyle to prominent. Now that works too, but it causes the automatic glass grouping to break up and the menu to hide.

I'm fine with the grouping to break up, but the menu shouldn't hide. Is this a bug or can this be prevented somehow?

Thank you for your post. I am currently attempting to understand the concept you are describing, but I would greatly appreciate it if you could provide a more detailed explanation in a form or a focused sample.

Do you get the same results with just the relevant code in a small test project? If so, please share a link to your test project. That'll help us better understand what's going on. If you're not familiar with preparing a test project, take a look at Creating a test project.

Albert Pascual
  Worldwide Developer Relations.

Thanks for your response. You can find an example project here (https://1drv.ms/u/c/9ff2ada21b6e758d/EchgHRMV9CpPhDWa5H3qQI8Bca72rFWsDCXVrTLnVAKEGw?e=HMiScu) or see the example code below. As you can see, the menu collapses when clicking the "Only favorites" menu action, even though .keepsMenuPresented is provided

final class FiltersVC: UIViewController {

    lazy var barItem = UIBarButtonItem(image: UIImage(systemName: "line.3.horizontal.decrease"), menu: makeFilterMenu())
    private var isFilterActive = false

    override func viewDidLoad() {
        super.viewDidLoad()

        let other = UIBarButtonItem(systemItem: .add, primaryAction: UIAction { _ in })
        navigationItem.leftBarButtonItems = [barItem, other] // if we only had one bar button item, the menu would not collapse after clicking "Only favorites"
    }

    private func makeFilterMenu() -> UIMenu {
        let a1 = UIAction(title: "Only favorites", attributes: [.keepsMenuPresented], state: isFilterActive ? .on : .off) { [weak self] action in
            guard let self = self else { return }
            isFilterActive = !isFilterActive;
            barItem.style = isFilterActive ? .prominent : .plain // this causes the menu to collapse despite .keepsMenuPresented
            barItem.menu = makeFilterMenu()
        }
        let a2 = UIAction(title: "Some other action") { _ in }

        return UIMenu(title: "Filter", options: [.displayInline], children: [a1, a2])
    }
}
UIMenuElementAttributesKeepsMenuPresented not working when Glass Grouping changes
 
 
Q