Skip to content

Commit d8a9818

Browse files
committed
fix(menu): update classlist when repositioning occurs due to scroll
1 parent c088a0f commit d8a9818

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

src/demo-app/menu/menu-demo.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,5 @@
167167
</mat-menu>
168168
</div>
169169
</div>
170+
171+
<div style="height: 500px">This div is for testing scrolled menus.</div>

src/demo-app/menu/menu-demo.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
}
99

1010
.end-icon {
11-
align-items: flex-end;
11+
justify-content: flex-end;
1212
}
1313
}

src/lib/menu/menu-trigger.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
Inject,
3030
InjectionToken,
3131
Input,
32+
NgZone,
3233
OnDestroy,
3334
Optional,
3435
Output,
@@ -127,6 +128,7 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
127128
constructor(private _overlay: Overlay,
128129
private _element: ElementRef,
129130
private _viewContainerRef: ViewContainerRef,
131+
private _ngZone: NgZone,
130132
@Inject(MAT_MENU_SCROLL_STRATEGY) private _scrollStrategy,
131133
@Optional() private _parentMenu: MatMenu,
132134
@Optional() @Self() private _menuItemInstance: MatMenuItem,
@@ -341,7 +343,8 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
341343
const posX: MenuPositionX = change.connectionPair.overlayX === 'start' ? 'after' : 'before';
342344
const posY: MenuPositionY = change.connectionPair.overlayY === 'top' ? 'below' : 'above';
343345

344-
this.menu.setPositionClasses(posX, posY);
346+
// Note that the position changes may be outside the Angular zone
347+
this._ngZone.run(() => this.menu.setPositionClasses(posX, posY));
345348
});
346349
}
347350

0 commit comments

Comments
 (0)