Skip to content

Commit 0d1fa82

Browse files
committed
chore(overlay): add attach method to PositionStrategy interface
1 parent 72360e2 commit 0d1fa82

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

src/cdk/overlay/overlay-ref.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ export class OverlayRef implements PortalHost {
4545
attach(portal: Portal<any>): any {
4646
let attachResult = this._portalHost.attach(portal);
4747

48+
if (this._state.positionStrategy) {
49+
this._state.positionStrategy.attach(this);
50+
}
51+
4852
// Update the pane element with the given state configuration.
4953
this._updateStackingOrder();
5054
this.updateSize();

src/cdk/overlay/overlay.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ class FakePositionStrategy implements PositionStrategy {
537537
return Promise.resolve(null);
538538
}
539539

540+
attach() {}
540541
dispose() {}
541542
}
542543

src/cdk/overlay/position/connected-position-strategy.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import {
1818
import {Subject} from 'rxjs/Subject';
1919
import {Observable} from 'rxjs/Observable';
2020
import {Scrollable} from '../scroll/scrollable';
21+
import {OverlayRef} from '../overlay-ref';
22+
2123

2224
/**
2325
* Container to hold the bounding positions of a particular element with respect to the viewport,
@@ -39,6 +41,9 @@ type ElementBoundingPositions = {
3941
* of the overlay.
4042
*/
4143
export class ConnectedPositionStrategy implements PositionStrategy {
44+
/** The overlay to which this strategy is attached. */
45+
private _overlayRef: OverlayRef;
46+
4247
private _dir = 'ltr';
4348

4449
/** The offset in pixels for the overlay connection point on the x-axis */
@@ -89,9 +94,11 @@ export class ConnectedPositionStrategy implements PositionStrategy {
8994
return this._preferredPositions;
9095
}
9196

92-
/**
93-
* To be used to for any cleanup after the element gets destroyed.
94-
*/
97+
attach(overlayRef: OverlayRef): void {
98+
this._overlayRef = overlayRef;
99+
}
100+
101+
/** To be used to for any cleanup after the element gets destroyed. */
95102
dispose() { }
96103

97104
/**

src/cdk/overlay/position/global-position-strategy.ts

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

99
import {PositionStrategy} from './position-strategy';
10+
import {OverlayRef} from '../overlay-ref';
1011

1112

1213
/**
@@ -16,6 +17,9 @@ import {PositionStrategy} from './position-strategy';
1617
* element to become blurry.
1718
*/
1819
export class GlobalPositionStrategy implements PositionStrategy {
20+
/** The overlay to which this strategy is attached. */
21+
private _overlayRef: OverlayRef;
22+
1923
private _cssPosition: string = 'static';
2024
private _topOffset: string = '';
2125
private _bottomOffset: string = '';
@@ -29,6 +33,10 @@ export class GlobalPositionStrategy implements PositionStrategy {
2933
/* A lazily-created wrapper for the overlay element that is used as a flex container. */
3034
private _wrapper: HTMLElement | null = null;
3135

36+
attach(overlayRef: OverlayRef): void {
37+
this._overlayRef = overlayRef;
38+
}
39+
3240
/**
3341
* Sets the top position of the overlay. Clears any previously set vertical position.
3442
* @param value New top offset.

src/cdk/overlay/position/position-strategy.ts

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

9+
import {OverlayRef} from '../overlay-ref';
10+
11+
912
/** Strategy for setting the position on an overlay. */
1013
export interface PositionStrategy {
1114

15+
/** Attaches this position strategy to an overlay. */
16+
attach(overlay: OverlayRef): void;
17+
1218
/** Updates the position of the overlay element. */
1319
apply(element: Element): void;
1420

0 commit comments

Comments
 (0)