Skip to content

fix(overlay): take scroll position into account on iOS (#6341) - #11947

Closed
jpzwarte wants to merge 1 commit into
angular:masterfrom
jpzwarte:fix-overlay-position-on-ios
Closed

jpzwarte wants to merge 1 commit into
angular:masterfrom
jpzwarte:fix-overlay-position-on-ios

Conversation

@jpzwarte

Copy link
Copy Markdown
Contributor

When the keyboard is visible on iOS, the .cdk-overlay-container will be positioned absolutely instead of fixed. The can be seen by checking the top value of the bounding client rect of the overlay container. When scrolled + keyboard, this will have a negative value on iOS. This PR adds the absolute top value to the y coordinate of the overlay point.

Note: unfortunately, "npm install" in material2 fails locally so i cannot test it on my own code :(

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jun 27, 2018

@crisbeto crisbeto left a comment •

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 tried it out and it definitely works, but we need a unit test for it, otherwise we run the risk of removing it next time we do any larger refactoring. What issues did you have with setting it up locally?

private _getOverlayScrollY(): number {
const clientRect = this._overlayRef.hostElement.getBoundingClientRect();

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.

* 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.

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.


// 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();

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?

@crisbeto crisbeto added the target: patch This PR is targeted for the next patch release label Jun 27, 2018
@crisbeto

crisbeto commented Jul 5, 2018

Copy link
Copy Markdown
Member

@jpzwarte are you able to address the feedback on this one?

@jpzwarte

jpzwarte commented Jul 7, 2018

Copy link
Copy Markdown
Contributor Author

I want to, but i have no time atm :(

@crisbeto

crisbeto commented Jul 8, 2018

Copy link
Copy Markdown
Member

In that case do you want me to open a separate PR and try to get the fix in?

@jpzwarte

jpzwarte commented Jul 8, 2018

Copy link
Copy Markdown
Contributor Author

Please do 👍

crisbeto added a commit to crisbeto/material2 that referenced this pull request Jul 9, 2018
This is taking over from angular#11947. Fixes the connected overlay positioning being thrown off, if it is opened while an input is focused (e.g. when building an autocomplete component). The issue comes from the fact that the browser will offset the entire page in order to put the input in the middle and to make space for the virtual keyboard.

Fixes angular#6341.
crisbeto added a commit to crisbeto/material2 that referenced this pull request Jul 10, 2018
This is taking over from angular#11947. Fixes the connected overlay positioning being thrown off, if it is opened while an input is focused (e.g. when building an autocomplete component). The issue comes from the fact that the browser will offset the entire page in order to put the input in the middle and to make space for the virtual keyboard.

Fixes angular#6341.
jelbourn pushed a commit that referenced this pull request Jul 11, 2018
This is taking over from #11947. Fixes the connected overlay positioning being thrown off, if it is opened while an input is focused (e.g. when building an autocomplete component). The issue comes from the fact that the browser will offset the entire page in order to put the input in the middle and to make space for the virtual keyboard.

Fixes #6341.
@jelbourn

Copy link
Copy Markdown
Contributor

Closing since @crisbeto took this over in #12119

@jelbourn jelbourn closed this Jul 11, 2018
jelbourn pushed a commit that referenced this pull request Jul 12, 2018
…12119)

This is taking over from #11947. Fixes the connected overlay positioning being thrown off, if it is opened while an input is focused (e.g. when building an autocomplete component). The issue comes from the fact that the browser will offset the entire page in order to put the input in the middle and to make space for the virtual keyboard.

Fixes #6341.
victoriaaa234 pushed a commit that referenced this pull request Jul 25, 2018
…12119)

This is taking over from #11947. Fixes the connected overlay positioning being thrown off, if it is opened while an input is focused (e.g. when building an autocomplete component). The issue comes from the fact that the browser will offset the entire page in order to put the input in the middle and to make space for the virtual keyboard.

Fixes #6341.
@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes PR author has agreed to Google's Contributor License Agreement target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants