Skip to content
Closed
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
17 changes: 16 additions & 1 deletion src/cdk/overlay/position/flexible-connected-position-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,13 +468,28 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
overlayStartY = pos.overlayY == 'top' ? 0 : -overlayRect.height;
}

// On iOS, the .cdk-overlay-container will be positioned absolute instead of fixed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think that's what's happening (the container becoming absolute). From what I can tell the element is still fixed, it's just that iOS shifts the entire coordinate system up to account for the keyboard.

// Adjust the y coordinate in that case by the scroll amount.
const overlayScrollY = this._getOverlayScrollY();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you move this one inline since it's basically a one-liner?


// The (x, y) coordinates of the overlay.
return {
x: originPoint.x + overlayStartX,
y: originPoint.y + overlayStartY,
y: originPoint.y + overlayScrollY + overlayStartY,
};
}

/**
* Gets the y coordinates of the overlay host element. On iOS when the keyboard is visible,
* .cdk-overlay-container will have an absolute position instead of fixed. When that happens,
* this will return a non-zero value.
*/
private _getOverlayScrollY(): number {
const clientRect = this._overlayRef.hostElement.getBoundingClientRect();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder whether this would still apply for a flexible overlay since the bounding box isn't 100% by 100% anymore.


return Math.abs(clientRect.top);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think we always want the absolute value here. If you flip the logic above so it's originPoint.y - overlayScrollY it should work the same and account for cases where it might be pushed from the top for some reason.

}

/** Gets how well an overlay at the given point will fit within the viewport. */
private _getOverlayFit(point: Point, overlay: ClientRect, viewport: ClientRect,
position: ConnectedPosition): OverlayFit {
Expand Down