Skip to content

Commit 2169f3f

Browse files
committed
fix(material/chips): wait for onStable when editing a chip
Address timing issue with MatChipRow. When a chip enters the editing state wait for ngZone's `onStable` event before accessing the ViewChild for the MatChipEditInput. Attempts to fix issue where editable chip goes blank when entering the editing state (#27462). What seemed to be happening is that the view would render the MatChiEditInput when setting `_isEditing` to true, but sometimes the ViewChild would not be initialized in the component. Address this issue by adding additional wait using `_ngZone.onStable`. Fix #27462.
1 parent c3f2a97 commit 2169f3f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/material/chips/chip-row.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {MAT_RIPPLE_GLOBAL_OPTIONS, RippleGlobalOptions} from '@angular/material/
3030
import {FocusMonitor} from '@angular/cdk/a11y';
3131
import {MatChip, MatChipEvent} from './chip';
3232
import {MatChipEditInput} from './chip-edit-input';
33-
import {takeUntil} from 'rxjs/operators';
33+
import {take, takeUntil} from 'rxjs/operators';
3434
import {MAT_CHIP} from './tokens';
3535

3636
/** Represents an event fired on an individual `mat-chip` when it is edited. */
@@ -183,8 +183,12 @@ export class MatChipRow extends MatChip implements AfterViewInit {
183183

184184
// Defer initializing the input so it has time to be added to the DOM.
185185
setTimeout(() => {
186-
this._getEditInput().initialize(value);
187-
this._editStartPending = false;
186+
this._ngZone.onStable.pipe(take(1)).subscribe({
187+
next: () => {
188+
this._getEditInput().initialize(value);
189+
this._editStartPending = false;
190+
},
191+
});
188192
});
189193
}
190194

0 commit comments

Comments
 (0)