Skip to content

fix(material/chips): ensure that edit input query is re-evaluated on time #27465

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

Merged
merged 1 commit into from
Jul 17, 2023
Merged
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
12 changes: 8 additions & 4 deletions src/material/chips/chip-row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,14 @@ export class MatChipRow extends MatChip implements AfterViewInit {
// The value depends on the DOM so we need to extract it before we flip the flag.
const value = this.value;

this._isEditing = true;
this._editStartPending = true;
this._isEditing = this._editStartPending = true;

// Starting the editing sequence below depends on the edit input
// query resolving on time. Trigger a synchronous change detection to
// ensure that it happens by the time we hit the timeout below.
this._changeDetectorRef.detectChanges();

// TODO(crisbeto): this timeout shouldn't be necessary given the `detectChange` call above.
// Defer initializing the input so it has time to be added to the DOM.
setTimeout(() => {
this._getEditInput().initialize(value);
Expand All @@ -189,8 +194,7 @@ export class MatChipRow extends MatChip implements AfterViewInit {
}

private _onEditFinish() {
this._isEditing = false;
this._editStartPending = false;
this._isEditing = this._editStartPending = false;
this.edited.emit({chip: this, value: this._getEditInput().getValue()});

// If the edit input is still focused or focus was returned to the body after it was destroyed,
Expand Down