Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions src/material/autocomplete/autocomplete-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
}
}
}
}

Expand Down
Loading