question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

mat-menu hides immediately on opening

See original GitHub issue

Bug, feature request, or proposal:

Bug

What is the expected behavior?

mat-menu should stay opened after clicking activating button

What is the current behavior?

menu opens and closes (hides) instantly, keeping overlay active. User must click outside of area that should be covered with menu to deactivate overlay. After that menu opens normally, as it should.

After inspection in chrome developer tools:

Menu is constructed but has styles:

opacity: 0;
transform: scale(0.01, 0.01);

After removing styles , menu shows.

Reverting to version 5.2.4 fixes problem

Problem exists at versions:

  • 6.0.2
  • 6.0.1
  • 6.0.0

Similar issue: https://github.com/angular/material2/issues/10212 https://github.com/angular/material2/issues/11366

What are the steps to reproduce?

//component.html
<div *ngIf="someBoolean">
    <button mat-icon-button [matMenuTriggerFor]="appMenu">
           <mat-icon>more_vert</mat-icon>
    </button>
</div>
<mat-menu #appMenu="matMenu">
             <button mat-menu-item><mat-icon>visibility</mat-icon>Change visibility</button>
            <mat-divider></mat-divider>
            <button mat-menu-item><mat-icon>delete_forever</mat-icon>Delete</button>
</mat-menu>

//component.ts
ngOnInit() {
        
        this.someObservable.pipe(
            take(1),
        ).subscribe((s) => {
            this.someBoolean = true;
            this.change.detectChanges();
        });
}

When variable change and detectChanges() is wrapped inside ngZone, problem disappears.

Fix:

    this.someObservable.pipe(
            take(1),
        ).subscribe((s) => {
           this.zone.run(() => {
                this.someBoolean = true;
                this.change.detectChanges();
           });
        });

What is the use-case or motivation for changing an existing behavior?

To work as predicted

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

user agent:

Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36

ng -v output:

Angular CLI: 6.0.3
Node: 10.1.0
OS: linux x64
Angular: 6.0.2
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.5.13
@angular-devkit/build-angular     0.5.13
@angular-devkit/build-optimizer   0.5.13
@angular-devkit/core              0.5.13
@angular-devkit/schematics        0.6.3
@angular/cdk                      6.0.2
@angular/cli                      6.0.3
@angular/flex-layout              6.0.0-beta.15
@angular/material                 6.0.2
@ngtools/webpack                  6.0.0-rc.11
@schematics/angular               0.6.3
@schematics/update                0.6.3
rxjs                              6.1.0
typescript                        2.7.2
webpack                           4.6.0

Is there anything else we should know?

no

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
bluecaretcommented, May 22, 2018

@kdcro101 Yes wrapping it inside ngZone.run makes it work for me without the need for the polyfill, I don’t really understand the underlying issue here, but this made it work for me so I’m happy 👍

2reactions
kdcro101commented, May 21, 2018

@bluecaret ,

I guess rxjs 6.* transition is work in progress. Does wrapping inside ngZone.run block helps?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to prevent closing of a mat menu which is inside ...
I have a parent wrapper class and child angular material menu button. When I hover outside of the parent class, I need to...
Read more >
<mat-menu> in Angular Material
The <mat-menu> acts as a kind of dropdown or menu section which expands or opens whenever user clicks on any button. Installation syntax:...
Read more >
Angular Material Menu: mat Menu example
How to open mat menu programmatically? Creating dynamic menu list items; mat-menu-item click event. Navigate to an angular route on menu click event....
Read more >
How to Close Dialog when click outside of its region in ...
It can also be closed by clicking outside of the dialog using hide method. ... id="targetButton" (click)="onOpenDialog($event)">Open Dialog</button> <div ...
Read more >
Angular Material Navigation Menu - Complete Responsive ...
Let's start with creating a new routing module: ... <button mat-menu-item (click)="onSidenavClose()">View profile</button>.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found