Skip to content

Commit 1de1b98

Browse files
crisbetommalerba
authored andcommitted
fix(sidenav): avoid CSS class name conflict (#16798)
Currently both the drawer and drawer container use a class called `mat-drawer-opened` which can cause confusion. These changes rename the class on the container.
1 parent 0a16e04 commit 1de1b98

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/material/sidenav/drawer.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ $mat-drawer-over-drawer-z-index: 4;
4040
&[fullscreen] {
4141
@include mat-fill();
4242

43-
&.mat-drawer-opened {
43+
&.mat-drawer-container-has-open {
4444
overflow: hidden;
4545
}
4646
}

src/material/sidenav/drawer.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ describe('MatDrawer', () => {
5252

5353
expect(testComponent.openCount).toBe(0);
5454
expect(testComponent.openStartCount).toBe(0);
55-
expect(container.classList).not.toContain('mat-drawer-opened');
55+
expect(container.classList).not.toContain('mat-drawer-container-has-open');
5656

5757
tick();
5858
expect(testComponent.openStartCount).toBe(1);
5959
fixture.detectChanges();
6060

6161
expect(testComponent.openCount).toBe(1);
6262
expect(testComponent.openStartCount).toBe(1);
63-
expect(container.classList).toContain('mat-drawer-opened');
63+
expect(container.classList).toContain('mat-drawer-container-has-open');
6464
}));
6565

6666
it('should be able to close', fakeAsync(() => {
@@ -80,15 +80,15 @@ describe('MatDrawer', () => {
8080

8181
expect(testComponent.closeCount).toBe(0);
8282
expect(testComponent.closeStartCount).toBe(0);
83-
expect(container.classList).toContain('mat-drawer-opened');
83+
expect(container.classList).toContain('mat-drawer-container-has-open');
8484

8585
flush();
8686
expect(testComponent.closeStartCount).toBe(1);
8787
fixture.detectChanges();
8888

8989
expect(testComponent.closeCount).toBe(1);
9090
expect(testComponent.closeStartCount).toBe(1);
91-
expect(container.classList).not.toContain('mat-drawer-opened');
91+
expect(container.classList).not.toContain('mat-drawer-container-has-open');
9292
}));
9393

9494
it('should resolve the open method promise with the new state of the drawer', fakeAsync(() => {

src/material/sidenav/drawer.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,10 +715,13 @@ export class MatDrawerContainer implements AfterContentInit, DoCheck, OnDestroy
715715

716716
/** Toggles the 'mat-drawer-opened' class on the main 'mat-drawer-container' element. */
717717
private _setContainerClass(isAdd: boolean): void {
718+
const classList = this._element.nativeElement.classList;
719+
const className = 'mat-drawer-container-has-open';
720+
718721
if (isAdd) {
719-
this._element.nativeElement.classList.add('mat-drawer-opened');
722+
classList.add(className);
720723
} else {
721-
this._element.nativeElement.classList.remove('mat-drawer-opened');
724+
classList.remove(className);
722725
}
723726
}
724727

0 commit comments

Comments
 (0)