Skip to content

Commit f5f3662

Browse files
crisbetojelbourn
authored andcommitted
refactor(scrolling): add dedicated module for CdkScrollable (#19064)
This is something that originally came up in #18082 and has been coming up as issues on GitHub. Some of our overlay-based components depend on `CdkScrollable` to tell them when to reposition, but the problem is that it's not very easy to consume, because: 1. It has an attribute selector so if it doesn't match, nothing will throw an error. 2. It has to be brought in through the `ScrollingModule` into the proper user module. The `ScrollingModule` is somewhat large, because it contains other things like virtual scrolling. These changes address the issues by adding a small module dedicated only to `CdkScrollable`, and exporting the module through the relevant Material components.
1 parent 0695e82 commit f5f3662

File tree

20 files changed

+53
-19
lines changed

20 files changed

+53
-19
lines changed

src/cdk/drag-drop/directives/drag.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
} from '@angular/core';
2424
import {TestBed, ComponentFixture, fakeAsync, flush, tick} from '@angular/core/testing';
2525
import {DOCUMENT} from '@angular/common';
26-
import {ViewportRuler, ScrollingModule} from '@angular/cdk/scrolling';
26+
import {ViewportRuler, CdkScrollableModule} from '@angular/cdk/scrolling';
2727
import {_supportsShadowDom} from '@angular/cdk/platform';
2828
import {of as observableOf} from 'rxjs';
2929

