Skip to content

Commit

Permalink
fix(sidenav): implicit content element being registered twice with sc…
Browse files Browse the repository at this point in the history
…roll 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.

(cherry picked from commit 61c39b2)
  • Loading branch information
crisbeto authored and andrewseguin committed Jan 13, 2022
1 parent ad21ee2 commit cb0a2ad
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/material/sidenav/drawer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ export function MAT_DRAWER_DEFAULT_AUTOSIZE_FACTORY(): boolean {
},
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
providers: [{
provide: CdkScrollable,
useExisting: MatDrawerContent,
}]
})
export class MatDrawerContent extends CdkScrollable implements AfterContentInit {
constructor(
Expand Down
2 changes: 1 addition & 1 deletion src/material/sidenav/sidenav-container.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

<ng-content select="mat-sidenav-content">
</ng-content>
<mat-sidenav-content *ngIf="!_content" cdkScrollable>
<mat-sidenav-content *ngIf="!_content">
<ng-content></ng-content>
</mat-sidenav-content>
6 changes: 5 additions & 1 deletion src/material/sidenav/sidenav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
coerceNumberProperty,
NumberInput,
} from '@angular/cdk/coercion';
import {ScrollDispatcher} from '@angular/cdk/scrolling';
import {ScrollDispatcher, CdkScrollable} from '@angular/cdk/scrolling';

@Component({
selector: 'mat-sidenav-content',
Expand All @@ -40,6 +40,10 @@ import {ScrollDispatcher} from '@angular/cdk/scrolling';
},
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
providers: [{
provide: CdkScrollable,
useExisting: MatSidenavContent,
}]
})
export class MatSidenavContent extends MatDrawerContent {
constructor(
Expand Down

0 comments on commit cb0a2ad

Please sign in to comment.