Skip to content

Commit 6776a67

Browse files
committed
fix(material/chips): ensure that edit input query is re-evaluated on time
Fixes an issue that showed up in an internal app where the edit input query wasn't being evaluated on time which led to a runtime error.
1 parent e3e0c6b commit 6776a67

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/material/chips/chip-row.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,12 @@ export class MatChipRow extends MatChip implements AfterViewInit {
178178
// The value depends on the DOM so we need to extract it before we flip the flag.
179179
const value = this.value;
180180

181-
this._isEditing = true;
182-
this._editStartPending = true;
181+
this._isEditing = this._editStartPending = true;
182+
183+
// Starting the editing sequence below depends on the edit input
184+
// query resolving on time. Trigger a synchronous change detection to
185+
// ensure that it happens by the time we hit the timeout below.
186+
this._changeDetectorRef.detectChanges();
183187

184188
// Defer initializing the input so it has time to be added to the DOM.
185189
setTimeout(() => {
@@ -189,8 +193,7 @@ export class MatChipRow extends MatChip implements AfterViewInit {
189193
}
190194

191195
private _onEditFinish() {
192-
this._isEditing = false;
193-
this._editStartPending = false;
196+
this._isEditing = this._editStartPending = false;
194197
this.edited.emit({chip: this, value: this._getEditInput().getValue()});
195198

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

0 commit comments

Comments
 (0)