Skip to content

Commit f5c4f63

Browse files
committed
refactor(material/select): switch to tree shakeable overlay APIs
Reworks the module to use the new tree-shakeable APIs for creating overlays.
1 parent c9ccc21 commit f5c4f63

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

goldens/material/select/index.api.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import { Observable } from 'rxjs';
3535
import { OnChanges } from '@angular/core';
3636
import { OnDestroy } from '@angular/core';
3737
import { OnInit } from '@angular/core';
38-
import { Overlay } from '@angular/cdk/overlay';
3938
import { QueryList } from '@angular/core';
4039
import { ScrollStrategy } from '@angular/cdk/overlay';
4140
import { SelectionModel } from '@angular/cdk/collections';
@@ -52,12 +51,12 @@ export const MAT_SELECT_SCROLL_STRATEGY: InjectionToken<() => ScrollStrategy>;
5251
// @public @deprecated
5352
export const MAT_SELECT_SCROLL_STRATEGY_PROVIDER: {
5453
provide: InjectionToken<() => ScrollStrategy>;
55-
deps: (typeof Overlay)[];
54+
deps: any[];
5655
useFactory: typeof MAT_SELECT_SCROLL_STRATEGY_PROVIDER_FACTORY;
5756
};
5857

5958
// @public @deprecated
60-
export function MAT_SELECT_SCROLL_STRATEGY_PROVIDER_FACTORY(overlay: Overlay): () => ScrollStrategy;
59+
export function MAT_SELECT_SCROLL_STRATEGY_PROVIDER_FACTORY(_overlay: unknown): () => ScrollStrategy;
6160

6261
// @public
6362
export const MAT_SELECT_TRIGGER: InjectionToken<MatSelectTrigger>;

src/material/select/select.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
TAB,
1616
UP_ARROW,
1717
} from '@angular/cdk/keycodes';
18-
import {CloseScrollStrategy, Overlay, OverlayContainer, OverlayModule} from '@angular/cdk/overlay';
18+
import {createCloseScrollStrategy, OverlayContainer, OverlayModule} from '@angular/cdk/overlay';
1919
import {ScrollDispatcher} from '@angular/cdk/scrolling';
2020
import {
2121
createKeyboardEvent,
@@ -30,6 +30,7 @@ import {
3030
Component,
3131
DebugElement,
3232
ElementRef,
33+
Injector,
3334
OnInit,
3435
Provider,
3536
QueryList,
@@ -1779,9 +1780,7 @@ describe('MatSelect', () => {
17791780
providers: [
17801781
{
17811782
provide: MAT_SELECT_SCROLL_STRATEGY,
1782-
useFactory: (overlay: Overlay) => (): CloseScrollStrategy =>
1783-
overlay.scrollStrategies.close(),
1784-
deps: [Overlay],
1783+
useFactory: () => () => createCloseScrollStrategy(TestBed.inject(Injector)),
17851784
},
17861785
{
17871786
provide: ScrollDispatcher,

src/material/select/select.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
CdkConnectedOverlay,
3131
CdkOverlayOrigin,
3232
ConnectedPosition,
33-
Overlay,
33+
createRepositionScrollStrategy,
3434
ScrollStrategy,
3535
} from '@angular/cdk/overlay';
3636
import {ViewportRuler} from '@angular/cdk/scrolling';
@@ -60,6 +60,7 @@ import {
6060
ViewEncapsulation,
6161
HostAttributeToken,
6262
Renderer2,
63+
Injector,
6364
} from '@angular/core';
6465
import {
6566
AbstractControl,
@@ -97,8 +98,8 @@ export const MAT_SELECT_SCROLL_STRATEGY = new InjectionToken<() => ScrollStrateg
9798
{
9899
providedIn: 'root',
99100
factory: () => {
100-
const overlay = inject(Overlay);
101-
return () => overlay.scrollStrategies.reposition();
101+
const injector = inject(Injector);
102+
return () => createRepositionScrollStrategy(injector);
102103
},
103104
},
104105
);
@@ -109,9 +110,10 @@ export const MAT_SELECT_SCROLL_STRATEGY = new InjectionToken<() => ScrollStrateg
109110
* @breaking-change 21.0.0
110111
*/
111112
export function MAT_SELECT_SCROLL_STRATEGY_PROVIDER_FACTORY(
112-
overlay: Overlay,
113+
_overlay: unknown,
113114
): () => ScrollStrategy {
114-
return () => overlay.scrollStrategies.reposition();
115+
const injector = inject(Injector);
116+
return () => createRepositionScrollStrategy(injector);
115117
}
116118

117119
/** Object that can be used to configure the default options for the select module. */
@@ -151,7 +153,7 @@ export const MAT_SELECT_CONFIG = new InjectionToken<MatSelectConfig>('MAT_SELECT
151153
*/
152154
export const MAT_SELECT_SCROLL_STRATEGY_PROVIDER = {
153155
provide: MAT_SELECT_SCROLL_STRATEGY,
154-
deps: [Overlay],
156+
deps: [] as any[],
155157
useFactory: MAT_SELECT_SCROLL_STRATEGY_PROVIDER_FACTORY,
156158
};
157159

0 commit comments

Comments
 (0)