Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Dec 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/lib/menu/menu-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions src/lib/menu/menu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down