Skip to content

Commit

Permalink
fix(cdk/menu): run change detection for changes to overlay ref of tri…
Browse files Browse the repository at this point in the history
…gger

Fixes an issue where menu triggers placed inside components using OnPush change detection
would not have their `aria-expanded` property updated correctly when switching between
sibling triggers.

Fixes angular#27725
  • Loading branch information
sbarfurth committed Aug 29, 2023
1 parent b6cbba7 commit 7e1e6a5
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/cdk/menu/menu-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Directive, ElementRef, inject, NgZone, OnDestroy} from '@angular/core';
import {ChangeDetectorRef, Directive, ElementRef, inject, NgZone, OnDestroy} from '@angular/core';
import {InputModalityDetector} from '@angular/cdk/a11y';
import {Directionality} from '@angular/cdk/bidi';
import {
Expand Down Expand Up @@ -70,6 +70,7 @@ export class CdkMenuTrigger extends CdkMenuTriggerBase implements OnDestroy {
private readonly _elementRef: ElementRef<HTMLElement> = inject(ElementRef);
private readonly _overlay = inject(Overlay);
private readonly _ngZone = inject(NgZone);
private readonly _changeDetectorRef = inject(ChangeDetectorRef);
private readonly _inputModalityDetector = inject(InputModalityDetector);
private readonly _directionality = inject(Directionality, {optional: true});

Expand Down Expand Up @@ -101,6 +102,7 @@ export class CdkMenuTrigger extends CdkMenuTriggerBase implements OnDestroy {

this.overlayRef = this.overlayRef || this._overlay.create(this._getOverlayConfig());
this.overlayRef.attach(this.getMenuContentPortal());
this._changeDetectorRef.markForCheck();
this._subscribeToOutsideClicks();
}
}
Expand All @@ -111,6 +113,7 @@ export class CdkMenuTrigger extends CdkMenuTriggerBase implements OnDestroy {
this.closed.next();

this.overlayRef!.detach();
this._changeDetectorRef.markForCheck();
}
this._closeSiblingTriggers();
}
Expand Down

0 comments on commit 7e1e6a5

Please sign in to comment.