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

fix(material/autocomplete): regression in requireSelection when options are filtered #28119

Merged
Merged
Show file tree
Hide file tree
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
8 changes: 1 addition & 7 deletions src/material/autocomplete/autocomplete-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,6 @@ export class MatAutocompleteTrigger
// of the available options,
// - if a valid string is entered after an invalid one.
if (this.panelOpen) {
this._captureValueOnAttach();
this._emitOpened();
} else {
this.autocomplete.closed.emit();
Expand All @@ -626,11 +625,6 @@ export class MatAutocompleteTrigger
this.autocomplete.opened.emit();
}

/** Intended to be called when the panel is attached. Captures the current value of the input. */
private _captureValueOnAttach() {
this._valueOnAttach = this._element.nativeElement.value;
}

/** Destroys the autocomplete suggestion panel. */
private _destroyPanel(): void {
if (this._overlayRef) {
Expand Down Expand Up @@ -744,6 +738,7 @@ export class MatAutocompleteTrigger

if (overlayRef && !overlayRef.hasAttached()) {
overlayRef.attach(this._portal);
this._valueOnAttach = this._element.nativeElement.value;
this._closingActionsSubscription = this._subscribeToClosingActions();
}

Expand All @@ -753,7 +748,6 @@ export class MatAutocompleteTrigger
this.autocomplete._setColor(this._formField?.color);
this._updatePanelState();
this._applyModalPanelOwnership();
this._captureValueOnAttach();

// We need to do an extra `panelOpen` check in here, because the
// autocomplete won't be shown if there are no options.
Expand Down
2 changes: 1 addition & 1 deletion tools/public_api_guard/material/autocomplete.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, AfterViewIn
// (undocumented)
_handleKeydown(event: KeyboardEvent): void;
// (undocumented)
static ngAcceptInputType_autocompleteDisabled: unknown /** Handles keyboard events coming from the overlay panel. */;
static ngAcceptInputType_autocompleteDisabled: unknown;
// (undocumented)
ngAfterViewInit(): void;
// (undocumented)
Expand Down