@@ -48,7 +48,7 @@ describe('CdkDrag', () => {
4848
extraDeclarations: Type<any>[] = []): ComponentFixture<T> {
4949
TestBed
5050
.configureTestingModule({
51-
imports: [DragDropModule, ScrollingModule],
51+
imports: [DragDropModule, CdkScrollableModule],
5252
declarations: [componentType, PassthroughComponent, ...extraDeclarations],
5353
providers: [
5454
{

src/cdk/drag-drop/drag-drop-module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
import {NgModule} from '@angular/core';
10+
import {CdkScrollableModule} from '@angular/cdk/scrolling';
1011
import {CdkDropList} from './directives/drop-list';
1112
import {CdkDropListGroup} from './directives/drop-list-group';
1213
import {CdkDrag} from './directives/drag';
@@ -25,6 +26,7 @@ import {DragDrop} from './drag-drop';
2526
CdkDragPlaceholder,
2627
],
2728
exports: [
29+
CdkScrollableModule,
2830
CdkDropList,
2931
CdkDropListGroup,
3032
CdkDrag,

src/cdk/scrolling/scrolling-module.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,26 @@ import {CdkVirtualForOf} from './virtual-for-of';
1515
import {CdkVirtualScrollViewport} from './virtual-scroll-viewport';
1616

1717
@NgModule({
18-
imports: [BidiModule, PlatformModule],
18+
exports: [CdkScrollable],
19+
declarations: [CdkScrollable]
20+
})
21+
export class CdkScrollableModule {}
22+
23+
@NgModule({
24+
imports: [
25+
BidiModule,
26+
PlatformModule,
27+
CdkScrollableModule
28+
],
1929
exports: [
2030
BidiModule,
31+
CdkScrollableModule,
2132
CdkFixedSizeVirtualScroll,
22-
CdkScrollable,
2333
CdkVirtualForOf,
2434
CdkVirtualScrollViewport,
2535
],
2636
declarations: [
2737
CdkFixedSizeVirtualScroll,
28-
CdkScrollable,
2938
CdkVirtualForOf,
3039
CdkVirtualScrollViewport,
3140
],

src/material-experimental/mdc-menu/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ ng_module(
2323
module_name = "@angular/material-experimental/mdc-menu",
2424
deps = [
2525
"//src/cdk/overlay",
26+
"//src/cdk/scrolling",
2627
"//src/material/core",
2728
"//src/material/menu",
2829
"@npm//@angular/animations",

src/material-experimental/mdc-menu/module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {NgModule} from '@angular/core';
1111
import {MatCommonModule, MatRippleModule} from '@angular/material/core';
1212
import {OverlayModule} from '@angular/cdk/overlay';
1313
import {_MatMenuDirectivesModule} from '@angular/material/menu';
14+
import {CdkScrollableModule} from '@angular/cdk/scrolling';
1415
import {MatMenu, MAT_MENU_SCROLL_STRATEGY_FACTORY_PROVIDER} from './menu';
1516
import {MatMenuItem} from './menu-item';
1617

@@ -22,7 +23,7 @@ import {MatMenuItem} from './menu-item';
2223
OverlayModule,
2324
_MatMenuDirectivesModule
2425
],
25-
exports: [MatMenu, MatCommonModule, MatMenuItem, _MatMenuDirectivesModule],
26+
exports: [CdkScrollableModule, MatMenu, MatCommonModule, MatMenuItem, _MatMenuDirectivesModule],
2627
declarations: [MatMenu, MatMenuItem],
2728
providers: [MAT_MENU_SCROLL_STRATEGY_FACTORY_PROVIDER]
2829
})

src/material/autocomplete/autocomplete-module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {NgModule} from '@angular/core';
1010
import {CommonModule} from '@angular/common';
1111
import {OverlayModule} from '@angular/cdk/overlay';
1212
import {MatOptionModule, MatCommonModule} from '@angular/material/core';
13+
import {CdkScrollableModule} from '@angular/cdk/scrolling';
1314
import {MatAutocomplete} from './autocomplete';
1415
import {
1516
MatAutocompleteTrigger,
@@ -20,6 +21,7 @@ import {MatAutocompleteOrigin} from './autocomplete-origin';
2021
@NgModule({
2122
imports: [MatOptionModule, OverlayModule, MatCommonModule, CommonModule],
2223
exports: [
24+
CdkScrollableModule,
2325
MatAutocomplete,
2426
MatOptionModule,
2527
MatAutocompleteTrigger,

src/material/datepicker/datepicker-module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {CommonModule} from '@angular/common';
1313
import {NgModule} from '@angular/core';
1414
import {MatButtonModule} from '@angular/material/button';
1515
import {MatDialogModule} from '@angular/material/dialog';
16+
import {CdkScrollableModule} from '@angular/cdk/scrolling';
1617
import {MatCalendar, MatCalendarHeader} from './calendar';
1718
import {MatCalendarBody} from './calendar-body';
1819
import {
@@ -38,6 +39,7 @@ import {MatYearView} from './year-view';
3839
PortalModule,
3940
],
4041
exports: [
42+
CdkScrollableModule,
4143
MatCalendar,
4244
MatCalendarBody,
4345
MatDatepicker,

src/material/menu/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ ng_module(
2828
"//src/cdk/overlay",
2929
"//src/cdk/platform",
3030
"//src/cdk/portal",
31+
"//src/cdk/scrolling",
3132
"//src/material/core",
3233
"@npm//@angular/animations",
3334
"@npm//@angular/common",

src/material/menu/menu-module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {OverlayModule} from '@angular/cdk/overlay';
1010
import {CommonModule} from '@angular/common';
1111
import {NgModule} from '@angular/core';
1212
import {MatCommonModule, MatRippleModule} from '@angular/material/core';
13+
import {CdkScrollableModule} from '@angular/cdk/scrolling';
1314
import {_MatMenu} from './menu';
1415
import {MatMenuContent} from './menu-content';
1516
import {MatMenuItem} from './menu-item';
@@ -38,7 +39,7 @@ export class _MatMenuDirectivesModule {}
3839
OverlayModule,
3940
_MatMenuDirectivesModule,
4041
],
41-
exports: [MatCommonModule, _MatMenu, MatMenuItem, _MatMenuDirectivesModule],
42+
exports: [CdkScrollableModule, MatCommonModule, _MatMenu, MatMenuItem, _MatMenuDirectivesModule],
4243
declarations: [_MatMenu, MatMenuItem],
4344
providers: [MAT_MENU_SCROLL_STRATEGY_FACTORY_PROVIDER]
4445
})

src/material/select/select-module.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {CommonModule} from '@angular/common';
1111
import {NgModule} from '@angular/core';
1212
import {MatCommonModule, MatOptionModule} from '@angular/material/core';
1313
import {MatFormFieldModule} from '@angular/material/form-field';
14+
import {CdkScrollableModule} from '@angular/cdk/scrolling';
1415
import {MAT_SELECT_SCROLL_STRATEGY_PROVIDER, MatSelect, MatSelectTrigger} from './select';
1516

1617

@@ -21,7 +22,14 @@ import {MAT_SELECT_SCROLL_STRATEGY_PROVIDER, MatSelect, MatSelectTrigger} from '
2122
MatOptionModule,
2223
MatCommonModule,
2324
],
24-
exports: [MatFormFieldModule, MatSelect, MatSelectTrigger, MatOptionModule, MatCommonModule],
25+
exports: [
26+
CdkScrollableModule,
27+
MatFormFieldModule,
28+
MatSelect,
29+
MatSelectTrigger,
30+
MatOptionModule,
31+
MatCommonModule
32+
],
2533
declarations: [MatSelect, MatSelectTrigger],
2634
providers: [MAT_SELECT_SCROLL_STRATEGY_PROVIDER]
2735
})

0 commit comments

Comments
 (0)