Skip to content
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

bug([@angular/material]): Autocomplete panel should grow to left when doesn't fit viewport #18854

Closed
JonWallsten opened this issue Mar 18, 2020 · 3 comments · Fixed by #18906, lingounet/testage#29 or michael-vasyliv/ngx-virtual-swiper#24
Assignees
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@JonWallsten
Copy link

Info

Not sure if this is a bug or a feature request.
I was digging around in the code to understand what's going on. It seems like the only way on getting what I want is to use RTL instead of LTR on the overlay panel. I didn't actually change this in the code, but I did change the value in Dev Tools while running my code and it was positioned correctly. However this should be set dynamically when the Auto complete panel doesn't fit.
I also tried to change the preferredPositions to use originX=end instead of start. But it didn't change the outcome

Reproduction

https://stackblitz.com/edit/angular-material-2-yzct7d

Steps to reproduce:

  1. Focus the input field and watch the Autocomplete panel

Expected Behavior

When the panel doesn't fit within the viewport's width I expect the panel to grow from right to left instead.

image

Actual Behavior

The box doesn't fit in the viewport

image

Environment

  • Angular: 9.x.x
  • CDK/Material: 9.x.x
  • Browser(s): Chrome
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows
@JonWallsten JonWallsten added the needs triage This issue needs to be triaged by the team label Mar 18, 2020
@crisbeto
Copy link
Member

Wouldn't this cause the same issue but in the other direction? Also did you override the panel width? We have some logic that forces the panel to be the same width as the input.

@JonWallsten
Copy link
Author

JonWallsten commented Mar 18, 2020

@crisbeto: Sorry, I should have mentioned that this occurs when the with is set manually. We have tables with inputs where the field can be really small, but the values can be really long. So we calculate a width based on the characters displayed in the option.

It should not be a problem if it's applied dynamically when it can't fit.

FlexibleConnectedPositionStrategy already checks if you can fit the panel:

image

If it can't fit it should reposition with RTL and check again.

I would have expected adding another preferredPosition would have solved this:
image

But I guess it only does the calculations from the right side of the host to right instead of the left side to the right, which of course will be worse.

Edit: Another thing is that it does already check if it can fit vertically below/above and change if necessary. I don't see why it shouldn't do that for left/right.

@crisbeto crisbeto self-assigned this Mar 24, 2020
@crisbeto crisbeto added has pr P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent and removed needs triage This issue needs to be triaged by the team labels Mar 24, 2020
crisbeto added a commit to crisbeto/material2 that referenced this issue Mar 24, 2020
The positions for the autocomplete dropdown are set up assuming that the panel's width will match the input so they don't provide fallbacks along the x axis. Since we have a `panelWidth` input, the consumer might've overwritten the width to something different so we need to provide the fallbacks to ensure that the panel is always inside the viewport.

Fixes angular#18854.
mmalerba pushed a commit that referenced this issue Apr 6, 2020
The positions for the autocomplete dropdown are set up assuming that the panel's width will match the input so they don't provide fallbacks along the x axis. Since we have a `panelWidth` input, the consumer might've overwritten the width to something different so we need to provide the fallbacks to ensure that the panel is always inside the viewport.

Fixes #18854.
mmalerba pushed a commit that referenced this issue Apr 14, 2020
The positions for the autocomplete dropdown are set up assuming that the panel's width will match the input so they don't provide fallbacks along the x axis. Since we have a `panelWidth` input, the consumer might've overwritten the width to something different so we need to provide the fallbacks to ensure that the panel is always inside the viewport.

Fixes #18854.
@angular-automatic-lock-bot
Copy link

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 May 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
2 participants