Skip to content

Autocomplete options can be positioned outside viewport if options list changes after position has been applied #11492

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

Closed
benelliott opened this issue May 24, 2018 · 1 comment · Fixed by #11495

Comments

@benelliott
Copy link
Contributor

benelliott commented May 24, 2018

Bug, feature request, or proposal:

Bug

What is the expected behavior?

MatAutocomplete options should always be repositioned so they don't fall outside the viewport.

What is the current behavior?

Place a MatAutocomplete near the bottom of the viewport, initially with few enough options that
its panel will fit inside the viewport using the default bottom position. Then, bind the associated input's focus output to a function which appends more options, so that the panel won't fit inside the viewport anymore. The autocomplete's panel position won't fallback to the top position.

What are the steps to reproduce?

https://stackblitz.com/edit/angular-material2-issue-7v48o6?file=app/app.component.ts

Focus on the first input and note that the autocomplete panel is positioned correctly. Focus on the second and see that it is not.

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

In my application I dynamically add autocomplete options based on the user's input.

For example, when using an autocomplete add tags the autocomplete options are made up from an API call to search existing tags for the current input value, plus a final option that represents adding the user's current input as a new tag.

When the user first focuses the tag autocomplete, the options list is empty. As soon as they type a single character, the options list is populated with the results from their search. The whole time, the user is focused on the autocomplete.

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

Angular 6.0.3, Material master-e592615 (also 6.1.0).

Is there anything else we should know?

I think this is because in autocomplete-trigger, when options are changed the panel position is blindly reapplied without recomputing its dimensions. Happy to attempt a PR.

benelliott added a commit to benelliott/material2 that referenced this issue May 24, 2018
Ensures that changes to the autocomplete options will cause the component to check that its current
overlay position is still within the viewport so that the overlay can fall back to the above
position, if necessary, while the panel is still open.

Fixes angular#11492
benelliott added a commit to benelliott/material2 that referenced this issue May 24, 2018
Ensures that changes to the autocomplete options will cause the component to check that its current
overlay position is still within the viewport so that the overlay can fall back to the above
position, if necessary, while the panel is still open.

Fixes angular#11492
benelliott added a commit to benelliott/material2 that referenced this issue May 24, 2018
Ensures that changes to the autocomplete options will cause the component to check that its current
overlay position is still within the viewport so that the overlay can fall back to the above
position, if necessary, while the panel is still open.

Fixes angular#11492
benelliott added a commit to benelliott/material2 that referenced this issue Jun 22, 2018
…gger

Add an updatePosition() method to MatAutocompleteTrigger that re-evaluates the position of the
autocomplete panel overlay and falls back to the above position if necessary. This is useful if
enough options have been added to the panel while it is open to cause it to exceed the viewport.

Fixes angular#11492
benelliott added a commit to benelliott/material2 that referenced this issue Jun 22, 2018
…gger

Add an updatePosition() method to MatAutocompleteTrigger that re-evaluates the position of the
autocomplete panel overlay and falls back to the above position if necessary. This is useful if
enough options have been added to the panel while it is open to cause it to exceed the viewport.

Fixes angular#11492
@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 Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants