Description
Is this a regression?
No.
The previous version in which this bug was not present was
Unknown.
Description
MenuPanels cannot be closed when they do not have an active trigger set.
A scenario where unsetting the trigger during runtime may be wanted is when the button is meant to open a context menu or a bottom sheet depending on the size of the viewport and so needs to switch between a click handler (that opens a bottom sheet) or a matMenu Trigger that opens a menu panel during runtime. An example application has been setup for such a scenario (without the click handler, just temporarily setting the menu trigger to null during runtime)
Reproduction
StackBlitz link: https://stackblitz.com/edit/ku1ehf?file=src%2Fexample%2Fmenu-icons-example.html
Steps to reproduce:
- Downsize the window width until the button text says "has Trigger" (less than 600px)
- Hit the button
- The MatMenuPanel should be open now showing some dummy options - do not click anything
- Now upsize the window width until the button says "no Trigger" - ensure that the menu panel remains open during that time
- Try clicking a menu option or anywhere in the app window that would normally close the MatMenuPanel
Expected Behavior
The menu panel closes when an option is selected or anywhere within the app window outside the menu panel is clicked.
Actual Behavior
When the trigger to open the menu is lost - the menu panel can no longer close until it regains a trigger.
Environment
- Angular: 19.0.1
- CDK/Material: 19.0.1
- Browser(s): Chromium
- Operating System (e.g. Windows, macOS, Ubuntu): Unrelated.