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(COMPONENT): chip with autocomplete does not clear the input field after adding new chip #30339

Open
1 task
jolenius opened this issue Jan 16, 2025 · 2 comments · May be fixed by #30396
Open
1 task

bug(COMPONENT): chip with autocomplete does not clear the input field after adding new chip #30339

jolenius opened this issue Jan 16, 2025 · 2 comments · May be fixed by #30396
Labels
area: material/chips docs This issue is related to documentation P4 A relatively minor issue that is not relevant to core functions

Comments

@jolenius
Copy link

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

When combining chips with the autocomplete component the input field isn't cleared between each entry. Despite setting the input fields value to a empty string at the end of my function that is invoked by the optionSelected event.

Reproduction

StackBlitz link: https://stackblitz.com/edit/2qghuqyq?file=src%2Fexample%2Fchips-autocomplete-example.ts
(stackblitz fetched from the Chips Autocomplete example at https://material.angular.io/components/chips/examples)
Steps to reproduce:

  1. Enter a few characters to start filtering the autocomplete list
  2. Select an item on the list by using your mouse

Expected Behavior

After clicking an item from the autocomplete list the input field should be cleared

Actual Behavior

The value in the input field is unchanged

Environment

  • Angular: 19
  • CDK/Material: 19
  • Browser(s): Edge
  • Operating System (e.g. Windows, macOS, Ubuntu): Linux (RHEL 8)
@jolenius jolenius added the needs triage This issue needs to be triaged by the team label Jan 16, 2025
@jolenius
Copy link
Author

A workaround for this issue is described here: #8214 (comment)

  • Add a reference to the input-element
  • Run input.value = '' after your optionSelected function like this:

<mat-autocomplete #auto="matAutocomplete" (optionSelected)="select($event); input.value = ''" [displayWith]="displayFn">

@crisbeto crisbeto added docs This issue is related to documentation P4 A relatively minor issue that is not relevant to core functions area: material/chips and removed needs triage This issue needs to be triaged by the team labels Jan 21, 2025
@crisbeto
Copy link
Member

We should update the doc example to clear the input, but we shouldn't change the component's behavior itself since some apps may want to keep the text.

naaajii added a commit to naaajii/components that referenced this issue Jan 27, 2025
made in chips autocomplete example

fixes angular#30339
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: material/chips docs This issue is related to documentation P4 A relatively minor issue that is not relevant to core functions
Projects
None yet
2 participants