Skip to content

feat(overlay): CoverPositionStrategy #15691

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

Closed
wants to merge 11 commits into from
Closed
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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
/src/dev-app/checkbox/** @jelbourn @devversion
/src/dev-app/chips/** @jelbourn
/src/dev-app/connected-overlay/** @jelbourn @crisbeto
/src/dev-app/cover-overlay/** @kkseamon @jelbourn
/src/dev-app/dataset/** @andrewseguin
/src/dev-app/datepicker/** @mmalerba
/src/dev-app/dev-app/** @mmalerba
Expand Down
42 changes: 42 additions & 0 deletions src/cdk/overlay/position/cover-position-strategy-factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {Inject, Injectable} from '@angular/core';
import {DOCUMENT} from '@angular/common';
import {Platform} from '@angular/cdk/platform';
import {ViewportRuler} from '@angular/cdk/scrolling';
import {FlexibleConnectedPositionStrategyOrigin} from './flexible-positioning';
import {CoverPositionStrategy} from './cover-position-strategy';

@Injectable({providedIn: 'root'})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add JsDoc description

I'd also add a file-level comment that explains that this class exists so that people can instantiate a CoverPositionStrategy without manually passing in its numerous injected deps

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do - IMO all of the factories for position strategies should move to something like this rather than baking them into Overlay (and defeating tree-shaking of them in the process).

export class CoverPositionStrategyFactory {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a dedicated factory for it? All of the other position strategies are created through the OverlayPositionBuilder.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO all of the strategies should move towards a separate factory approach for better tree shakability. In this case, I did not want to add something new that would not be tree-shaken away by default.

Copy link
Member

@crisbeto crisbeto Apr 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've had that on my list for a while, but the problem is that we can't do it easily without either a breaking change or having to maintain two approaches for a while. It would also be tricky to migrate people once we remove the deprecated approach. Having only this strategy with a dedicated factory is inconsistent.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably you'd add individual factories, have the existing combined factory use them for now, mark it as deprecated and remove it after a couple releases? I'll defer to whatever Jeremy prefers though.

constructor(
private _viewportRuler: ViewportRuler,
@Inject(DOCUMENT) private _document: any,
private _platform: Platform) {}

create() {
return this.createWithConnections({});
}

createWithConnections({top, right, left, bottom}: {
top?: FlexibleConnectedPositionStrategyOrigin,
right?: FlexibleConnectedPositionStrategyOrigin,
bottom?: FlexibleConnectedPositionStrategyOrigin,
left?: FlexibleConnectedPositionStrategyOrigin
}) {
return new CoverPositionStrategy(
this._viewportRuler,
this._document,
this._platform,
top,
right,
bottom,
left);
}
}
Loading