Skip to content

Creating Overlay declaratively - incorrect positioning #10821

@jackwootton

Description

@jackwootton

Bug, feature request, or proposal: Bug

Following the documentation for CdkConnectedOverlay I created an overlay with a hard-coded cdkConnectedOverlayWidth and cdkConnectedOverlayHeight

<ng-template
    cdkConnectedOverlay
    cdkConnectedOverlayHeight="100"
    cdkConnectedOverlayWidth="100"
    [cdkConnectedOverlayPositions]="positions"
    [cdkConnectedOverlayScrollStrategy]="scrollStrategy"
    [cdkConnectedOverlayOrigin]="trigger"
    [cdkConnectedOverlayOpen]="open">
	<div class="cdk-overlay-pane">
		Hello Component!
	</div>
</ng-template>

In the same component was the cdkOverlayOrigin - which toggles the overlay visibility:

<mat-card cdkOverlayOrigin #trigger="cdkOverlayOrigin">
	<button mat-button (click)="open=!open">Toggle Overlay</button>
</mat-card> 

The component defines positions:

private originPos: OriginConnectionPosition = {
    originX: 'start',
    originY: 'top'
};
private overlayPos: OverlayConnectionPosition = {
    overlayX: 'start',
    overlayY: 'top'
};

private position: ConnectionPositionPair = new ConnectionPositionPair(this.originPos, this.overlayPos, 0, 0);
public positions: ConnectionPositionPair[] = [this.position];

And ScrollStrategy is a noop:

  constructor(sso: ScrollStrategyOptions) {
    this.scrollStrategy = sso.noop();
  }

All of this lives within a <hello></hello> component (<br> to force scrolling):

<hello></hello>

<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />

What is the expected behavior?

  • A cdkConnectedOverlay should be positioned at the top-left of the mat-card according to cdkConnectedOverlayPositions.
  • The cdkConnectedOverlay should have a width of 100px and height of 100px.

What is the current behavior?

cdkConnectedOverlay is incorrectly positioned with the component.

image

image

The overlay is positioned below the <br> elements.

What are the steps to reproduce?

StackBlitz: declaratively-cdk-overlay

What is the use-case or motivation for changing an existing behavior?

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

angular-cdk: 5.2.4
angular-material: 5.2.4
angular-core: 5.2.8

Is there anything else we should know?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions