Skip to content

Commit c0c6f63

Browse files
authored
fix(multiple): add fallback root providers to injection tokens (#28259)
Cherry-picks some of the changes from #28155 to the patch branch since they're necessary for compatibility with `@defer`. Fixes #28198.
1 parent fc67358 commit c0c6f63

File tree

7 files changed

+58
-4
lines changed

7 files changed

+58
-4
lines changed

src/cdk/overlay/overlay-directives.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
TemplateRef,
2525
ViewContainerRef,
2626
booleanAttribute,
27+
inject,
2728
} from '@angular/core';
2829
import {Subscription} from 'rxjs';
2930
import {takeWhile} from 'rxjs/operators';
@@ -69,6 +70,13 @@ const defaultPositionList: ConnectedPosition[] = [
6970
/** Injection token that determines the scroll handling while the connected overlay is open. */
7071
export const CDK_CONNECTED_OVERLAY_SCROLL_STRATEGY = new InjectionToken<() => ScrollStrategy>(
7172
'cdk-connected-overlay-scroll-strategy',
73+
{
74+
providedIn: 'root',
75+
factory: () => {
76+
const overlay = inject(Overlay);
77+
return () => overlay.scrollStrategies.reposition();
78+
},
79+
},
7280
);
7381

7482
/**

src/material/autocomplete/autocomplete-trigger.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
ElementRef,
1616
forwardRef,
1717
Host,
18+
inject,
1819
Inject,
1920
InjectionToken,
2021
Input,
@@ -82,6 +83,13 @@ export function getMatAutocompleteMissingPanelError(): Error {
8283
/** Injection token that determines the scroll handling while the autocomplete panel is open. */
8384
export const MAT_AUTOCOMPLETE_SCROLL_STRATEGY = new InjectionToken<() => ScrollStrategy>(
8485
'mat-autocomplete-scroll-strategy',
86+
{
87+
providedIn: 'root',
88+
factory: () => {
89+
const overlay = inject(Overlay);
90+
return () => overlay.scrollStrategies.reposition();
91+
},
92+
},
8593
);
8694

8795
/** @docs-private */

src/material/chips/tokens.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import {ENTER} from '@angular/cdk/keycodes';
910
import {InjectionToken} from '@angular/core';
1011

1112
/** Default options, for the chips module, that can be overridden. */
@@ -20,6 +21,12 @@ export interface MatChipsDefaultOptions {
2021
/** Injection token to be used to override the default options for the chips module. */
2122
export const MAT_CHIPS_DEFAULT_OPTIONS = new InjectionToken<MatChipsDefaultOptions>(
2223
'mat-chips-default-options',
24+
{
25+
providedIn: 'root',
26+
factory: () => ({
27+
separatorKeyCodes: [ENTER],
28+
}),
29+
},
2330
);
2431

2532
/**

src/material/datepicker/datepicker-base.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ let datepickerUid = 0;
7979
/** Injection token that determines the scroll handling while the calendar is open. */
8080
export const MAT_DATEPICKER_SCROLL_STRATEGY = new InjectionToken<() => ScrollStrategy>(
8181
'mat-datepicker-scroll-strategy',
82+
{
83+
providedIn: 'root',
84+
factory: () => {
85+
const overlay = inject(Overlay);
86+
return () => overlay.scrollStrategies.reposition();
87+
},
88+
},
8289
);
8390

8491
/** @docs-private */
@@ -333,10 +340,11 @@ export interface MatDatepickerPanel<
333340
/** Base class for a datepicker. */
334341
@Directive()
335342
export abstract class MatDatepickerBase<
336-
C extends MatDatepickerControl<D>,
337-
S,
338-
D = ExtractDateTypeFromSelection<S>,
339-
> implements MatDatepickerPanel<C, S, D>, OnDestroy, OnChanges
343+
C extends MatDatepickerControl<D>,
344+
S,
345+
D = ExtractDateTypeFromSelection<S>,
346+
>
347+
implements MatDatepickerPanel<C, S, D>, OnDestroy, OnChanges
340348
{
341349
private _scrollStrategy: () => ScrollStrategy;
342350
private _inputStateChanges = Subscription.EMPTY;

src/material/menu/menu-trigger.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ import {MenuPositionX, MenuPositionY} from './menu-positions';
5353
/** Injection token that determines the scroll handling while the menu is open. */
5454
export const MAT_MENU_SCROLL_STRATEGY = new InjectionToken<() => ScrollStrategy>(
5555
'mat-menu-scroll-strategy',
56+
{
57+
providedIn: 'root',
58+
factory: () => {
59+
const overlay = inject(Overlay);
60+
return () => overlay.scrollStrategies.reposition();
61+
},
62+
},
5663
);
5764

5865
/** @docs-private */

src/material/select/select.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import {
6464
SimpleChanges,
6565
ViewChild,
6666
ViewEncapsulation,
67+
inject,
6768
} from '@angular/core';
6869
import {
6970
AbstractControl,
@@ -114,6 +115,13 @@ let nextUniqueId = 0;
114115
/** Injection token that determines the scroll handling while a select is open. */
115116
export const MAT_SELECT_SCROLL_STRATEGY = new InjectionToken<() => ScrollStrategy>(
116117
'mat-select-scroll-strategy',
118+
{
119+
providedIn: 'root',
120+
factory: () => {
121+
const overlay = inject(Overlay);
122+
return () => overlay.scrollStrategies.reposition();
123+
},
124+
},
117125
);
118126

119127
/** @docs-private */

src/material/tooltip/tooltip.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
ViewChild,
3030
ViewContainerRef,
3131
ViewEncapsulation,
32+
inject,
3233
} from '@angular/core';
3334
import {DOCUMENT} from '@angular/common';
3435
import {normalizePassiveListenerOptions, Platform} from '@angular/cdk/platform';
@@ -77,6 +78,13 @@ export function getMatTooltipInvalidPositionError(position: string) {
7778
/** Injection token that determines the scroll handling while a tooltip is visible. */
7879
export const MAT_TOOLTIP_SCROLL_STRATEGY = new InjectionToken<() => ScrollStrategy>(
7980
'mat-tooltip-scroll-strategy',
81+
{
82+
providedIn: 'root',
83+
factory: () => {
84+
const overlay = inject(Overlay);
85+
return () => overlay.scrollStrategies.reposition({scrollThrottle: SCROLL_THROTTLE_MS});
86+
},
87+
},
8088
);
8189

8290
/** @docs-private */

0 commit comments

Comments
 (0)