Skip to content

bug(Menu): fix menu panels not closing when no trigger is present #30139

Open
@SeraphCoding

Description

@SeraphCoding

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:

  1. Downsize the window width until the button text says "has Trigger" (less than 600px)
  2. Hit the button
  3. The MatMenuPanel should be open now showing some dummy options - do not click anything
  4. Now upsize the window width until the button says "no Trigger" - ensure that the menu panel remains open during that time
  5. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4A relatively minor issue that is not relevant to core functionsarea: material/menu

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions