Skip to content

Commit 3eb71c2

Browse files
jelbournandrewseguin
authored andcommitted
fix(select): scroll strategy token cannot inject overlay (#10535)
1 parent c05005a commit 3eb71c2

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

src/lib/select/select-module.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import {NgModule} from '@angular/core';
8+
9+
import {OverlayModule} from '@angular/cdk/overlay';
910
import {CommonModule} from '@angular/common';
10-
import {MatSelect, MatSelectTrigger} from './select';
11+
import {NgModule} from '@angular/core';
1112
import {MatCommonModule, MatOptionModule} from '@angular/material/core';
12-
import {OverlayModule} from '@angular/cdk/overlay';
1313
import {MatFormFieldModule} from '@angular/material/form-field';
14+
import {MAT_SELECT_SCROLL_STRATEGY_PROVIDER, MatSelect, MatSelectTrigger} from './select';
1415

1516

1617
@NgModule({
@@ -22,5 +23,6 @@ import {MatFormFieldModule} from '@angular/material/form-field';
2223
],
2324
exports: [MatFormFieldModule, MatSelect, MatSelectTrigger, MatOptionModule, MatCommonModule],
2425
declarations: [MatSelect, MatSelectTrigger],
26+
providers: [MAT_SELECT_SCROLL_STRATEGY_PROVIDER]
2527
})
2628
export class MatSelectModule {}

src/lib/select/select.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ import {
2323
import {
2424
CdkConnectedOverlay,
2525
Overlay,
26+
RepositionScrollStrategy,
2627
ScrollStrategy,
2728
ViewportRuler,
2829
} from '@angular/cdk/overlay';
29-
import {filter, take, map, switchMap, takeUntil, startWith} from 'rxjs/operators';
3030
import {
3131
AfterContentInit,
3232
Attribute,
@@ -40,7 +40,6 @@ import {
4040
ElementRef,
4141
EventEmitter,
4242
Inject,
43-
inject,
4443
InjectionToken,
4544
Input,
4645
isDevMode,
@@ -75,7 +74,8 @@ import {
7574
mixinTabIndex,
7675
} from '@angular/material/core';
7776
import {MatFormField, MatFormFieldControl} from '@angular/material/form-field';
78-
import {defer, Subject, merge, Observable} from 'rxjs';
77+
import {defer, merge, Observable, Subject} from 'rxjs';
78+
import {filter, map, startWith, switchMap, take, takeUntil} from 'rxjs/operators';
7979
import {matSelectAnimations} from './select-animations';
8080
import {
8181
getMatSelectDynamicMultipleError,
@@ -122,13 +122,20 @@ export const SELECT_PANEL_VIEWPORT_PADDING = 8;
122122

123123
/** Injection token that determines the scroll handling while a select is open. */
124124
export const MAT_SELECT_SCROLL_STRATEGY =
125-
new InjectionToken<() => ScrollStrategy>('mat-select-scroll-strategy', {
126-
providedIn: 'root',
127-
factory: () => {
128-
const overlay = inject(Overlay);
129-
return () => overlay.scrollStrategies.reposition();
130-
}
131-
});
125+
new InjectionToken<() => ScrollStrategy>('mat-select-scroll-strategy');
126+
127+
/** @docs-private */
128+
export function MAT_SELECT_SCROLL_STRATEGY_PROVIDER_FACTORY(overlay: Overlay):
129+
() => RepositionScrollStrategy {
130+
return () => overlay.scrollStrategies.reposition();
131+
}
132+
133+
/** @docs-private */
134+
export const MAT_SELECT_SCROLL_STRATEGY_PROVIDER = {
135+
provide: MAT_SELECT_SCROLL_STRATEGY,
136+
deps: [Overlay],
137+
useFactory: MAT_SELECT_SCROLL_STRATEGY_PROVIDER_FACTORY,
138+
};
132139

133140
/** Change event object that is emitted when the select value has changed. */
134141
export class MatSelectChange {

0 commit comments

Comments
 (0)