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

Autocomplete - add option to always treat first option as active #8423

Closed
lcecil opened this issue Nov 13, 2017 · 4 comments · Fixed by #9495
Closed

Autocomplete - add option to always treat first option as active #8423

lcecil opened this issue Nov 13, 2017 · 4 comments · Fixed by #9495
Assignees
Labels
feature This issue represents a new feature or feature request rather than a bug or bug fix P2 The issue is important to a large percentage of users, with a workaround

Comments

@lcecil
Copy link

lcecil commented Nov 13, 2017

Bug, feature request, or proposal:

Feature Request

What is the expected behavior?

Should be able to manually/programmatically set the first option in the autocomplete panel as the activeOption, so that it receives the appropriate styles and is selected when the user presses enter.

What is the current behavior?

User must either use the down key or hover with the mouse on the option to make it active.

What are the steps to reproduce?

N/A

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

Our users are going to be limited to selecting only options from the autocomplete. We're experiencing problems where users are either typing in a partial value or the full value, hitting the enter key, and not understanding why that option isn't being selected.

See attached images
partial-match
full-match

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

Angular - 4.4.6
Material - 2.0.0-beta.12

Is there anything else we should know?

There is a way to select the first option by using matAutocomplete.options.first.select() and binding that to the keyup.enter event. I can also forcibly set the active styles on the first option by using matAutocomplete.options.first.setActiveStyles() but this doesn't set the first option as the activeOption. Without that, the key manager doesn't know that the first option is already highlighted and pressing the DOWN_ARROW should make the second option active.

The typeahead using bootstrap and AngularJS has the exact desired behavior for a working example: https://angular-ui.github.io/bootstrap/#!#typeahead

@jelbourn jelbourn added discussion feature This issue represents a new feature or feature request rather than a bug or bug fix labels Nov 14, 2017
@myagoo
Copy link

myagoo commented Nov 16, 2017

I don't know how but this exact feature seems to be working in https://teradata.github.io/covalent/#/components/chips (which use material 5 internally). After some research, I did not find any call the methods cited above

@lcecil
Copy link
Author

lcecil commented Nov 16, 2017

@myagoo Thanks, yes that's as far as I've gotten right now. But if you use the keyboard to navigate up or down in their autocomplete menu, it's not working properly:

image

They're probably doing what I mentioned above - use the .select() method on enter, and .setActiveStyles() to make the first option seem active.

@jelbourn jelbourn changed the title Autocomplete - Set first option as activeOption manually Autocomplete - add option to always treat first option as active Jan 19, 2018
@jelbourn jelbourn added P2 The issue is important to a large percentage of users, with a workaround and removed discussion labels Jan 19, 2018
@jelbourn
Copy link
Member

@crisbeto we have some folks inside Google asking for this (or something close enough). Now that I look at it, I think this is an important feature to add. A good example of the behavior I have in mind is the "Enter action" or "Open file by name" pop-ups in WebStorm; you need to be able to start entering a string and hit enter as soon as your desired match is on top.

For API, I'm thinking something like firstOptionAlwaysActive (I'm at a loss for anything shorter). It might also be nice to make a provider that could make this the default behavior.

crisbeto added a commit to crisbeto/material2 that referenced this issue Jan 20, 2018
…open

Adds the ability for the consumer opt-in to having the autocomplete highlight the first option when opened. Includes an injection token that allows it to be configured globally.

Fixes angular#8423.
crisbeto added a commit to crisbeto/material2 that referenced this issue Jan 20, 2018
…open

Adds the ability for the consumer opt-in to having the autocomplete highlight the first option when opened. Includes an injection token that allows it to be configured globally.

Fixes angular#8423.
crisbeto added a commit to crisbeto/material2 that referenced this issue Jan 20, 2018
…open

Adds the ability for the consumer opt-in to having the autocomplete highlight the first option when opened. Includes an injection token that allows it to be configured globally.

Fixes angular#8423.
crisbeto added a commit to crisbeto/material2 that referenced this issue Jan 25, 2018
…open

Adds the ability for the consumer opt-in to having the autocomplete highlight the first option when opened. Includes an injection token that allows it to be configured globally.

Fixes angular#8423.
jelbourn pushed a commit that referenced this issue Jan 26, 2018
…open (#9495)

Adds the ability for the consumer opt-in to having the autocomplete highlight the first option when opened. Includes an injection token that allows it to be configured globally.

Fixes #8423.
@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 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature This issue represents a new feature or feature request rather than a bug or bug fix P2 The issue is important to a large percentage of users, with a workaround
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants