Skip to content

Commit 2620abc

Browse files
authored
fix(angular/sidebar): implicit content element being registered twice with scroll dispatcher
When the consumer doesn't provide a `sbb-sidebar-content`, we create one implicitly for them. The implicit content element has a `cdkScrollable` on it, which means that it'll be registered on the `ScrollDispatcher` as a `CdkScrollable`, however since `SbbSidebarContent` also extends `CdkScrollable`, it'll be registered again as a `SbbSidebarContent`. These change remove the extra `cdkScrollable` from the view in order to avoid the issue. These changes also provide the sidebar content as a `CdkScrollable` for DI purposes. angular/components#13973
1 parent 5e978c6 commit 2620abc

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<ng-content select="sbb-icon-sidebar"></ng-content>
22

33
<ng-content select="sbb-icon-sidebar-content"> </ng-content>
4-
<sbb-icon-sidebar-content *ngIf="!_content" cdkScrollable>
4+
<sbb-icon-sidebar-content *ngIf="!_content">
55
<ng-content></ng-content>
66
</sbb-icon-sidebar-content>

src/angular/sidebar/icon-sidebar/icon-sidebar.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import { BooleanInput, coerceBooleanProperty } from '@angular/cdk/coercion';
55
import { BreakpointObserver } from '@angular/cdk/layout';
6-
import { ScrollDispatcher } from '@angular/cdk/scrolling';
6+
import { CdkScrollable, ScrollDispatcher } from '@angular/cdk/scrolling';
77
import {
88
AfterContentInit,
99
ChangeDetectionStrategy,
@@ -39,6 +39,12 @@ import {
3939
},
4040
changeDetection: ChangeDetectionStrategy.OnPush,
4141
encapsulation: ViewEncapsulation.None,
42+
providers: [
43+
{
44+
provide: CdkScrollable,
45+
useExisting: SbbIconSidebarContent,
46+
},
47+
],
4248
})
4349
export class SbbIconSidebarContent extends SbbSidebarContentBase {
4450
constructor(

src/angular/sidebar/sidebar/sidebar-container.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
<ng-content select="sbb-sidebar"></ng-content>
2020

2121
<ng-content select="sbb-sidebar-content"> </ng-content>
22-
<sbb-sidebar-content *ngIf="!_content" cdkScrollable>
22+
<sbb-sidebar-content *ngIf="!_content">
2323
<ng-content></ng-content>
2424
</sbb-sidebar-content>

src/angular/sidebar/sidebar/sidebar.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import { ESCAPE, hasModifierKey } from '@angular/cdk/keycodes';
1212
import { BreakpointObserver } from '@angular/cdk/layout';
1313
import { Platform } from '@angular/cdk/platform';
14-
import { ScrollDispatcher, ViewportRuler } from '@angular/cdk/scrolling';
14+
import { CdkScrollable, ScrollDispatcher, ViewportRuler } from '@angular/cdk/scrolling';
1515
import { DOCUMENT } from '@angular/common';
1616
import {
1717
AfterContentChecked,
@@ -73,6 +73,12 @@ export type SbbSidebarMode = 'over' | 'side';
7373
},
7474
changeDetection: ChangeDetectionStrategy.OnPush,
7575
encapsulation: ViewEncapsulation.None,
76+
providers: [
77+
{
78+
provide: CdkScrollable,
79+
useExisting: SbbSidebarContent,
80+
},
81+
],
7682
})
7783
export class SbbSidebarContent extends SbbSidebarContentBase implements AfterContentInit {
7884
constructor(

0 commit comments

Comments
 (0)