Skip to content

Commit 902588a

Browse files
committed
fix(material-experimental/mdc-chips): fix changed after checked error when restoring focus to input (#24243)
Fixes that the MDC chip grid was causing a "changed after checked" error when the last chip is removed, if it is used together with `mat-autocomplete`. The problem is that the chip grid focuses the input when the last chip is removed which then opens the autocomplete panel, resulting in an error. (cherry picked from commit c5cede8)
1 parent 17d7a08 commit 902588a

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/material-experimental/mdc-chips/chip-grid.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,9 @@ export class MatChipGrid
353353
if (this._chips.length > 0) {
354354
this._keyManager.setFirstCellActive();
355355
} else {
356-
this._focusInput();
356+
// Delay until the next tick, because this can cause a "changed after checked"
357+
// error if the input does something on focus (e.g. opens an autocomplete).
358+
Promise.resolve().then(() => this._chipInput.focus());
357359
}
358360

359361
this.stateChanges.next();
@@ -548,9 +550,4 @@ export class MatChipGrid
548550

549551
this._lastDestroyedChipIndex = null;
550552
}
551-
552-
/** Focus input element. */
553-
private _focusInput() {
554-
this._chipInput.focus();
555-
}
556553
}

0 commit comments

Comments
 (0)