Skip to content

Commit c9ab38b

Browse files
committedJan 20, 2022
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 4acbae7 commit c9ab38b

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed
 

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

+3-6
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,9 @@ export class MatChipGrid
357357
this._chips.forEach(chip => chip.primaryAction._updateTabindex(-1));
358358
this._chips.first.focus();
359359
} else {
360-
this._focusInput();
360+
// Delay until the next tick, because this can cause a "changed after checked"
361+
// error if the input does something on focus (e.g. opens an autocomplete).
362+
Promise.resolve().then(() => this._chipInput.focus());
361363
}
362364

363365
this.stateChanges.next();
@@ -482,9 +484,4 @@ export class MatChipGrid
482484

483485
this._lastDestroyedChipIndex = null;
484486
}
485-
486-
/** Focus input element. */
487-
private _focusInput() {
488-
this._chipInput.focus();
489-
}
490487
}

0 commit comments

Comments
 (0)
Please sign in to comment.