Fix MacOS select popup with empty selection
Minor
Commit Hash:
acca2bd05fcaf495a4e328f828f11cfa008e25a0
Commit Time: 2026-01-30 21:55:27+00:00
Impact Level: Minor
Generated By: webview2-upstream-sentry
Upstream Review:
View Upstream Review 🔗
📋 Summary
This commit fixes the display issue with macOS select popups when no option is selected. It modifies the option selection logic in the -runMenuInView:withBounds:initialIndex: method of the WebMenuRunner class. When index is -1 (indicating no selection), the original code would use [cell selectItemWithTag:index], which caused the first menu item to appear as checked. After the change, when index > -1, selectItemWithTag: is called normally, and when index is -1, [cell selectItemAtIndex:-1] is explicitly called to deselect all options, ensuring that no item is marked as checked when the menu opens.
🎯 Impact Analysis
The impact of this change on WebView2Mac is minor. The WebMenuRunner class is an implementation class in the content/app_shim_remote_cocoa module used for handling native menu display of web form elements (select dropdowns). This class is not part of the core remote_cocoa interfaces that WebView2Mac directly depends on (such as NativeWidgetNSWindowBridge, Application Mojo interfaces, etc.), but is specifically used for rendering native menus for HTML select elements.
When WebView2Mac embeds web content through the Remote Cocoa mechanism, it does utilize this class to display dropdown menus in web pages. This fix improves user experience by ensuring that when a web page's select element has no default selected item, the native menu correctly displays with no selection, rather than incorrectly showing the first item as checked. This is a behavioral fix that does not involve interface changes, class inheritance modifications, or architectural adjustments, so it will not affect WebView2Mac's compilation or integration approach.
This change enhances the display accuracy of web form controls in WebView2Mac, making their behavior consistent with expectations. It is a functional improvement rather than a breaking change.
When WebView2Mac embeds web content through the Remote Cocoa mechanism, it does utilize this class to display dropdown menus in web pages. This fix improves user experience by ensuring that when a web page's select element has no default selected item, the native menu correctly displays with no selection, rather than incorrectly showing the first item as checked. This is a behavioral fix that does not involve interface changes, class inheritance modifications, or architectural adjustments, so it will not affect WebView2Mac's compilation or integration approach.
This change enhances the display accuracy of web form controls in WebView2Mac, making their behavior consistent with expectations. It is a functional improvement rather than a breaking change.
Impacted Classes:
WebMenuRunner
NSPopUpButtonCell (AppKit)