Skip to content

fix(connected-position-strategy): allow positions to be updated after init #8800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/cdk/overlay/position/connected-position-strategy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
OverlayContainer,
ConnectedPositionStrategy,
ConnectedOverlayPositionChange,
ConnectionPositionPair,
} from '../index';


Expand Down Expand Up @@ -544,6 +545,32 @@ describe('ConnectedPositionStrategy', () => {
expect(Math.floor(overlayRect.top)).toBe(Math.floor(originRect!.top));
expect(Math.floor(overlayRect.left)).toBe(Math.floor(originRect!.left));
});

it('should allow for the positions to be updated after init', () => {
strategy = positionBuilder.connectedTo(
fakeElementRef,
{originX: 'start', originY: 'bottom'},
{overlayX: 'start', overlayY: 'top'});

strategy.attach(fakeOverlayRef(overlayElement));
strategy.apply();

let overlayRect = overlayElement.getBoundingClientRect();
expect(Math.floor(overlayRect.top)).toBe(Math.floor(originRect!.bottom));
expect(Math.floor(overlayRect.left)).toBe(Math.floor(originRect!.left));

strategy.withPositions([new ConnectionPositionPair(
{originX: 'start', originY: 'bottom'},
{overlayX: 'end', overlayY: 'top'}
)]);

strategy.apply();

overlayRect = overlayElement.getBoundingClientRect();
expect(Math.floor(overlayRect.top)).toBe(Math.floor(originRect!.bottom));
expect(Math.floor(overlayRect.right)).toBe(Math.floor(originRect!.left));
});

}
});

Expand Down
9 changes: 9 additions & 0 deletions src/cdk/overlay/position/connected-position-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,15 @@ export class ConnectedPositionStrategy implements PositionStrategy {
return this;
}

/**
* Overwrites the current set of positions with an array of new ones.
* @param positions Position pairs to be set on the strategy.
*/
withPositions(positions: ConnectionPositionPair[]): this {
this._preferredPositions = positions.slice();
return this;
}

/**
* Gets the horizontal (x) "start" dimension based on whether the overlay is in an RTL context.
* @param rect
Expand Down