Repository navigation
fix(overlay): take scroll position into account on iOS (#6341) #11947
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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. | ||
| // Adjust the y coordinate in that case by the scroll amount. | ||
| const overlayScrollY = this._getOverlayScrollY(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| } | ||
|
|
||
| /** 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 { | ||
|
|
||
There was a problem hiding this comment.
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.