From 7e1e6a533a390cdc65d34a4ccdff26f965e0a47b Mon Sep 17 00:00:00 2001 From: sbarfurth Date: Tue, 29 Aug 2023 19:26:35 +0200 Subject: [PATCH] fix(cdk/menu): run change detection for changes to overlay ref of trigger 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 #27725 --- src/cdk/menu/menu-trigger.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cdk/menu/menu-trigger.ts b/src/cdk/menu/menu-trigger.ts index c2e418b43204..2774491f4f9a 100644 --- a/src/cdk/menu/menu-trigger.ts +++ b/src/cdk/menu/menu-trigger.ts @@ -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 { @@ -70,6 +70,7 @@ export class CdkMenuTrigger extends CdkMenuTriggerBase implements OnDestroy { private readonly _elementRef: ElementRef = 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}); @@ -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(); } } @@ -111,6 +113,7 @@ export class CdkMenuTrigger extends CdkMenuTriggerBase implements OnDestroy { this.closed.next(); this.overlayRef!.detach(); + this._changeDetectorRef.markForCheck(); } this._closeSiblingTriggers(); }