Skip to content

Commit 21b4a60

Browse files
committed
refactor(material/tooltip): switch to tree shakeable overlay APIs
Reworks the module to use the new tree-shakeable APIs for creating overlays.
1 parent 7490b8a commit 21b4a60

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

goldens/material/tooltip/index.api.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { NumberInput } from '@angular/cdk/coercion';
1919
import { Observable } from 'rxjs';
2020
import { OnDestroy } from '@angular/core';
2121
import { OriginConnectionPosition } from '@angular/cdk/overlay';
22-
import { Overlay } from '@angular/cdk/overlay';
2322
import { OverlayConnectionPosition } from '@angular/cdk/overlay';
2423
import { OverlayRef } from '@angular/cdk/overlay';
2524
import { ScrollStrategy } from '@angular/cdk/overlay';
@@ -37,12 +36,12 @@ export function MAT_TOOLTIP_DEFAULT_OPTIONS_FACTORY(): MatTooltipDefaultOptions;
3736
export const MAT_TOOLTIP_SCROLL_STRATEGY: InjectionToken<() => ScrollStrategy>;
3837

3938
// @public @deprecated
40-
export function MAT_TOOLTIP_SCROLL_STRATEGY_FACTORY(overlay: Overlay): () => ScrollStrategy;
39+
export function MAT_TOOLTIP_SCROLL_STRATEGY_FACTORY(_overlay: unknown): () => ScrollStrategy;
4140

4241
// @public @deprecated
4342
export const MAT_TOOLTIP_SCROLL_STRATEGY_FACTORY_PROVIDER: {
4443
provide: InjectionToken<() => ScrollStrategy>;
45-
deps: (typeof Overlay)[];
44+
deps: any[];
4645
useFactory: typeof MAT_TOOLTIP_SCROLL_STRATEGY_FACTORY;
4746
};
4847

src/material/tooltip/tooltip.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ import {Directionality} from '@angular/cdk/bidi';
3939
import {
4040
ConnectedPosition,
4141
ConnectionPositionPair,
42+
createFlexibleConnectedPositionStrategy,
43+
createOverlayRef,
44+
createRepositionScrollStrategy,
4245
FlexibleConnectedPositionStrategy,
4346
HorizontalConnectionPos,
4447
OriginConnectionPosition,
45-
Overlay,
4648
OverlayConnectionPosition,
4749
OverlayRef,
4850
ScrollDispatcher,
@@ -82,8 +84,8 @@ export const MAT_TOOLTIP_SCROLL_STRATEGY = new InjectionToken<() => ScrollStrate
8284
{
8385
providedIn: 'root',
8486
factory: () => {
85-
const overlay = inject(Overlay);
86-
return () => overlay.scrollStrategies.reposition({scrollThrottle: SCROLL_THROTTLE_MS});
87+
const injector = inject(Injector);
88+
return () => createRepositionScrollStrategy(injector, {scrollThrottle: SCROLL_THROTTLE_MS});
8789
},
8890
},
8991
);
@@ -93,8 +95,9 @@ export const MAT_TOOLTIP_SCROLL_STRATEGY = new InjectionToken<() => ScrollStrate
9395
* @deprecated No longer used, will be removed.
9496
* @breaking-change 21.0.0
9597
*/
96-
export function MAT_TOOLTIP_SCROLL_STRATEGY_FACTORY(overlay: Overlay): () => ScrollStrategy {
97-
return () => overlay.scrollStrategies.reposition({scrollThrottle: SCROLL_THROTTLE_MS});
98+
export function MAT_TOOLTIP_SCROLL_STRATEGY_FACTORY(_overlay: unknown): () => ScrollStrategy {
99+
const injector = inject(Injector);
100+
return () => createRepositionScrollStrategy(injector, {scrollThrottle: SCROLL_THROTTLE_MS});
98101
}
99102

100103
/**
@@ -104,7 +107,7 @@ export function MAT_TOOLTIP_SCROLL_STRATEGY_FACTORY(overlay: Overlay): () => Scr
104107
*/
105108
export const MAT_TOOLTIP_SCROLL_STRATEGY_FACTORY_PROVIDER = {
106109
provide: MAT_TOOLTIP_SCROLL_STRATEGY,
107-
deps: [Overlay],
110+
deps: [] as any[],
108111
useFactory: MAT_TOOLTIP_SCROLL_STRATEGY_FACTORY,
109112
};
110113

@@ -525,13 +528,13 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
525528
.get(ScrollDispatcher)
526529
.getAncestorScrollContainers(this._elementRef);
527530

528-
const overlay = this._injector.get(Overlay);
529531
const panelClass = `${this._cssClassPrefix}-${PANEL_CLASS}`;
530532

531533
// Create connected position strategy that listens for scroll events to reposition.
532-
const strategy = overlay
533-
.position()
534-
.flexibleConnectedTo(this.positionAtOrigin ? origin || this._elementRef : this._elementRef)
534+
const strategy = createFlexibleConnectedPositionStrategy(
535+
this._injector,
536+
this.positionAtOrigin ? origin || this._elementRef : this._elementRef,
537+
)
535538
.withTransformOriginOn(`.${this._cssClassPrefix}-tooltip`)
536539
.withFlexibleDimensions(false)
537540
.withViewportMargin(this._viewportMargin)
@@ -549,7 +552,7 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
549552
}
550553
});
551554

552-
this._overlayRef = overlay.create({
555+
this._overlayRef = createOverlayRef(this._injector, {
553556
direction: this._dir,
554557
positionStrategy: strategy,
555558
panelClass: this._overlayPanelClass ? [...this._overlayPanelClass, panelClass] : panelClass,

0 commit comments

Comments
 (0)