Skip to content

feat(menu): allow for backdrop to be disabled #10070

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

Merged
merged 1 commit into from
Feb 28, 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
11 changes: 11 additions & 0 deletions src/lib/menu/menu-directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ export interface MatMenuDefaultOptions {

/** Class to be applied to the menu's backdrop. */
backdropClass: string;

/** Whether the menu has a backdrop. */
hasBackdrop: boolean;
}

/** Injection token to be used to override the default options for `mat-menu`. */
Expand Down Expand Up @@ -151,6 +154,14 @@ export class MatMenu implements OnInit, AfterContentInit, MatMenuPanel, OnDestro
}
private _overlapTrigger: boolean = this._defaultOptions.overlapTrigger;

/** Whether the menu has a backdrop. */
@Input()
get hasBackdrop(): boolean { return this._hasBackdrop; }
set hasBackdrop(value: boolean) {
this._hasBackdrop = coerceBooleanProperty(value);
}
private _hasBackdrop: boolean = this._defaultOptions.hasBackdrop;

/**
* This method takes classes set on the host mat-menu element and applies them on the
* menu template that displays in the overlay container. Otherwise, it's difficult
Expand Down
1 change: 1 addition & 0 deletions src/lib/menu/menu-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ export interface MatMenuPanel {
setElevation?(depth: number): void;
lazyContent?: MatMenuContent;
backdropClass?: string;
hasBackdrop?: boolean;
}
2 changes: 1 addition & 1 deletion src/lib/menu/menu-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
private _getOverlayConfig(): OverlayConfig {
return new OverlayConfig({
positionStrategy: this._getPosition(),
hasBackdrop: !this.triggersSubmenu(),
hasBackdrop: this.menu.hasBackdrop == null ? !this.triggersSubmenu() : this.menu.hasBackdrop,
backdropClass: this.menu.backdropClass || 'cdk-overlay-transparent-backdrop',
direction: this.dir,
scrollStrategy: this._scrollStrategy()
Expand Down
12 changes: 12 additions & 0 deletions src/lib/menu/menu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ describe('MatMenu', () => {
expect(overlayContainerElement.textContent).toBe('');
}));

it('should be able to remove the backdrop', fakeAsync(() => {
const fixture = TestBed.createComponent(SimpleMenu);
fixture.detectChanges();

fixture.componentInstance.menu.hasBackdrop = false;
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 = TestBed.createComponent(SimpleMenu);
fixture.detectChanges();
Expand Down