Skip to content

bug(mat-autocomplete): Removing the selected option manually adds a flicker in the dropdown rendering. #30721

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

Open
1 task
aghosh-evertz opened this issue Mar 26, 2025 · 1 comment
Labels
needs triage This issue needs to be triaged by the team

Comments

@aghosh-evertz
Copy link

aghosh-evertz commented Mar 26, 2025

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

Hi,

There is a requirement to add a 'clear'(X) icon sort of thing which basically should clear the data present in the mat-autocomplete field. Something like this:

Image

Post MDC migration of our project, the selected options have started coming in blue color (mat-selected class getting added) which is fine. But since there is a custom function written for this clear-icon-click, although we set the control value to null/undefined and the value is updated properly in the control, still the selected classes are not getting removed. So, even if there is no option selected, the previously selected option still has the selected classes, when dropdown is opened. I used the hideSingleSelectionIndicator, hence tick is not present.

Image

To counter this, I used the below code in my clear function :

this.autocompleteRef?.options.find((data: MatOption) => data.selected)?.deselect();

Now, on clearing the field, the field gets cleared properly and the 'selected-related' classes are removed from that option in the dropdown but a flickering thing happening.

How can we avoid it ???

Reproduction

Steps to reproduce:

  1. Click on the field to open the drodown panel.
  2. Select the first option from the dropdown. (cause this only happens with the first option)
  3. Again try to click on the field so that dropdown opens with only that option in the dropdown.
  4. While the dropdown panel is in opened state, click on the clear icon. It flickers the dropdown.

Below is the example:

Screencast.from.2025-03-26.19-30-11.webm

Expected Behavior

On clear icon click, it should re-open the dropdown with all the options without any flickering

Actual Behavior

On clear icon click, there is a flicker in the dropdown section and the autocomplete dropdown panel ultimately gets closed.

Environment

  • "@angular/forms": "16.2.12",
  • "@angular/material": "16.2.14",
  • "@angular/cdk": "16.2.14",
  • Browser(s): Chrome
@aghosh-evertz aghosh-evertz added the needs triage This issue needs to be triaged by the team label Mar 26, 2025
@aghosh-evertz
Copy link
Author

Also, why is the first option, when selected, turns into blue color (selected-class) while other options don't show this behaviour ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage This issue needs to be triaged by the team
Projects
None yet
Development

No branches or pull requests

1 participant