Error should not occur
Repeatedly and quickly clicking on menu trigger button causes error
StackBlitz
Click on menuTrigger repeatedly -> error shows in console
Angular 7.1.0
Angular Material 7.1.0
Chrome Browser
ChangeDetection: OnPush
ERROR
Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'aria-expanded: true'. Current value: 'aria-expanded: null'.
I am seeing this error happening as well. Any word on a fix?
Same error here with 7.2.2 and 7.3.0 . Does not happen when being outside a *ngFor but inside I'm reliably able to reproduce the issue.
Still an issue with 8.0.0.
Here is a workaround that fixed it for me: use the menuOpened and menuClosed Output
s to set the disabled
property of the trigger.
<button
#menuTrigger
[matMenuTriggerFor]="addContactButton"
(menuOpened)="menuTrigger.disabled = true"
(menuClosed)="menuTrigger.disabled = false"
i18n>+ Add New</button>
Here is a workaround that fixed it for me: use the menuOpened and menuClosed
Output
s to set thedisabled
property of the trigger.<button #menuTrigger [matMenuTriggerFor]="addContactButton" (menuOpened)="menuTrigger.disabled = true" (menuClosed)="menuTrigger.disabled = false" i18n>+ Add New</button>
Actually, you just have to subscribe to menuClosed EventEmitter to get it "fixed", at least in my case.
<button #menuTrigger [matMenuTriggerFor]="menu" (menuClosed)="(true)">+</button>
Not sure why because if I subscribe directly to menuClosed in MatMenuTrigger directive I still have this issue.
Here is a workaround that fixed it for me: use the menuOpened and menuClosed
Output
s to set thedisabled
property of the trigger.<button #menuTrigger [matMenuTriggerFor]="addContactButton" (menuOpened)="menuTrigger.disabled = true" (menuClosed)="menuTrigger.disabled = false" i18n>+ Add New</button>
Actually, you just have to subscribe to menuClosed EventEmitter to get it "fixed", at least in my case.
<button #menuTrigger [matMenuTriggerFor]="menu" (menuClosed)="(true)">+</button>
Not sure why because if I subscribe directly to menuClosed in MatMenuTrigger directive I still have this issue.
Works for me
Angular 8.2.11
Angular Material 8.2.3
is there a solution to this that isn't an ugly workaround?
I need aria-expanded=false when menu is not opened. What is the fix for this?
When matMenuTrigger is used in component with OnPush change detection strategy then aria-expanded is not changing. I suppose it is caused because menu trigger has default change detection strategy.
Quick workaround to trigger change detection
<button
[matMenuTriggerFor]="menu"
(menuClosed)="(true)"
>
Most helpful comment
Here is a workaround that fixed it for me: use the menuOpened and menuClosed
Output
s to set thedisabled
property of the trigger.