Skip to content

Commit c179440

Browse files
committed
fix(sidenav): implicit content element being registered twice with scroll dispatcher
When the consumer doesn't provide a `mat-sidenav-content`, we create one implicitly for them. The implicit content element has a `cdkScrollable` on it, which means that the it'll be registered on the `ScrollDispatcher` as a `CdkScrollable`, however since `MatSidenavContent` also extends `CdkScrollable`, it'll be registered again as a `MatSidenavContent`. These change remove the extra `cdkScrollable` from the view in order to avoid the issue. These changes also provide the sidenav content as a `CdkScrollable` for DI purposes.
1 parent 03a9a39 commit c179440

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

src/material/sidenav/drawer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ export function MAT_DRAWER_DEFAULT_AUTOSIZE_FACTORY(): boolean {
8787
},
8888
changeDetection: ChangeDetectionStrategy.OnPush,
8989
encapsulation: ViewEncapsulation.None,
90+
providers: [{
91+
provide: CdkScrollable,
92+
useExisting: MatDrawerContent,
93+
}]
9094
})
9195
export class MatDrawerContent extends CdkScrollable implements AfterContentInit {
9296
constructor(

src/material/sidenav/sidenav-container.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55

66
<ng-content select="mat-sidenav-content">
77
</ng-content>
8-
<mat-sidenav-content *ngIf="!_content" cdkScrollable>
8+
<mat-sidenav-content *ngIf="!_content">
99
<ng-content></ng-content>
1010
</mat-sidenav-content>

src/material/sidenav/sidenav.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
import {MatDrawer, MatDrawerContainer, MatDrawerContent} from './drawer';
2424
import {matDrawerAnimations} from './drawer-animations';
2525
import {coerceBooleanProperty, coerceNumberProperty} from '@angular/cdk/coercion';
26-
import {ScrollDispatcher} from '@angular/cdk/scrolling';
26+
import {ScrollDispatcher, CdkScrollable} from '@angular/cdk/scrolling';
2727

2828

2929
@Component({
@@ -37,6 +37,10 @@ import {ScrollDispatcher} from '@angular/cdk/scrolling';
3737
},
3838
changeDetection: ChangeDetectionStrategy.OnPush,
3939
encapsulation: ViewEncapsulation.None,
40+
providers: [{
41+
provide: CdkScrollable,
42+
useExisting: MatSidenavContent,
43+
}]
4044
})
4145
export class MatSidenavContent extends MatDrawerContent {
4246
constructor(

0 commit comments

Comments
 (0)