components icon indicating copy to clipboard operation
components copied to clipboard

bug(MatAutocomplete): matAutocomplete with initial value does not filter options and does not highlight selected

Open mmercure opened this issue 3 years ago • 3 comments

Is this a regression?

  • [ ] Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

A MatAutocomplete field initialized with a value does not filter the list of options are mark selected item.

Reproduction

StackBlitz link: https://stackblitz.com/edit/vemaxm-6ktpyr?file=src%2Fexample%2Fautocomplete-auto-active-first-option-example.html

Steps to reproduce:

  1. In the stackblitz, the formControl for the autcomplet is initialized with 'Two'

  2. Click on the field image

  3. if I click on the option image

it is as expected.

  1. after that if I click the 'clear' button image

value is still selected

  1. reselect a value, lets say 'Two'
  2. delete the two last letters image

Expected Behavior

The list of option should be filtered with the initial FormControl value The actual value should be marked as selected.

Resetting the value should remove the selected

deleting last letter of input keeps last selected option as selected

Actual Behavior

All options are displayed, and nothing indicates that a value is selected.

Resetting the form still displays a value as selected.

if not option exactly match the value, there should not be any selected option.

Environment

  • Angular:
  • CDK/Material:
  • Browser(s):
  • Operating System (e.g. Windows, macOS, Ubuntu):

mmercure avatar Sep 05 '23 20:09 mmercure

mat-autocomplete doesn't do any filtering, it just displays the mat-option that are projected and keeps track of the value. You can get it to work by changing startWith('') to startWith(this.myControl.value).

crisbeto avatar Sep 06 '23 10:09 crisbeto

Ok that's fair, and resetting the selected is addressed with #27652 but what about the resetting selected when there is a partial value, or selecting when the value is the same, but was not selected in the dropdown?

mmercure avatar Sep 06 '23 12:09 mmercure

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.