diff --git a/src/material/autocomplete/autocomplete-trigger.ts b/src/material/autocomplete/autocomplete-trigger.ts index 159c036ce973..7baf6f220a4d 100644 --- a/src/material/autocomplete/autocomplete-trigger.ts +++ b/src/material/autocomplete/autocomplete-trigger.ts @@ -529,18 +529,6 @@ export class MatAutocompleteTrigger if (!value) { this._clearPreviousSelectedOption(null, false); - } else if (this.panelOpen && !this.autocomplete.requireSelection) { - // Note that we don't reset this when `requireSelection` is enabled, - // because the option will be reset when the panel is closed. - const selectedOption = this.autocomplete.options?.find(option => option.selected); - - if (selectedOption) { - const display = this._getDisplayValue(selectedOption.value); - - if (value !== display) { - selectedOption.deselect(false); - } - } } if (this._canOpen() && this._document.activeElement === event.target) { @@ -553,6 +541,20 @@ export class MatAutocompleteTrigger this._valueOnLastKeydown = null; this._openPanelInternal(valueOnAttach); } + + if (value && this.panelOpen && !this.autocomplete.requireSelection) { + // Note that we don't reset this when `requireSelection` is enabled, + // because the option will be reset when the panel is closed. + const selectedOption = this.autocomplete.options?.find(option => option.selected); + + if (selectedOption) { + const display = this._getDisplayValue(selectedOption.value); + + if (value !== display) { + selectedOption.deselect(false); + } + } + } } }