Skip to content

bug(MatAutocomplete): requireSelection directive does not work the same on documentation and stackblitz example #28656

Closed
@rcb98

Description

@rcb98

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

MatAutocomplete's requireSelection directive has a weird behaviour that isn't present in the documentation examples but is present in the Stackblitz link attached to the same example titled "Require an autocomplete option to be selected".

Reproduction

StackBlitz link: https://stackblitz.com/edit/vctmtb?file=src%2Fexample%2Fautocomplete-require-selection-example.css
Steps to reproduce:

  1. Click on field to open autocomplete panel
  2. Select any available option, for instance "One"
  3. Add an extra character to the input field, for instance "Onea"
  4. Focus out of the field by clicking outside
  5. See error (input is not reset)

NOTE: It's possible that it works as expected on the first try, so in that case, try to follow the same steps another time but with another option.

Expected Behavior

The form control should be cleaned out when detecting the option is not the same as one of the autocomplete's options. In this case, "Onea" is not the same as "One", so the input should reset and left empty.

Here you can see it working as expected in Angular Material's MatAutocomplete documentation.

Actual Behavior

The input is not cleaned out and stays with the wrong value.

Environment

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

Metadata

Metadata

Assignees

Labels

P2The issue is important to a large percentage of users, with a workaroundarea: material/autocomplete

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions