Skip to content
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
2 changes: 1 addition & 1 deletion src/lib/sidenav/drawer-container.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="mat-drawer-backdrop" (click)="_onBackdropClicked()"
<div class="mat-drawer-backdrop" (click)="_onBackdropClicked()" *ngIf="hasBackdrop"
[class.mat-drawer-shown]="_isShowingBackdrop()"></div>

<ng-content select="mat-drawer"></ng-content>
Expand Down
18 changes: 16 additions & 2 deletions src/lib/sidenav/drawer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ describe('MatDrawerContainer', () => {
DrawerSetToOpenedTrue,
DrawerContainerStateChangesTestApp,
AutosizeDrawer,
BasicTestApp,
],
});

Expand Down Expand Up @@ -630,6 +631,18 @@ describe('MatDrawerContainer', () => {
discardPeriodicTasks();
}));

it('should be able to toggle whether the container has a backdrop', fakeAsync(() => {
const fixture = TestBed.createComponent(BasicTestApp);
fixture.detectChanges();

expect(fixture.nativeElement.querySelector('.mat-drawer-backdrop')).toBeTruthy();

fixture.componentInstance.hasBackdrop = false;
fixture.detectChanges();

expect(fixture.nativeElement.querySelector('.mat-drawer-backdrop')).toBeFalsy();
}));

});


Expand All @@ -652,13 +665,13 @@ class DrawerContainerTwoDrawerTestApp {
/** Test component that contains an MatDrawerContainer and one MatDrawer. */
@Component({
template: `
<mat-drawer-container (backdropClick)="backdropClicked()">
<mat-drawer-container (backdropClick)="backdropClicked()" [hasBackdrop]="hasBackdrop">
<mat-drawer #drawer position="start"
(opened)="open()"
(openedStart)="openStart()"
(closed)="close()"
(closedStart)="closeStart()">
<button #drawerButton>Content.</button>
<button #drawerButton>Content</button>
</mat-drawer>
<button (click)="drawer.open()" class="open" #openButton></button>
<button (click)="drawer.close()" class="close" #closeButton></button>
Expand All @@ -670,6 +683,7 @@ class BasicTestApp {
closeCount = 0;
closeStartCount = 0;
backdropClickedCount = 0;
hasBackdrop = true;

@ViewChild('drawerButton') drawerButton: ElementRef;
@ViewChild('openButton') openButton: ElementRef;
Expand Down
14 changes: 14 additions & 0 deletions src/lib/sidenav/drawer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,20 @@ export class MatDrawerContainer implements AfterContentInit, OnDestroy {
set autosize(value: boolean) { this._autosize = coerceBooleanProperty(value); }
private _autosize: boolean;

/** Whether the drawer container should have a backdrop while one of the sidenavs is open. */
@Input()
get hasBackdrop() {
if (this._hasBackdrop == null) {
return !this._start || this._start.mode !== 'side' || !this._end || this._end.mode !== 'side';
}

return this._hasBackdrop;
}
set hasBackdrop(value: any) {
this._hasBackdrop = value == null ? null : coerceBooleanProperty(value);
}
private _hasBackdrop: boolean | null;

/** Event emitted when the drawer backdrop is clicked. */
@Output() readonly backdropClick = new EventEmitter<void>();

Expand Down
2 changes: 1 addition & 1 deletion src/lib/sidenav/sidenav-container.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="mat-drawer-backdrop" (click)="_onBackdropClicked()"
<div class="mat-drawer-backdrop" (click)="_onBackdropClicked()" *ngIf="hasBackdrop"
[class.mat-drawer-shown]="_isShowingBackdrop()"></div>

<ng-content select="mat-sidenav"></ng-content>
Expand Down