Skip to content

fix(macos): respect disabled state for menu items#46

Merged
lijy91 merged 1 commit into
mainfrom
fix/macos-disable-menu-item
May 30, 2026
Merged

fix(macos): respect disabled state for menu items#46
lijy91 merged 1 commit into
mainfrom
fix/macos-disable-menu-item

Conversation

@lijy91
Copy link
Copy Markdown
Member

@lijy91 lijy91 commented May 30, 2026

Problem

When calling MenuItem::SetEnabled(false) on macOS, the disabled menu item remains clickable. This happens because:

  1. NSMenu has autoenablesItems enabled by default, which overrides explicit setEnabled: calls during menu validation.
  2. The menuItemClicked: handler did not check the item's enabled state.

Changes

  • Set autoenablesItems = NO on NSMenu so that explicitly set enabled states are always respected.
  • Add isEnabled check in menuItemClicked: callback as an extra safety net — if AppKit still sends the action for a disabled item, the handler ignores it.
  • Implement menu:validateMenuItem: in NSMenuDelegateImpl to return the item's actual isEnabled state.

Testing

Verified that a disabled menu item now appears grayed out and does not fire MenuItemClickedEvent when clicked.

- Set autoenablesItems=NO on NSMenu so explicit setEnabled: calls
  are not overridden by AppKit's auto-validation.
- Add isEnabled check in menuItemClicked: as an extra safety net
  to ignore clicks on disabled items.
- Implement menu:validateMenuItem: on NSMenuDelegateImpl to return
  the item's actual isEnabled state.
@lijy91 lijy91 merged commit fa9c8ef into main May 30, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant