Skip to content

Commit 61c39b2

Browse files
authored
fix(sidenav): implicit content element being registered twice with scroll dispatcher (#13973)
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 caf979a commit 61c39b2

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

src/material/sidenav/drawer.ts

+4
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ export function MAT_DRAWER_DEFAULT_AUTOSIZE_FACTORY(): boolean {
103103
},
104104
changeDetection: ChangeDetectionStrategy.OnPush,
105105
encapsulation: ViewEncapsulation.None,
106+
providers: [{
107+
provide: CdkScrollable,
108+
useExisting: MatDrawerContent,
109+
}]
106110
})
107111
export class MatDrawerContent extends CdkScrollable implements AfterContentInit {
108112
constructor(

src/material/sidenav/sidenav-container.html

+1-1
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

+5-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
coerceNumberProperty,
2929
NumberInput,
3030
} from '@angular/cdk/coercion';
31-
import {ScrollDispatcher} from '@angular/cdk/scrolling';
31+
import {ScrollDispatcher, CdkScrollable} from '@angular/cdk/scrolling';
3232

3333
@Component({
3434
selector: 'mat-sidenav-content',
@@ -40,6 +40,10 @@ import {ScrollDispatcher} from '@angular/cdk/scrolling';
4040
},
4141
changeDetection: ChangeDetectionStrategy.OnPush,
4242
encapsulation: ViewEncapsulation.None,
43+
providers: [{
44+
provide: CdkScrollable,
45+
useExisting: MatSidenavContent,
46+
}]
4347
})
4448
export class MatSidenavContent extends MatDrawerContent {
4549
constructor(

0 commit comments

Comments
 (0)