fix(menu): hasBackdrop not being updated after first open (#14561)

Fixes changing the `hasBackdrop` value not having an effect if it happens after the first time a menu is opened.

Fixes #14560.
This commit is contained in:
Kristiyan Kostadinov
2018-12-19 16:14:52 +01:00
committed by Jeremy Elbourn
parent 2463200324
commit 268b0e8f13
2 changed files with 32 additions and 2 deletions
+5 -2
View File
@@ -226,7 +226,11 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
this._checkMenu();
const overlayRef = this._createOverlay();
this._setPosition(overlayRef.getConfig().positionStrategy as FlexibleConnectedPositionStrategy);
const overlayConfig = overlayRef.getConfig();
this._setPosition(overlayConfig.positionStrategy as FlexibleConnectedPositionStrategy);
overlayConfig.hasBackdrop = this.menu.hasBackdrop == null ? !this.triggersSubmenu() :
this.menu.hasBackdrop;
overlayRef.attach(this._getPortal());
if (this.menu.lazyContent) {
@@ -394,7 +398,6 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
.flexibleConnectedTo(this._element)
.withLockedPosition()
.withTransformOriginOn('.mat-menu-panel'),
hasBackdrop: this.menu.hasBackdrop == null ? !this.triggersSubmenu() : this.menu.hasBackdrop,
backdropClass: this.menu.backdropClass || 'cdk-overlay-transparent-backdrop',
scrollStrategy: this._scrollStrategy(),
direction: this._dir
+27
View File
@@ -114,6 +114,33 @@ describe('MatMenu', () => {
expect(overlayContainerElement.querySelector('.cdk-overlay-backdrop')).toBeFalsy();
}));
it('should be able to remove the backdrop on repeat openings', fakeAsync(() => {
const fixture = createComponent(SimpleMenu, [], [FakeIcon]);
fixture.detectChanges();
fixture.componentInstance.trigger.openMenu();
fixture.detectChanges();
tick(500);
// Start off with a backdrop.
expect(overlayContainerElement.querySelector('.cdk-overlay-backdrop')).toBeTruthy();
fixture.componentInstance.trigger.closeMenu();
fixture.detectChanges();
tick(500);
// Change `hasBackdrop` after the first open.
fixture.componentInstance.menu.hasBackdrop = false;
fixture.detectChanges();
// Reopen the menu.
fixture.componentInstance.trigger.openMenu();
fixture.detectChanges();
tick(500);
expect(overlayContainerElement.querySelector('.cdk-overlay-backdrop')).toBeFalsy();
}));
it('should restore focus to the trigger when the menu was opened by keyboard', fakeAsync(() => {
const fixture = createComponent(SimpleMenu, [], [FakeIcon]);
fixture.detectChanges();