Skip to content

Commit eee804f

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 a30094b commit eee804f

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
@@ -96,6 +96,10 @@ export function MAT_DRAWER_DEFAULT_AUTOSIZE_FACTORY(): boolean {
9696
},
9797
changeDetection: ChangeDetectionStrategy.OnPush,
9898
encapsulation: ViewEncapsulation.None,
99+
providers: [{
100+
provide: CdkScrollable,
101+
useExisting: MatDrawerContent,
102+
}]
99103
})
100104
export class MatDrawerContent extends CdkScrollable implements AfterContentInit {
101105
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

3434
@Component({
@@ -41,6 +41,10 @@ import {ScrollDispatcher} from '@angular/cdk/scrolling';
4141
},
4242
changeDetection: ChangeDetectionStrategy.OnPush,
4343
encapsulation: ViewEncapsulation.None,
44+
providers: [{
45+
provide: CdkScrollable,
46+
useExisting: MatSidenavContent,
47+
}]
4448
})
4549
export class MatSidenavContent extends MatDrawerContent {
4650
constructor(

0 commit comments

Comments
 (0)